diff --git a/ate/__init__.py b/ate/__init__.py index 0ffab71e..6fb2e710 100644 --- a/ate/__init__.py +++ b/ate/__init__.py @@ -1 +1 @@ -__version__ = '0.7.3' \ No newline at end of file +__version__ = '0.7.4' \ No newline at end of file diff --git a/ate/cli.py b/ate/cli.py index 0bf17b86..92971fe0 100644 --- a/ate/cli.py +++ b/ate/cli.py @@ -6,6 +6,7 @@ from collections import OrderedDict from ate import __version__ from ate.task import TaskSuite +from ate.utils import create_scaffold import PyUnitReport @@ -30,6 +31,9 @@ def main_ate(): parser.add_argument( '--failfast', action='store_true', default=False, help="Stop the test run on the first error or failure.") + parser.add_argument( + '--startproject', + help="Specify new project name.") try: from jenkins_mail_py import MailgunHelper @@ -46,6 +50,12 @@ def main_ate(): log_level = getattr(logging, args.log_level.upper()) logging.basicConfig(level=log_level) + project_name = args.startproject + if project_name: + project_path = os.path.join(os.getcwd(), project_name) + create_scaffold(project_path) + exit(0) + report_name = args.report_name if report_name and len(args.testset_paths) > 1: report_name = None diff --git a/ate/utils.py b/ate/utils.py index 63746621..33f8c694 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -405,3 +405,29 @@ def print_output(output): content += "============================================\n" logging.debug(content) + +def create_scaffold(project_path): + logging.info(" Start to create new project: {}".format(project_path)) + + if os.path.isdir(project_path): + folder_name = os.path.basename(project_path) + logging.warning(" Folder {} exists, please specify a new folder name.".format(folder_name)) + return + + def create_path(path, ptype): + if ptype == "folder": + os.makedirs(path) + elif ptype == "file": + open(path, 'w').close() + + logging.info("\tcreated {}: {}".format(ptype, path)) + + path_list = [ + (project_path, "folder"), + (os.path.join(project_path, "tests"), "folder"), + (os.path.join(project_path, "tests", "api"), "folder"), + (os.path.join(project_path, "tests", "suite"), "folder"), + (os.path.join(project_path, "tests", "testcases"), "folder"), + (os.path.join(project_path, "tests", "debugtalk.py"), "file") + ] + [create_path(p[0], p[1]) for p in path_list] diff --git a/tests/test_utils.py b/tests/test_utils.py index 80d42467..eb274b84 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ import os +import shutil from collections import OrderedDict from ate import exception, utils @@ -308,3 +309,13 @@ class TestUtils(ApiServerUnittest): override_mapping = {"a": 3, "c": 4} with self.assertRaises(exception.ParamsError): utils.override_variables_binds(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, "tests"))) + self.assertTrue(os.path.isdir(os.path.join(project_path, "tests", "api"))) + self.assertTrue(os.path.isdir(os.path.join(project_path, "tests", "suite"))) + self.assertTrue(os.path.isdir(os.path.join(project_path, "tests", "testcases"))) + self.assertTrue(os.path.isfile(os.path.join(project_path, "tests", "debugtalk.py"))) + shutil.rmtree(project_path)