Skip to content

Commit

Permalink
feat: change extracted data from str to python object
Browse files Browse the repository at this point in the history
  • Loading branch information
wuranxu committed Jan 31, 2024
1 parent ac7934d commit 0743772
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
8 changes: 0 additions & 8 deletions app/core/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ def append(self, content, end=False):
else:
self.logger.append(content, end)

@case_log
async def parse_gconfig(self, data, type_, env, *fields):
"""
解析全局变量
"""
for f in fields:
await self.parse_field(data, f, GconfigType.text(type_), env)

async def load_testcase_variables(self, data, type_, params, *fields):
"""load_testcase_variables, include global variables"""
for f in fields:
Expand Down
10 changes: 5 additions & 5 deletions app/core/paramters/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def parse(source: dict, expression: str = "", **kwargs) -> Any:
@staticmethod
def parse_result(data: list, match_index: str = None):
if len(data) == 0:
return "null"
return None
# 如果是数字
length = len(data)
if match_index is not None:
if match_index.isdigit():
idx = int(match_index)
if idx >= length or idx < -length:
raise CaseParametersError(f"results length is {length}, index is not in [{-length}, {length})")
return json.dumps(data[idx], ensure_ascii=False)
return data[idx]
if match_index.lower() == 'random':
# 随机选取
return json.dumps(random.choice(data), ensure_ascii=False)
return random.choice(data)
if match_index.lower() == 'all':
return json.dumps(data, ensure_ascii=False)
return data
raise CaseParametersError(f"invalid match index: {match_index}, not number or random")
return json.dumps(data, ensure_ascii=False)
return data

0 comments on commit 0743772

Please sign in to comment.