From 09e190b55d96ba0ff47947f9eac1d4e8530d92b0 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Tue, 11 Sep 2018 00:40:47 +0800 Subject: [PATCH] update create_scaffold --- httprunner/cli.py | 3 +-- httprunner/utils.py | 37 ++++++++++++++++++------------------- tests/test_utils.py | 18 +++++++++--------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/httprunner/cli.py b/httprunner/cli.py index f0e7f70e..b7dcda62 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -74,8 +74,7 @@ def main_hrun(): project_name = args.startproject if project_name: - project_path = os.path.join(os.getcwd(), project_name) - create_scaffold(project_path) + create_scaffold(project_name) exit(0) try: diff --git a/httprunner/utils.py b/httprunner/utils.py index 83ca7c4d..2fb15dae 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -356,13 +356,16 @@ def print_io(in_out): logger.log_debug(content) -def create_scaffold(project_path): - if os.path.isdir(project_path): - folder_name = os.path.basename(project_path) - logger.log_warning(u"Folder {} exists, please specify a new folder name.".format(folder_name)) + +def create_scaffold(project_name): + """ create scaffold with specified project name. + """ + if os.path.isdir(project_name): + logger.log_warning(u"Folder {} exists, please specify a new folder name.".format(project_name)) return - logger.color_print("Start to create new project: {}\n".format(project_path), "GREEN") + logger.color_print("Start to create new project: {}".format(project_name), "GREEN") + logger.color_print("CWD: {}\n".format(os.getcwd()), "BLUE") def create_path(path, ptype): if ptype == "folder": @@ -370,23 +373,19 @@ def create_scaffold(project_path): elif ptype == "file": open(path, 'w').close() - return "created {}: {}\n".format(ptype, path) + msg = "created {}: {}".format(ptype, path) + logger.color_print(msg, "BLUE") path_list = [ - (project_path, "folder"), - (os.path.join(project_path, "api"), "folder"), - (os.path.join(project_path, "testcases"), "folder"), - (os.path.join(project_path, "testsuites"), "folder"), - (os.path.join(project_path, "reports"), "folder"), - (os.path.join(project_path, "debugtalk.py"), "file"), - (os.path.join(project_path, ".env"), "file") + (project_name, "folder"), + (os.path.join(project_name, "api"), "folder"), + (os.path.join(project_name, "testcases"), "folder"), + (os.path.join(project_name, "testsuites"), "folder"), + (os.path.join(project_name, "reports"), "folder"), + (os.path.join(project_name, "debugtalk.py"), "file"), + (os.path.join(project_name, ".env"), "file") ] - - msg = "" - for p in path_list: - msg += create_path(p[0], p[1]) - - logger.color_print(msg, "BLUE") + [create_path(p[0], p[1]) for p in path_list] def gen_cartesian_product(*args): diff --git a/tests/test_utils.py b/tests/test_utils.py index ce7dede0..c382bed0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -252,15 +252,15 @@ class TestUtils(ApiServerUnittest): utils.override_mapping_list(map_list, override_mapping) def test_create_scaffold(self): - project_path = os.path.join(os.getcwd(), "projectABC") - utils.create_scaffold(project_path) - self.assertTrue(os.path.isdir(os.path.join(project_path, "api"))) - self.assertTrue(os.path.isdir(os.path.join(project_path, "testcases"))) - self.assertTrue(os.path.isdir(os.path.join(project_path, "testsuites"))) - self.assertTrue(os.path.isdir(os.path.join(project_path, "reports"))) - self.assertTrue(os.path.isfile(os.path.join(project_path, "debugtalk.py"))) - self.assertTrue(os.path.isfile(os.path.join(project_path, ".env"))) - shutil.rmtree(project_path) + project_name = "projectABC" + utils.create_scaffold(project_name) + self.assertTrue(os.path.isdir(os.path.join(project_name, "api"))) + self.assertTrue(os.path.isdir(os.path.join(project_name, "testcases"))) + self.assertTrue(os.path.isdir(os.path.join(project_name, "testsuites"))) + self.assertTrue(os.path.isdir(os.path.join(project_name, "reports"))) + self.assertTrue(os.path.isfile(os.path.join(project_name, "debugtalk.py"))) + self.assertTrue(os.path.isfile(os.path.join(project_name, ".env"))) + shutil.rmtree(project_name) def test_cartesian_product_one(self): parameters_content_list = [