diff --git a/Runner/API/DefaultRunner.py b/Runner/API/DefaultRunner.py index 9b5f160..8904cfa 100644 --- a/Runner/API/DefaultRunner.py +++ b/Runner/API/DefaultRunner.py @@ -11,12 +11,9 @@ from Base.Class.Logger import * def reparse(regexp, string): import re - if isinstance(regexp, tuple): - reg = str(regexp[0]) - flg = eval('re.' + str(regexp[1]).upper()) - else: - reg = str(regexp) - flg = 0 + mut = isinstance(regexp, tuple) + reg = [str(regexp), str(regexp[0])][mut] + flg = [0, eval('re.%s' % str(regexp[1]).upper())][mut] if reg in ['', 'trim']: return ReText(string.strip()) else: @@ -38,7 +35,7 @@ class ReList(list): r = super().__getitem__(item) if isinstance(r, (list, tuple, set)): return __class__(r) - elif isinstance(r, (dict, )): + elif isinstance(r, (dict,)): return ReDict(r) else: return ReText(r) @@ -64,7 +61,7 @@ class ReDict(dict): def __getitem__(self, item): if item in self: r = super().__getitem__(item) - if isinstance(r, (dict, )): + if isinstance(r, (dict,)): return __class__(r) elif isinstance(r, (list, tuple, set)): return ReList(r) @@ -220,9 +217,6 @@ class TestCase: self.d = data['TestData']['views'] self.c = data['TestCase']['views'] - # print(self.h.where((self.h['Name'] == 'HTTP2'), inplace=False).dropna(how='all').reset_index(drop=True, inplace=False).loc[0].to_dict()) - # exit() - self._set_levels(testlves) self._set_request_mode(self.m) @@ -256,7 +250,7 @@ class TestCase: @staticmethod def _match_bool(value=None): return value in ['是', '开启', '打开', 'True', 'true', 'TRUE', True, 'Yes', 'yes', 'YES', 'Y', 'y', '1', 1, 1.0] - + @staticmethod def _match_mode(value=None): return value in ['会话模式', 'Session', 'session'] @@ -309,7 +303,8 @@ class TestCase: continue data[k] = self._sub_variable(text=data[k], vars_dict=vars_dict) return data - if isinstance(data, str): return self._sub_variable(data, vars_dict=vars_dict) + if isinstance(data, str): + return self._sub_variable(data, vars_dict=vars_dict) return data @staticmethod @@ -327,24 +322,27 @@ class TestCase: return str(text) def test_unit(self, data): - locals().setdefault('h', self.h.where((self.h['Name'] == data['HTTPChannel']), inplace=False).dropna(how='all').reset_index(drop=True, inplace=False).loc[0].to_dict()) + http = self.h.where((self.h['Name'] == data['HTTPChannel']), inplace=False).dropna(how='all').reset_index(drop=True, inplace=False).loc[0].to_dict() res_kwargs = { - 'method': data['HTTPMethod'], - 'url': self._sub_variable_auto((locals().get('h')['HostWithScheme'] or '') + (data['HTTPUri'] or '/'), [self._g, self._l]), - 'query': self._sub_variable_auto(auto_decode(data['HTTPQuery']), [self._g, self._l]), - 'data': None, - 'json': None, - 'file': None, - 'header': {}, - 'cookie': self._sub_variable_auto(auto_decode(data['HTTPCookie']), [self._g, self._l]), - 'auth': None, - 'timeout': 60, - 'proxy': None, + 'method': data['HTTPMethod'], + 'url': self._sub_variable_auto((http['HostWithScheme'] or '') + (data['HTTPUri'] or '/'), [self._g, self._l]), + 'query': self._sub_variable_auto(auto_decode(data['HTTPQuery']), [self._g, self._l]), + 'data': None, + 'json': None, + 'file': None, + 'header': {}, + 'cookie': self._sub_variable_auto( + auto_decode(data['HTTPCookie']), + [self._g, self._l] + ), + 'auth': None, + 'timeout': 60, + 'proxy': None, 'auto_redirect': self._match_bool(data['HTTPRedirect']), 'ignore_cert_error': False, 'debug': True } - res_kwargs['header'].update((auto_decode(locals().get('h')['DefaultHeader']) or {})) + res_kwargs['header'].update((auto_decode(http['DefaultHeader']) or {})) res_kwargs['header'].update((self._sub_variable_auto(auto_decode(data['HTTPHeader']), [self._g, self._l]) or {})) match self._match_parm_type(data['HTTPParamType']): case 10: @@ -356,21 +354,24 @@ class TestCase: res_kwargs['file'] = locals().setdefault('f', self._sub_variable_auto(auto_decode( data['HTTPParamOfFile']))) and {k: open(os.path.abspath(os.path.join(self.dirs, './%s' % v)), 'rb') for k, v in locals().get('f').items()} res = self.http.http(**res_kwargs) - locals().setdefault('_Status', ReText(res['status'] or '')) - locals().setdefault('_Reason', ReText(res['reason'] or '')) - locals().setdefault('_Header', ReDict(res['header'] or {}).update({'_': yaml_encode(dict(res['header'] or {}))})) - locals().setdefault('_Cookie', ReDict(res['cookie'] or {}).update({'_': '; '.join([k + '=' + (v or '') for k, v in dict(res['cookie'] or {}).items()])})) - locals().setdefault('_Body', ReText(res['text'] or '')) - locals().setdefault('_Json', ReDict(res['json'] or {})) + for var_name, var_value in { + '_Status': ReText(res['status'] or ''), + '_Reason': ReText(res['reason'] or ''), + '_Header': ReDict(res['header'] or {}).update({'_': yaml_encode(dict(res['header'] or {}))}), + '_Cookie': ReDict(res['cookie'] or {}).update({'_': '; '.join([k + '=' + (v or '') for k, v in dict(res['cookie'] or {}).items()])}), + '_Body': ReText(res['text'] or ''), + '_Json': ReDict(res['json'] or {}), + json_encode(None): None, + json_encode(bool(0)): bool(0), + json_encode(bool(1)): bool(1) + }.items(): + locals().setdefault(var_name, var_value) for k, v in (auto_decode(data['HTTPExtract']) or {}).items(): d = re.findall('^([0-9A-Za-z_]+).*?', v)[0] self._g[str(k)] = str(eval('_' + v.replace(d, d.title(), 1))) expect = self._to_string(data['HTTPAssertStatus']) if expect: - locals().setdefault('null', None) - locals().setdefault('true', True) - locals().setdefault('false', False) opers = [" == ", " != ", " >= ", " <= ", " > ", " < ", " in ", " not in "] opers_flag = 0 for v in opers: @@ -378,7 +379,7 @@ class TestCase: opers_flag = 1 break if opers_flag: - contrast = list(filter(lambda x: x,expect.split("\n"))) + contrast = list(filter(lambda x: x, expect.split("\n"))) for contr in contrast: exec('assert ' + self._sub_variable_auto(contr).replace('$', str(res['status']))) else: @@ -389,9 +390,6 @@ class TestCase: raise AssertionError(str(expect) + ' == ' + str(actual)) # sys.stderr.write() - - - def test(self, index): # print(view_case.loc[index]) main_case = dict(self.c.loc[index].to_dict()) diff --git a/main3.py b/main3.py index 6869cad..a1b7279 100644 --- a/main3.py +++ b/main3.py @@ -1,5 +1,26 @@ -def to_string(text): - if text is None: - return '' - return str(text) -exec('assert 1 == 2') +str0 = '''"it in the ..." in $['content']''' + +str1 = '''"it in the ..." in $['content']''' +str2 = '''$['content'] == "ha in the end."''' +str3 = '''"it in the ..." in $''' +str4 = """$w.dasfd[9][0] in 'it in the ...'""" +str5 = '''$.flag == true''' + +import re + + +str41 = """$w.dasfd[9][0] in 'it in the ...'""" +str42 = '''$w.dasfd[9][0] in "it in the ..."''' +str43 = """$w.dasfd['a']['vf'] in 'it in the ...'""" +str44 = """$w.dasfd['a']['vf in '] in true""" +str45 = """$null in true""" +str46 = "$w.dasfd['a']['vf in '] in \"true\"" + + +s = str45 +print(re.findall('[\"].*?[\"].*?[\s]*( in )[\s]*', s)) +print(re.findall('[\'].*?[\'].*?[\s]*( in )[\s]*', s)) +print(re.findall('[\s]*( in )[\s]*.*?[\"].*?[\"]', s)) +print(re.findall('[\s]*( in )[\s]*.*?[\'].*?[\']', s)) +# ? +# print(re.compile(' in ').sub(' IN ', str1))