mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 23:41:22 +08:00
update docstring for extract_functions and extract_variables
This commit is contained in:
@@ -32,13 +32,26 @@ def parse_string_value(str_value):
|
|||||||
|
|
||||||
def extract_variables(content):
|
def extract_variables(content):
|
||||||
""" extract all variable names from content, which is in format $variable
|
""" extract all variable names from content, which is in format $variable
|
||||||
@param (str) content
|
|
||||||
@return (list) variable name list
|
|
||||||
|
|
||||||
e.g. $variable => ["variable"]
|
Args:
|
||||||
/blog/$postid => ["postid"]
|
content (str): string content
|
||||||
/$var1/$var2 => ["var1", "var2"]
|
|
||||||
abc => []
|
Returns:
|
||||||
|
list: variables list extracted from string content
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
>>> extract_variables("$variable")
|
||||||
|
["variable"]
|
||||||
|
|
||||||
|
>>> extract_variables("/blog/$postid")
|
||||||
|
["postid"]
|
||||||
|
|
||||||
|
>>> extract_variables("/$var1/$var2")
|
||||||
|
["var1", "var2"]
|
||||||
|
|
||||||
|
>>> extract_variables("abc")
|
||||||
|
[]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# TODO: change variable notation from $var to {{var}}
|
# TODO: change variable notation from $var to {{var}}
|
||||||
try:
|
try:
|
||||||
@@ -47,6 +60,38 @@ def extract_variables(content):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def extract_functions(content):
|
||||||
|
""" extract all functions from string content, which are in format ${fun()}
|
||||||
|
|
||||||
|
Args:
|
||||||
|
content (str): string content
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: functions list extracted from string content
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
>>> extract_functions("${func(5)}")
|
||||||
|
["func(5)"]
|
||||||
|
|
||||||
|
>>> extract_functions("${func(a=1, b=2)}")
|
||||||
|
["func(a=1, b=2)"]
|
||||||
|
|
||||||
|
>>> extract_functions("/api/1000?_t=${get_timestamp()}")
|
||||||
|
["get_timestamp()"]
|
||||||
|
|
||||||
|
>>> extract_functions("/api/${add(1, 2)}")
|
||||||
|
["add(1, 2)"]
|
||||||
|
|
||||||
|
>>> extract_functions("/api/${add(1, 2)}?_t=${get_timestamp()}")
|
||||||
|
["add(1, 2)", "get_timestamp()"]
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return re.findall(function_regexp, content)
|
||||||
|
except TypeError:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def parse_function(content):
|
def parse_function(content):
|
||||||
""" parse function name and args from string content.
|
""" parse function name and args from string content.
|
||||||
@param (str) content
|
@param (str) content
|
||||||
@@ -248,23 +293,6 @@ def parse_parameters(parameters, testset_path=None):
|
|||||||
return utils.gen_cartesian_product(*parsed_parameters_list)
|
return utils.gen_cartesian_product(*parsed_parameters_list)
|
||||||
|
|
||||||
|
|
||||||
def extract_functions(content):
|
|
||||||
""" extract all functions from string content, which are in format ${fun()}
|
|
||||||
@param (str) content
|
|
||||||
@return (list) functions list
|
|
||||||
|
|
||||||
e.g. ${func(5)} => ["func(5)"]
|
|
||||||
${func(a=1, b=2)} => ["func(a=1, b=2)"]
|
|
||||||
/api/1000?_t=${get_timestamp()} => ["get_timestamp()"]
|
|
||||||
/api/${add(1, 2)} => ["add(1, 2)"]
|
|
||||||
"/api/${add(1, 2)}?_t=${get_timestamp()}" => ["add(1, 2)", "get_timestamp()"]
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
return re.findall(function_regexp, content)
|
|
||||||
except TypeError:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
class TestcaseParser(object):
|
class TestcaseParser(object):
|
||||||
|
|
||||||
def __init__(self, variables={}, functions={}, file_path=None):
|
def __init__(self, variables={}, functions={}, file_path=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user