From 0743772d048203eb7b065173bc8d29df01397445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B1=B3=E6=B4=9B?= <619434176@qq.com> Date: Wed, 31 Jan 2024 23:29:24 +0800 Subject: [PATCH] feat: change extracted data from str to python object --- app/core/executor.py | 8 -------- app/core/paramters/parser.py | 10 +++++----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/app/core/executor.py b/app/core/executor.py index e47b0e78..c9cb1613 100755 --- a/app/core/executor.py +++ b/app/core/executor.py @@ -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: diff --git a/app/core/paramters/parser.py b/app/core/paramters/parser.py index 2e9938df..1c838c91 100644 --- a/app/core/paramters/parser.py +++ b/app/core/paramters/parser.py @@ -14,7 +14,7 @@ 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: @@ -22,11 +22,11 @@ def parse_result(data: list, match_index: str = None): 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