Skip to content

Commit c62c3d5

Browse files
committed
Relax the test result matching regex
1 parent e5273d5 commit c62c3d5

File tree

1 file changed

+51
-52
lines changed

1 file changed

+51
-52
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ def fun(self):
106106
import re
107107

108108
executable = sys.executable.split(" ") # HACK: our sys.executable on Java is a cmdline
109-
# We consider skipped tests as passing in order to avoid a situation where a Linux run
110-
# untags a Darwin-only test and vice versa
111-
re_success = re.compile(r"(test\S+) \(([^\s]+)\) \.\.\. (?:ok|skipped.*)$", re.MULTILINE)
112-
re_failure = re.compile(r"(test\S+) \(([^\s]+)\) \.\.\. (?:ERROR|FAIL)$", re.MULTILINE)
109+
re_test_result = re.compile(r"""(test\S+) \(([^\s]+)\)(?:\n.*?)? \.\.\. \b(ok|skipped(?: ["'][^\n]+)?|ERROR|FAIL)$""", re.MULTILINE | re.DOTALL)
113110
kwargs = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE, "text": True, "check": False}
114111

115112
glob_pattern = os.path.join(os.path.dirname(test.__file__), "test_*.py")
@@ -167,57 +164,59 @@ def fun(self):
167164
print("*stderr*")
168165
print(p.stderr)
169166

170-
if repeat < maxrepeats:
171-
passing_tests = []
172-
failed_tests = []
173-
174-
def get_pass_name(funcname, classname):
175-
try:
176-
imported_test_module = __import__(testmod)
177-
except:
178-
imported_test_module = None
179-
else:
180-
# try hard to get a most specific pattern
181-
classname = "".join(classname.rpartition(testmod)[1:])
182-
clazz = imported_test_module
183-
path_to_class = classname.split(".")[1:]
184-
for part in path_to_class:
185-
clazz = getattr(clazz, part, None)
186-
if clazz:
187-
func = getattr(clazz, funcname, None)
188-
if func:
189-
return func.__qualname__
190-
return funcname
191-
192-
# n.b.: we add a '*' in the front, so that unittests doesn't add
193-
# its own asterisks, because now this is already a pattern
194-
195-
for funcname,classname in re_failure.findall(p.stdout):
196-
failed_tests.append("*" + get_pass_name(funcname, classname))
197-
for funcname,classname in re_failure.findall(p.stderr):
198-
failed_tests.append("*" + get_pass_name(funcname, classname))
199-
200-
for funcname,classname in re_success.findall(p.stdout):
201-
passing_tests.append("*" + get_pass_name(funcname, classname))
202-
for funcname,classname in re_success.findall(p.stderr):
167+
passing_tests = []
168+
failed_tests = []
169+
170+
def get_pass_name(funcname, classname):
171+
try:
172+
imported_test_module = __import__(testmod)
173+
except Exception:
174+
pass
175+
else:
176+
# try hard to get a most specific pattern
177+
classname = "".join(classname.rpartition(testmod)[1:])
178+
clazz = imported_test_module
179+
path_to_class = classname.split(".")[1:]
180+
for part in path_to_class:
181+
clazz = getattr(clazz, part, None)
182+
if clazz:
183+
func = getattr(clazz, funcname, None)
184+
if func:
185+
return func.__qualname__
186+
return funcname
187+
188+
stderr = p.stderr.replace("Please note: This Python implementation is in the very early stages, and can run little more than basic benchmarks at this point.\n", '')
189+
190+
# n.b.: we add a '*' in the front, so that unittests doesn't add
191+
# its own asterisks, because now this is already a pattern
192+
for funcname, classname, result in re_test_result.findall(stderr):
193+
# We consider skipped tests as passing in order to avoid a situation where a Linux run
194+
# untags a Darwin-only test and vice versa
195+
if result == 'ok' or result.startswith('skipped'):
203196
passing_tests.append("*" + get_pass_name(funcname, classname))
197+
else:
198+
failed_tests.append("*" + get_pass_name(funcname, classname))
204199

205-
# n.b.: unittests uses the __qualname__ of the function as
206-
# pattern, which we're trying to do as well. however, sometimes
207-
# the same function is shared in multiple test classes, and
208-
# fails in some. so we always subtract the failed patterns from
209-
# the passed patterns
210-
passing_only_patterns = set(passing_tests) - set(failed_tests)
211-
with open(tagfile, "w") as f:
212-
for passing_test in sorted(passing_only_patterns):
213-
f.write(passing_test)
214-
f.write("\n")
215-
if not passing_only_patterns:
216-
os.unlink(tagfile)
217-
else:
218-
# we tried the last time and failed, so our tags don't work for
219-
# some reason
200+
# n.b.: unittests uses the __qualname__ of the function as
201+
# pattern, which we're trying to do as well. however, sometimes
202+
# the same function is shared in multiple test classes, and
203+
# fails in some. so we always subtract the failed patterns from
204+
# the passed patterns
205+
passing_only_patterns = set(passing_tests) - set(failed_tests)
206+
with open(tagfile, "w") as f:
207+
for passing_test in sorted(passing_only_patterns):
208+
f.write(passing_test)
209+
f.write("\n")
210+
if not passing_only_patterns:
220211
os.unlink(tagfile)
221212

222213
if p.returncode == 0:
223214
break
215+
216+
else:
217+
# we tried the last time and failed, so our tags don't work for
218+
# some reason
219+
try:
220+
os.unlink(tagfile)
221+
except Exception:
222+
pass

0 commit comments

Comments
 (0)