From 9225848ffb2327d3cb7f89c7059f032b2c3a919c Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 5 Dec 2019 20:07:51 +0800 Subject: [PATCH] change: format code --- httprunner/parser.py | 19 ++++++++++++------- tests/test_context.py | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/httprunner/parser.py b/httprunner/parser.py index 506783c3..d6b5a5fe 100644 --- a/httprunner/parser.py +++ b/httprunner/parser.py @@ -379,6 +379,7 @@ def extend_validators(raw_validators, override_validators): def_validators_mapping.update(ref_validators_mapping) return list(def_validators_mapping.values()) + ############################################################################### ## parse content with variables and functions mapping ############################################################################### @@ -408,8 +409,8 @@ def get_mapping_function(function_name, functions_mapping): if not found, then try to check if builtin function. Args: - variable_name (str): variable name - variables_mapping (dict): variables mapping + function_name (str): function name + functions_mapping (dict): functions mapping Returns: mapping function object. @@ -499,6 +500,7 @@ def parse_function_params(params): class LazyFunction(object): """ call function lazily. """ + def __init__(self, function_meta, functions_mapping=None, check_variables_set=None): """ init LazyFunction object with function_meta @@ -592,6 +594,7 @@ cached_functions_mapping = {} class LazyString(object): """ evaluate string lazily. """ + def __init__(self, raw_string, functions_mapping=None, check_variables_set=None, cached=False): """ make raw_string as lazy object with functions_mapping check if any variable undefined in check_variables_set @@ -672,7 +675,7 @@ class LazyString(object): curr_position = match_start_position try: # find next $ location - match_start_position = raw_string.index("$", curr_position+1) + match_start_position = raw_string.index("$", curr_position + 1) remain_string = raw_string[curr_position:match_start_position] except ValueError: remain_string = raw_string[curr_position:] @@ -1004,7 +1007,8 @@ def _extend_with_testcase(test_dict, testcase_def_dict): """ # override testcase config variables testcase_def_dict["config"].setdefault("variables", {}) - testcase_def_variables = utils.ensure_mapping_format(testcase_def_dict["config"].get("variables", {})) + testcase_def_variables = utils.ensure_mapping_format( + testcase_def_dict["config"].get("variables", {})) testcase_def_variables.update(test_dict.pop("variables", {})) testcase_def_dict["config"]["variables"] = testcase_def_variables @@ -1016,8 +1020,8 @@ def _extend_with_testcase(test_dict, testcase_def_dict): # override name test_name = test_dict.pop("name", None) \ - or testcase_def_dict["config"].pop("name", None) \ - or "testcase name undefined" + or testcase_def_dict["config"].pop("name", None) \ + or "testcase name undefined" # override testcase config name, output, etc. testcase_def_dict["config"].update(test_dict) @@ -1036,7 +1040,8 @@ def __prepare_config(config, project_mapping, session_variables_set=None): override_variables = utils.deepcopy_dict(project_mapping.get("variables", {})) functions = project_mapping.get("functions", {}) - if isinstance(raw_config_variables, basestring) and function_regex_compile.match(raw_config_variables): + if isinstance(raw_config_variables, basestring) and function_regex_compile.match( + raw_config_variables): # config variables are generated by calling function # e.g. # "config": { diff --git a/tests/test_context.py b/tests/test_context.py index 67367c97..a0c6b203 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -9,7 +9,6 @@ class TestContext(ApiServerUnittest): def setUp(self): loader.load_project_tests(os.path.join(os.getcwd(), "tests")) - project_mapping = loader.project_mapping self.context = context.SessionContext( variables={"SECRET_KEY": "DebugTalk"} )