mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-15 20:38:44 +08:00
parse functions: add support for variable argument
This commit is contained in:
11
ate/utils.py
11
ate/utils.py
@@ -17,7 +17,7 @@ except NameError:
|
||||
PYTHON_VERSION = 3
|
||||
|
||||
variable_regexp = re.compile(r"^\$(\w+)$")
|
||||
function_regexp = re.compile(r"^\$\{(\w+)\(([\w =,]*)\)\}$")
|
||||
function_regexp = re.compile(r"^\$\{(\w+)\(([\$\w =,]*)\)\}$")
|
||||
|
||||
def gen_random_string(str_len):
|
||||
return ''.join(
|
||||
@@ -168,10 +168,19 @@ def is_functon(content):
|
||||
return True if matched else False
|
||||
|
||||
def parse_string_value(str_value):
|
||||
""" parse string to number if possible
|
||||
e.g. "123" => 123
|
||||
"12.2" => 12.3
|
||||
"abc" => "abc"
|
||||
"$var" => "$var"
|
||||
"""
|
||||
try:
|
||||
return ast.literal_eval(str_value)
|
||||
except ValueError:
|
||||
return str_value
|
||||
except SyntaxError:
|
||||
# e.g. $var, ${func}
|
||||
return str_value
|
||||
|
||||
def parse_function(content):
|
||||
""" parse function name and args from string content.
|
||||
|
||||
Reference in New Issue
Block a user