diff options
Diffstat (limited to 'dovetail/cli/commands/cli_testcase.py')
-rw-r--r-- | dovetail/cli/commands/cli_testcase.py | 115 |
1 files changed, 48 insertions, 67 deletions
diff --git a/dovetail/cli/commands/cli_testcase.py b/dovetail/cli/commands/cli_testcase.py index a498d495..6711381c 100644 --- a/dovetail/cli/commands/cli_testcase.py +++ b/dovetail/cli/commands/cli_testcase.py @@ -7,92 +7,73 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import os -import sys -import yaml + import click -import six +import yaml -import dovetail.utils.dovetail_utils as dt_utils -from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +from dovetail import constants from dovetail.testcase import Testsuite +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_utils as dt_utils class CliTestcase(object): - @classmethod - def testsuite_load(cls): - dt_cfg.load_config_files() + @staticmethod + def testsuite_load(): + dt_cfg.load_config_files(constants.CONF_PATH) Testsuite.load() - @classmethod - def get_path(cls, path): - if isinstance(path, six.string_types): - dt_cfg.load_config_files() - dovetail_dir = os.path.abspath( - os.path.join(os.path.dirname(__file__), - os.pardir, os.pardir)) - relative_path = dt_cfg.dovetail_config[path] - abs_path = os.path.join(dovetail_dir, relative_path) + @staticmethod + def list_one_testsuite(testsuite): + testsuite_stream = Testsuite.get(testsuite) + if testsuite_stream: + mandatory = dt_utils.get_value_from_dict( + 'testcases_list.mandatory', testsuite_stream) + optional = dt_utils.get_value_from_dict( + 'testcases_list.optional', testsuite_stream) + if mandatory: + click.echo("- mandatory") + for testcase in mandatory: + click.echo(" {}".format(testcase)) + if optional: + click.echo("- optional") + for testcase in optional: + click.echo(" {}".format(testcase)) + if not (mandatory or optional): + click.echo("No testcase in testsuite {}".format(testsuite)) else: - click.echo("input %s is not a string" % path) - sys.exit(1) - return abs_path + click.echo("testsuite {} does not exist".format(testsuite)) - def list_testcase(self, testsuite): + def list_testsuites(self, testsuite): self.testsuite_load() if testsuite: - testsuite_stream = Testsuite.get(testsuite) - if testsuite_stream: - testcase_list = [] - for value in testsuite_stream['testcases_list']: - if value is not None: - testcase_list.append(value) - testarea_list = [] - for testcase in testcase_list: - testarea = testcase.split('.')[1] - if testarea not in testarea_list: - testarea_list.append(testarea) - for testarea in testarea_list: - click.echo("- %s" % testarea) - for testcase in testcase_list: - if testarea in testcase: - click.echo(" %s" % testcase) - else: - click.echo("testsuite %s does not exist or not supported" - % testsuite) + self.list_one_testsuite(testsuite) else: testsuite_json = Testsuite.get_all() if testsuite_json: - for key, value in testsuite_json.items(): - click.echo("- %s" % key) - testsuite_stream = Testsuite.get(key) - if testsuite_stream['testcases_list']: - for testcase in testsuite_stream['testcases_list']: - click.echo(" %s" % testcase) - else: - click.echo("No testcase in testsuite %s" % key) + for key in testsuite_json.keys(): + click.echo("--------------------------") + click.echo("Test Suite {}".format(key)) + click.echo("--------------------------") + self.list_one_testsuite(key) else: click.echo("No testsuite defined yet in dovetail!!!") - def show_testcase(self, testcase): - abs_testcase_path = self.get_path('TESTCASE_PATH') - if testcase.startswith("dovetail."): - testcase_yml = testcase[9:] + '.yml' + @staticmethod + def show_testcase(name): + tc_path = os.path.join(constants.TESTCASE_PATH, "{}.yml".format(name)) + if os.path.isfile(tc_path): + with open(tc_path, 'r') as stream: + try: + click.echo(stream.read()) + except yaml.YAMLError as exc: + click.echo(exc) else: - testcase_yml = testcase + '.yml' - for root, dirs, files in os.walk(abs_testcase_path): - if testcase_yml in files: - testcase_path = abs_testcase_path + testcase_yml - with open(testcase_path, 'r') as stream: - try: - click.echo(stream.read()) - except yaml.YAMLError as exc: - click.echo(exc) - else: - click.echo("testcase %s does not exist or not supported" - % testcase) + click.echo("testcase %s not exist or not supported" % name) - def run(self, args_str): + @staticmethod + def run(args_str): options = '' if args_str: options = options + args_str @@ -101,7 +82,7 @@ class CliTestcase(object): os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) - cmd = ("python %s/run.py" + cmd = ("python3 %s/run.py" " %s" % (repo_dir, options)) - dt_utils.exec_cmd(cmd, exit_on_error=False, + dt_utils.exec_cmd(cmd, exit_on_error=True, exec_msg_on=False, info=True) |