make wrappers for get_bind_item

This commit is contained in:
debugtalk
2018-03-13 22:25:38 +08:00
parent 9044bfb971
commit c7a1a17b3c
2 changed files with 10 additions and 4 deletions

View File

@@ -209,7 +209,7 @@ class Context(object):
""" validate with functions
"""
comparator = utils.get_uniform_comparator(validator_dict["comparator"])
validate_func = self.testcase_parser.get_bind_item("function", comparator)
validate_func = self.testcase_parser.get_bind_function(comparator)
if not validate_func:
raise exception.FunctionNotFound("comparator not found: {}".format(comparator))

View File

@@ -718,7 +718,7 @@ class TestcaseParser(object):
"""
self.functions = functions
def get_bind_item(self, item_type, item_name):
def _get_bind_item(self, item_type, item_name):
if item_type == "function":
if item_name in self.functions:
return self.functions[item_name]
@@ -745,6 +745,12 @@ class TestcaseParser(object):
raise exception.ParamsError(
"{} is not defined in bind {}s!".format(item_name, item_type))
def get_bind_function(self, func_name):
return self._get_bind_item("function", func_name)
def get_bind_variable(self, variable_name):
return self._get_bind_item("variable", variable_name)
def parameterize(self, csv_file_name, fetch_method="Sequential"):
parameter_file_path = os.path.join(
os.path.dirname(self.file_path),
@@ -771,7 +777,7 @@ class TestcaseParser(object):
if func_name in ["parameterize", "P"]:
eval_value = self.parameterize(*args, **kwargs)
else:
func = self.get_bind_item("function", func_name)
func = self.get_bind_function(func_name)
eval_value = func(*args, **kwargs)
func_content = "${" + func_content + "}"
@@ -804,7 +810,7 @@ class TestcaseParser(object):
"""
variables_list = extract_variables(content)
for variable_name in variables_list:
variable_value = self.get_bind_item("variable", variable_name)
variable_value = self.get_bind_variable(variable_name)
if "${}".format(variable_name) == content:
# content is a variable