You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
tests: Make cmdline tests more stable by using regex for matching.
This commit is contained in:
+220
-344
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,9 @@
|
||||
1
|
||||
File cmdline/cmd_verbose.py, code block '<module>' (descriptor: ######
|
||||
Raw bytecode (code_info_size=8, bytecode_size=13):
|
||||
08 82 23 83 45 43 00 00 02 00 00 1c 81 13 00 81
|
||||
64 01 32 11 5b
|
||||
File cmdline/cmd_verbose.py, code block '<module>' (descriptor: \.\+, bytecode \.\+ bytes)
|
||||
Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
|
||||
08 \.\+
|
||||
########
|
||||
\.\+5b
|
||||
arg names:
|
||||
(N_STATE 2)
|
||||
(N_EXC_STACK 0)
|
||||
@@ -15,7 +16,7 @@ arg names:
|
||||
07 POP_TOP
|
||||
08 LOAD_CONST_NONE
|
||||
09 RETURN_VALUE
|
||||
mem: total=######
|
||||
stack: ######
|
||||
GC: total: ######
|
||||
No. of 1-blocks: ######
|
||||
mem: total=\\d\+, current=\\d\+, peak=\\d\+
|
||||
stack: \\d\+ out of \\d\+
|
||||
GC: total: \\d\+, used: \\d\+, free: \\d\+
|
||||
No. of 1-blocks: \\d\+, 2-blocks: \\d\+, max blk sz: \\d\+
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Micro Python ######
|
||||
Micro Python v\.\+ version
|
||||
>>> # basic REPL tests
|
||||
>>> print(1)
|
||||
1
|
||||
|
||||
+47
-8
@@ -5,6 +5,7 @@ import subprocess
|
||||
import sys
|
||||
import platform
|
||||
import argparse
|
||||
import re
|
||||
from glob import glob
|
||||
|
||||
# Tests require at least CPython 3.3. If your default python3 executable
|
||||
@@ -49,18 +50,56 @@ def run_micropython(pyb, args, test_file):
|
||||
except subprocess.CalledProcessError:
|
||||
output_mupy = b'CRASH'
|
||||
|
||||
# erase parts of the output that are not stable across runs
|
||||
# unescape wanted regex chars and escape unwanted ones
|
||||
def convert_regex_escapes(line):
|
||||
cs = []
|
||||
escape = False
|
||||
for c in str(line, 'utf8'):
|
||||
if escape:
|
||||
escape = False
|
||||
cs.append(c)
|
||||
elif c == '\\':
|
||||
escape = True
|
||||
elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'):
|
||||
cs.append('\\' + c)
|
||||
else:
|
||||
cs.append(c)
|
||||
return bytes(''.join(cs), 'utf8')
|
||||
|
||||
# convert parts of the output that are not stable across runs
|
||||
with open(test_file + '.exp', 'rb') as f:
|
||||
lines_exp = f.readlines()
|
||||
lines_exp = []
|
||||
for line in f.readlines():
|
||||
if line == b'########\n':
|
||||
line = (line,)
|
||||
else:
|
||||
line = (line, re.compile(convert_regex_escapes(line)))
|
||||
lines_exp.append(line)
|
||||
lines_mupy = [line + b'\n' for line in output_mupy.split(b'\n')]
|
||||
if output_mupy.endswith(b'\n'):
|
||||
lines_mupy = lines_mupy[:-1] # remove erroneous last empty line
|
||||
if len(lines_mupy) == len(lines_exp):
|
||||
for i in range(len(lines_mupy)):
|
||||
pos = lines_exp[i].find(b'######')
|
||||
if pos != -1 and len(lines_mupy[i]) >= pos:
|
||||
lines_mupy[i] = lines_mupy[i][:pos] + b'######\n'
|
||||
output_mupy = b''.join(lines_mupy)
|
||||
i_mupy = 0
|
||||
for i in range(len(lines_exp)):
|
||||
if lines_exp[i][0] == b'########\n':
|
||||
# 8x #'s means match 0 or more whole lines
|
||||
line_exp = lines_exp[i + 1]
|
||||
skip = 0
|
||||
while i_mupy + skip < len(lines_mupy) and not line_exp[1].match(lines_mupy[i_mupy + skip]):
|
||||
skip += 1
|
||||
if i_mupy + skip >= len(lines_mupy):
|
||||
lines_mupy[i_mupy] = b'######## FAIL\n'
|
||||
break
|
||||
del lines_mupy[i_mupy:i_mupy + skip]
|
||||
lines_mupy.insert(i_mupy, b'########\n')
|
||||
i_mupy += 1
|
||||
else:
|
||||
# a regex
|
||||
if lines_exp[i][1].match(lines_mupy[i_mupy]):
|
||||
lines_mupy[i_mupy] = lines_exp[i][0]
|
||||
i_mupy += 1
|
||||
if i_mupy >= len(lines_mupy):
|
||||
break
|
||||
output_mupy = b''.join(lines_mupy)
|
||||
|
||||
else:
|
||||
# a standard test
|
||||
|
||||
Reference in New Issue
Block a user