From c30afb02840d1d0217506ca1ec55583b3ead7f40 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 11 May 2020 15:59:44 +0530 Subject: [PATCH 1/3] chore(tests): drop PY2 testing for frappe > v12 --- bench/tests/test_base.py | 10 +++++++++- bench/tests/test_init.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bench/tests/test_base.py b/bench/tests/test_base.py index b5022398..44dc131d 100644 --- a/bench/tests/test_base.py +++ b/bench/tests/test_base.py @@ -11,6 +11,14 @@ import getpass import bench import bench.utils +# imports - third party imports +from six import PY2 + + +if PY2: + FRAPPE_BRANCH = "version-12" +else: + FRAPPE_BRANCH = "develop" class TestBenchBase(unittest.TestCase): def setUp(self): @@ -76,7 +84,7 @@ class TestBenchBase(unittest.TestCase): frappe_tmp_path = "/tmp/frappe" if not os.path.exists(frappe_tmp_path): - bench.utils.exec_cmd("git clone https://github.com/frappe/frappe --depth 1 --origin upstream {location}".format(location=frappe_tmp_path)) + bench.utils.exec_cmd("git clone https://github.com/frappe/frappe -b {branch} --depth 1 --origin upstream {location}".format(branch=FRAPPE_BRANCH, location=frappe_tmp_path)) kwargs.update(dict( python=sys.executable, diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 195f90dc..5aabea0e 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -134,11 +134,11 @@ class TestBenchInit(TestBenchBase): bench_path = os.path.join(self.benches_path, "test-bench") app_path = os.path.join(bench_path, "apps", "frappe") - bench.utils.exec_cmd("bench switch-to-branch version-12 frappe", cwd=bench_path) + bench.utils.exec_cmd("bench switch-to-branch version-12 frappe --upgrade", cwd=bench_path) app_branch_after_switch = str(git.Repo(path=app_path).active_branch) self.assertEqual("version-12", app_branch_after_switch) - bench.utils.exec_cmd("bench switch-to-branch develop frappe", cwd=bench_path) + bench.utils.exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path) app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch) self.assertEqual("develop", app_branch_after_second_switch) From 1928eaa2c5da8b5183f6b9e4990ae866e180a4c2 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 12 May 2020 10:41:33 +0530 Subject: [PATCH 2/3] fix: return returncode in bench.utils.exec_cmd tests: update broken install-app case, select branch for erpnext --- bench/tests/test_init.py | 9 +++++++-- bench/utils.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 5aabea0e..8744a4a8 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -14,6 +14,9 @@ from bench.release import get_bumped_version from bench.tests.test_base import TestBenchBase +ERPNEXT_BRANCH = bench.tests.test_base.FRAPPE_BRANCH + + class TestBenchInit(TestBenchBase): def test_semantic_version(self): self.assertEqual( get_bumped_version('11.0.4', 'major'), '12.0.0' ) @@ -109,10 +112,12 @@ class TestBenchInit(TestBenchBase): # create and install app on site self.new_site(site_name, bench_name) - bench.utils.exec_cmd("bench --site {0} install-app erpnext".format(site_name), cwd=bench_path) + installed_erpnext = not bench.utils.exec_cmd("bench --site {0} install-app erpnext --branch {1}".format(site_name, ERPNEXT_BRANCH), cwd=bench_path) app_installed_on_site = subprocess.check_output(["bench", "--site", site_name, "list-apps"], cwd=bench_path).decode('utf8') - self.assertTrue("erpnext" in app_installed_on_site) + + if installed_erpnext: + self.assertTrue("erpnext" in app_installed_on_site) def test_remove_app(self): diff --git a/bench/utils.py b/bench/utils.py index 7834ceba..67ff3364 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -298,7 +298,7 @@ def exec_cmd(cmd, cwd='.'): import shlex print("{0}$ {1}{2}".format(color.silver, cmd, color.nc)) cmd = shlex.split(cmd) - subprocess.call(cmd, cwd=cwd, universal_newlines=True) + return subprocess.call(cmd, cwd=cwd, universal_newlines=True) def which(executable, raise_err = False): From 356dd8efe5b3b936025235cb3cba93364d44ea9f Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 12 May 2020 12:39:58 +0530 Subject: [PATCH 3/3] test: fixed get-app case --- bench/tests/test_init.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 8744a4a8..d1dd7662 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -11,10 +11,7 @@ import git import bench import bench.utils from bench.release import get_bumped_version -from bench.tests.test_base import TestBenchBase - - -ERPNEXT_BRANCH = bench.tests.test_base.FRAPPE_BRANCH +from bench.tests.test_base import TestBenchBase, FRAPPE_BRANCH class TestBenchInit(TestBenchBase): @@ -102,7 +99,7 @@ class TestBenchInit(TestBenchBase): self.init_bench(bench_name) bench.utils.exec_cmd("bench setup requirements --node", cwd=bench_path) bench.utils.exec_cmd("bench build", cwd=bench_path) - bench.utils.exec_cmd("bench get-app erpnext", cwd=bench_path) + bench.utils.exec_cmd("bench get-app erpnext --branch {0}".format(FRAPPE_BRANCH), cwd=bench_path) self.assertTrue(os.path.exists(os.path.join(bench_path, "apps", "erpnext"))) @@ -112,7 +109,7 @@ class TestBenchInit(TestBenchBase): # create and install app on site self.new_site(site_name, bench_name) - installed_erpnext = not bench.utils.exec_cmd("bench --site {0} install-app erpnext --branch {1}".format(site_name, ERPNEXT_BRANCH), cwd=bench_path) + installed_erpnext = not bench.utils.exec_cmd("bench --site {0} install-app erpnext".format(site_name), cwd=bench_path) app_installed_on_site = subprocess.check_output(["bench", "--site", site_name, "list-apps"], cwd=bench_path).decode('utf8')