refactor: is_test_path

This commit is contained in:
debugtalk
2020-01-01 22:34:41 +08:00
parent 3ccf68061e
commit b5be7f0cb4
3 changed files with 27 additions and 14 deletions

View File

@@ -289,7 +289,7 @@ class HttpRunner(object):
""" """
logger.log_info("HttpRunner version: {}".format(__version__)) logger.log_info("HttpRunner version: {}".format(__version__))
if loader.is_testcase_path(path_or_tests): if loader.is_test_path(path_or_tests):
return self.run_path(path_or_tests, dot_env_path, mapping) return self.run_path(path_or_tests, dot_env_path, mapping)
elif loader.is_testcases(path_or_tests): elif loader.is_testcases(path_or_tests):
return self.run_tests(path_or_tests) return self.run_tests(path_or_tests)

View File

@@ -8,13 +8,13 @@ HttpRunner loader
""" """
from httprunner.loader.check import is_testcase_path, is_testcases, JsonSchemaChecker from httprunner.loader.check import is_test_path, is_testcases, JsonSchemaChecker
from httprunner.loader.locate import get_project_working_directory as get_pwd from httprunner.loader.locate import get_project_working_directory as get_pwd
from httprunner.loader.load import load_csv_file, load_builtin_functions from httprunner.loader.load import load_csv_file, load_builtin_functions
from httprunner.loader.buildup import load_cases, load_project_data from httprunner.loader.buildup import load_cases, load_project_data
__all__ = [ __all__ = [
"is_testcase_path", "is_test_path",
"is_testcases", "is_testcases",
"JsonSchemaChecker", "JsonSchemaChecker",
"get_pwd", "get_pwd",

View File

@@ -175,30 +175,43 @@ def is_testcases(data_structure):
return True return True
def is_testcase_path(path): def is_test_path(path):
""" check if path is testcase path or path list. """ check if path is valid json/yaml file path or a existed directory.
Args: Args:
path (str/list): file path or file path list. path (str/list/tuple): file path/directory or file path list.
Returns: Returns:
bool: True if path is valid file path or path list, otherwise False. bool: True if path is valid file path or path list, otherwise False.
""" """
if not isinstance(path, (str, list)): if not isinstance(path, (str, list, tuple)):
return False return False
if isinstance(path, list): elif isinstance(path, (list, tuple)):
for p in path: for p in path:
if not is_testcase_path(p): if not is_test_path(p):
return False return False
if isinstance(path, str): return True
else:
# path is string
if not os.path.exists(path): if not os.path.exists(path):
return False return False
file_suffix = os.path.splitext(path)[1].lower() # path exists
if file_suffix != ['.json', '.yaml', '.yml']: if os.path.isfile(path):
# path is a file
file_suffix = os.path.splitext(path)[1].lower()
if file_suffix not in ['.json', '.yaml', '.yml']:
# path is not json/yaml file
return False
else:
return True
elif os.path.isdir(path):
# path is a directory
return True
else:
# path is neither a folder nor a file, maybe a symbol link or something else
return False return False
return True