def load_test_dependencies(): """ load all api and suite definitions. default api folder is "$CWD/tests/api/". default suite folder is "$CWD/tests/suite/". """ test_def_overall_dict["loaded"] = True test_def_overall_dict["api"] = {} test_def_overall_dict["suite"] = {} # load api definitions api_def_folder = os.path.join(os.getcwd(), "tests", "api") api_files = utils.load_folder_files(api_def_folder) for test_file in api_files: testset = load_test_file(test_file) test_def_overall_dict["api"].update(testset["api"]) # load suite definitions suite_def_folder = os.path.join(os.getcwd(), "tests", "suite") suite_files = utils.load_folder_files(suite_def_folder) for suite_file in suite_files: suite = load_test_file(suite_file) if "def" not in suite["config"]: raise exception.ParamsError( "def missed in suite file: {}!".format(suite_file)) call_func = suite["config"]["def"] function_meta = parse_function(call_func) suite["function_meta"] = function_meta test_def_overall_dict["suite"][function_meta["func_name"]] = suite
def test_load_folder_files(self): folder = os.path.join(os.getcwd(), 'tests') file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py') file2 = os.path.join(os.getcwd(), 'tests', 'data', 'demo_binds.yml') files = utils.load_folder_files(folder, ["*.py"]) self.assertIn(file1, files) self.assertNotIn(file2, files)
def test_load_folder_files(self): folder = os.path.join(os.getcwd(), 'tests') file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py') file2 = os.path.join(os.getcwd(), 'tests', 'data', 'demo_binds.yml') files = utils.load_folder_files(folder, recursive=False) self.assertNotIn(file2, files) files = utils.load_folder_files(folder) self.assertIn(file2, files) self.assertNotIn(file1, files) files_1 = utils.load_folder_files(folder) api_file = os.path.join(os.getcwd(), 'tests', 'api', 'demo.yml') self.assertEqual(files_1[0], api_file) files_2 = utils.load_folder_files(folder) api_file = os.path.join(os.getcwd(), 'tests', 'api', 'demo.yml') self.assertEqual(files_2[0], api_file) self.assertEqual(len(files_1), len(files_2)) files = utils.load_folder_files("not_existed_foulder", recursive=False) self.assertEqual([], files) files = utils.load_folder_files(file2, recursive=False) self.assertEqual([], files)
def load_testcases_by_path(path): """ load testcases from file path @param path: path could be in several type - absolute/relative file path - absolute/relative folder path - list/set container with file(s) and/or folder(s) @return testcase sets list, each testset is corresponding to a file [ testset_dict_1, testset_dict_2 ] """ if isinstance(path, (list, set)): testsets = [] for file_path in set(path): testset = load_testcases_by_path(file_path) if not testset: continue testsets.extend(testset) return testsets if not os.path.isabs(path): path = os.path.join(os.getcwd(), path) if path in testcases_cache_mapping: return testcases_cache_mapping[path] if os.path.isdir(path): files_list = utils.load_folder_files(path) testcases_list = load_testcases_by_path(files_list) elif os.path.isfile(path): try: testset = load_test_file(path) if testset["testcases"] or testset["api"]: testcases_list = [testset] else: testcases_list = [] except exception.FileFormatError: testcases_list = [] else: logging.error(u"file not found: {}".format(path)) testcases_list = [] testcases_cache_mapping[path] = testcases_list return testcases_list