def import_module_items(self, imported_module): """ import module functions and variables and bind to testset context """ imported_functions_dict = utils.filter_module(imported_module, "function") self.__update_context_functions_config("testset", imported_functions_dict) imported_variables_dict = utils.filter_module(imported_module, "variable") self.bind_variables(imported_variables_dict, "testset")
def import_module_items(self, modules, level="testcase"): """ import modules and bind all functions within the context """ sys.path.insert(0, os.getcwd()) for module_name in modules: imported_module = utils.get_imported_module(module_name) imported_functions_dict = utils.filter_module(imported_module, "function") self.__update_context_functions_config(level, imported_functions_dict) imported_variables_dict = utils.filter_module(imported_module, "variable") self.bind_variables(imported_variables_dict, level)
def test_filter_module_functions(self): imported_module = utils.get_imported_module("httprunner.utils") self.assertIn("PYTHON_VERSION", dir(imported_module)) functions_dict = utils.filter_module(imported_module, "function") self.assertIn("filter_module", functions_dict) self.assertNotIn("PYTHON_VERSION", functions_dict)
def test_get_imported_module_from_file(self): imported_module = utils.get_imported_module_from_file("tests/data/debugtalk.py") self.assertIn("gen_md5", dir(imported_module)) functions_dict = utils.filter_module(imported_module, "function") self.assertIn("gen_md5", functions_dict) self.assertNotIn("PYTHON_VERSION", functions_dict) with self.assertRaises(exception.FileNotFoundError): utils.get_imported_module_from_file("tests/data/debugtalk2.py")
def test_get_imported_module_from_file(self): imported_module = utils.get_imported_module_from_file("tests/debugtalk.py") self.assertIn("gen_md5", dir(imported_module)) functions_dict = utils.filter_module(imported_module, "function") self.assertIn("gen_md5", functions_dict) self.assertNotIn("urllib", functions_dict) with self.assertRaises(exception.FileNotFoundError): utils.get_imported_module_from_file("tests/debugtalk2.py")
def import_module_items(self, modules, level="testcase"): """ import modules and bind all functions within the context """ #在程序的生命周期内引入工作目录路径到环境变量 sys.path.insert(0, os.getcwd()) for module_name in modules: #导入并返回指定的模块 imported_module = utils.get_imported_module(module_name) #将导入的模块里,类型是function的筛选出来,存入字典imported_functions_dict中 imported_functions_dict = utils.filter_module( imported_module, "function") #将imported_functions_dict字典更新到列表testcase_functions_config #和实例testcase_parser的列表bind_functions self.__update_context_functions_config(level, imported_functions_dict) # 将导入的模块里,类型是variable的筛选出来,存入字典imported_variables_dict中 imported_variables_dict = utils.filter_module( imported_module, "variable") self.bind_variables(imported_variables_dict, level)
def test_validators(self): imported_module = utils.get_imported_module("httprunner.built_in") functions_mapping = utils.filter_module(imported_module, "function") functions_mapping["equals"](None, None) functions_mapping["equals"](1, 1) functions_mapping["equals"]("abc", "abc") with self.assertRaises(AssertionError): functions_mapping["equals"]("123", 123) functions_mapping["less_than"](1, 2) functions_mapping["less_than_or_equals"](2, 2) functions_mapping["greater_than"](2, 1) functions_mapping["greater_than_or_equals"](2, 2) functions_mapping["not_equals"](123, "123") functions_mapping["length_equals"]("123", 3) functions_mapping["length_greater_than"]("123", 2) functions_mapping["length_greater_than_or_equals"]("123", 3) functions_mapping["contains"]("123abc456", "3ab") functions_mapping["contains"](['1', '2'], "1") functions_mapping["contains"]({'a': 1, 'b': 2}, "a") functions_mapping["contained_by"]("3ab", "123abc456") functions_mapping["regex_match"]("123abc456", "^123\w+456$") with self.assertRaises(AssertionError): functions_mapping["regex_match"]("123abc456", "^12b.*456$") functions_mapping["startswith"]("abc123", "ab") functions_mapping["startswith"]("123abc", 12) functions_mapping["startswith"](12345, 123) functions_mapping["endswith"]("abc123", 23) functions_mapping["endswith"]("123abc", "abc") functions_mapping["endswith"](12345, 45) functions_mapping["type_match"](580509390, int) functions_mapping["type_match"](580509390, "int") functions_mapping["type_match"]([], list) functions_mapping["type_match"]([], "list") functions_mapping["type_match"]([1], "list") functions_mapping["type_match"]({}, "dict") functions_mapping["type_match"]({"a": 1}, "dict")
def test_validators(self): imported_module = utils.get_imported_module("httprunner.built_in") functions_mapping = utils.filter_module(imported_module, "function") functions_mapping["equals"](None, None) functions_mapping["equals"](1, 1) functions_mapping["equals"]("abc", "abc") with self.assertRaises(AssertionError): functions_mapping["equals"]("123", 123) functions_mapping["less_than"](1, 2) functions_mapping["less_than_or_equals"](2, 2) functions_mapping["greater_than"](2, 1) functions_mapping["greater_than_or_equals"](2, 2) functions_mapping["not_equals"](123, "123") functions_mapping["length_equals"]("123", 3) functions_mapping["length_greater_than"]("123", 2) functions_mapping["length_greater_than_or_equals"]("123", 3) functions_mapping["contains"]("123abc456", "3ab") functions_mapping["contains"](['1', '2'], "1") functions_mapping["contains"]({'a':1, 'b':2}, "a") functions_mapping["contained_by"]("3ab", "123abc456") functions_mapping["regex_match"]("123abc456", "^123\w+456$") with self.assertRaises(AssertionError): functions_mapping["regex_match"]("123abc456", "^12b.*456$") functions_mapping["startswith"]("abc123", "ab") functions_mapping["startswith"]("123abc", 12) functions_mapping["startswith"](12345, 123) functions_mapping["endswith"]("abc123", 23) functions_mapping["endswith"]("123abc", "abc") functions_mapping["endswith"](12345, 45)
def setUp(self): imported_module = utils.get_imported_module("httprunner.built_in") self.functions_mapping = utils.filter_module(imported_module, "function")