make variables marker unified to be

This commit is contained in:
debugtalk
2017-06-27 23:56:59 +08:00
parent baf2d1c8b6
commit 887845493d
7 changed files with 33 additions and 30 deletions

View File

@@ -2,8 +2,8 @@ import hashlib
import json
import os.path
import random
import re
import string
import yaml
from ate.exception import ParamsError
@@ -190,3 +190,23 @@ def load_testcases_by_path(path):
else:
return []
def parse_content_with_variables(content, variables_binds):
""" replace variables with bind value
"""
# check if content includes ${variable}
matched = re.match(r"(.*)\$\{(.*)\}(.*)", content)
if matched:
# this is a variable, and will replace with its bind value
variable_name = matched.group(2)
value = variables_binds.get(variable_name)
if value is None:
raise ParamsError(
"%s is not defined in bind variables!" % variable_name)
if matched.group(1) or matched.group(3):
# e.g. /api/users/${uid}
return re.sub(r"\$\{.*\}", value, content)
return value
return content