From c48a8e933f4017e41a175ba5a9a6e1b2207f758f Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 6 May 2021 18:39:17 +0530 Subject: [PATCH 1/4] fix: remove six.moves.input and use builtin.input reason: py2 support no longer required and six makes mocking/testing complicated. --- frappe/utils/boilerplate.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/frappe/utils/boilerplate.py b/frappe/utils/boilerplate.py index ba20562544..b935bfbf4f 100755 --- a/frappe/utils/boilerplate.py +++ b/frappe/utils/boilerplate.py @@ -3,8 +3,6 @@ from __future__ import unicode_literals, print_function -from six.moves import input - import frappe, os, re, git from frappe.utils import touch_file, cstr From 4210299ab424aa77c61269fb41f1b29d95cdee94 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 6 May 2021 19:12:19 +0530 Subject: [PATCH 2/4] test: add test for creating new app --- frappe/tests/test_boilerplate.py | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 frappe/tests/test_boilerplate.py diff --git a/frappe/tests/test_boilerplate.py b/frappe/tests/test_boilerplate.py new file mode 100644 index 0000000000..14741dc29e --- /dev/null +++ b/frappe/tests/test_boilerplate.py @@ -0,0 +1,67 @@ +import os +import unittest +from unittest.mock import patch + +import frappe +from frappe.utils.boilerplate import make_boilerplate + + +class TestBoilerPlate(unittest.TestCase): + def test_create_app(self): + title = "Test App" + description = "Test app for unit testing" + publisher = "Test Publisher" + email = "example@example.org" + icon = "" # empty -> default + color = "" + app_license = "MIT" + + user_input = [ + title, + description, + publisher, + email, + icon, + color, + app_license, + ] + + bench_path = frappe.utils.get_bench_path() + apps_dir = os.path.join(bench_path, "apps") + app_name = "test_app" + + with patch("builtins.input", side_effect=user_input): + make_boilerplate(apps_dir, app_name) + + root_paths = [ + app_name, + "requirements.txt", + "README.md", + "setup.py", + "license.txt", + ".git", + ] + paths_inside_app = [ + "__init__.py", + "hooks.py", + "patches.txt", + "templates", + "www", + "config", + "modules.txt", + "public", + app_name, + ] + + new_app_dir = os.path.join(bench_path, apps_dir, app_name) + + all_paths = list() + + for path in root_paths: + all_paths.append(os.path.join(new_app_dir, path)) + + for path in paths_inside_app: + all_paths.append(os.path.join(new_app_dir, app_name, path)) + + for path in all_paths: + self.assertTrue(os.path.exists(path), msg=f"{path} should exist in new app") From 835ed181b5d57ed26b163403bdd8eb3872a8212a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 7 May 2021 10:34:17 +0530 Subject: [PATCH 3/4] test: delete created test_app in tearDownClass --- frappe/tests/test_boilerplate.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frappe/tests/test_boilerplate.py b/frappe/tests/test_boilerplate.py index 14741dc29e..7dd704aad1 100644 --- a/frappe/tests/test_boilerplate.py +++ b/frappe/tests/test_boilerplate.py @@ -1,4 +1,5 @@ import os +import shutil import unittest from unittest.mock import patch @@ -7,6 +8,14 @@ from frappe.utils.boilerplate import make_boilerplate class TestBoilerPlate(unittest.TestCase): + @classmethod + def tearDownClass(cls): + + bench_path = frappe.utils.get_bench_path() + test_app_dir = os.path.join(bench_path, "apps", "test_app") + if os.path.exists(test_app_dir): + shutil.rmtree(test_app_dir) + def test_create_app(self): title = "Test App" description = "Test app for unit testing" From e9a3569bf78792cc9b03fe2027a7c8f3ae396311 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 7 May 2021 10:34:46 +0530 Subject: [PATCH 4/4] test: check if created python files are parsable --- frappe/tests/test_boilerplate.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frappe/tests/test_boilerplate.py b/frappe/tests/test_boilerplate.py index 7dd704aad1..4ae78c94de 100644 --- a/frappe/tests/test_boilerplate.py +++ b/frappe/tests/test_boilerplate.py @@ -1,3 +1,5 @@ +import ast +import glob import os import shutil import unittest @@ -74,3 +76,13 @@ class TestBoilerPlate(unittest.TestCase): for path in all_paths: self.assertTrue(os.path.exists(path), msg=f"{path} should exist in new app") + + # check if python files are parsable + python_files = glob.glob(new_app_dir + "**/*.py", recursive=True) + + for python_file in python_files: + with open(python_file) as p: + try: + ast.parse(p.read()) + except Exception as e: + self.fail(f"Can't parse python file in new app: {python_file}\n" + str(e))