Skip to content

Commit 0eedeb7

Browse files
committed
[GR-20488] Add CI task for unittest retagger
PullRequest: graalpython/829
2 parents 66803f9 + 592b721 commit 0eedeb7

File tree

258 files changed

+2295
-2143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+2295
-2143
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "6ec8de6ed2c3aa9e0a603e4d89f5e686d725338a" }
1+
{ "overlay": "e395ba62d2ef675461ea7fc24bbfd488775e856f" }

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

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -106,8 +106,7 @@ def fun(self):
106106
import re
107107

108108
executable = sys.executable.split(" ") # HACK: our sys.executable on Java is a cmdline
109-
re_success = re.compile("(test\S+) \(([^\s]+)\) \.\.\. ok$", re.MULTILINE)
110-
re_failure = re.compile("(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)
111110
kwargs = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE, "text": True, "check": False}
112111

113112
glob_pattern = os.path.join(os.path.dirname(test.__file__), "test_*.py")
@@ -123,7 +122,7 @@ def fun(self):
123122
else:
124123
glob_pattern = os.path.join(os.path.dirname(test.__file__), arg)
125124

126-
p = subprocess.run(["/usr/bin/which", "timeout"], **kwargs)
125+
p = subprocess.run(["/usr/bin/which", "timeout" if sys.platform != 'darwin' else 'gtimeout'], **kwargs)
127126
if p.returncode != 0:
128127
print("Cannot find the 'timeout' GNU tool. Do you have coreutils installed?")
129128
sys.exit(1)
@@ -140,9 +139,9 @@ def fun(self):
140139
# entirely
141140
testfile_stem = os.path.splitext(os.path.basename(testfile))[0]
142141
testmod = "test." + testfile_stem
143-
cmd = [timeout, "-s", "9", "60"] + executable + ["-S", "-m"]
142+
cmd = [timeout, "-s", "9", "120"] + executable + ["-S", "-m"]
144143
tagfile = os.path.join(TAGS_DIR, testfile_stem + ".txt")
145-
if retag:
144+
if retag and repeat == 0:
146145
test_selectors = []
147146
else:
148147
test_selectors = working_selectors(tagfile)
@@ -165,64 +164,59 @@ def fun(self):
165164
print("*stderr*")
166165
print(p.stderr)
167166

168-
if p.returncode == 0 and not os.path.exists(tagfile):
169-
# if we're re-tagging a test without tags, all passed
170-
with open(tagfile, "w") as f:
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:
171174
pass
172-
break
173-
elif p.returncode == 0:
174-
# we ran the tagged tests and they were fine
175-
break
176-
elif repeat < maxrepeats:
177-
# we failed the first run, create a tag file with the passing
178-
# tests (if any)
179-
passing_tests = []
180-
failed_tests = []
181-
182-
def get_pass_name(funcname, classname):
183-
try:
184-
imported_test_module = __import__(testmod)
185-
except:
186-
imported_test_module = None
187-
else:
188-
# try hard to get a most specific pattern
189-
classname = "".join(classname.rpartition(testmod)[1:])
190-
clazz = imported_test_module
191-
path_to_class = classname.split(".")[1:]
192-
for part in path_to_class:
193-
clazz = getattr(clazz, part, None)
194-
if clazz:
195-
func = getattr(clazz, funcname, None)
196-
if func:
197-
return func.__qualname__
198-
return funcname
199-
200-
# n.b.: we add a '*' in the front, so that unittests doesn't add
201-
# its own asterisks, because now this is already a pattern
202-
203-
for funcname,classname in re_failure.findall(p.stdout):
204-
failed_tests.append("*" + get_pass_name(funcname, classname))
205-
for funcname,classname in re_failure.findall(p.stderr):
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'):
196+
passing_tests.append("*" + get_pass_name(funcname, classname))
197+
else:
206198
failed_tests.append("*" + get_pass_name(funcname, classname))
207199

208-
for funcname,classname in re_success.findall(p.stdout):
209-
passing_tests.append("*" + get_pass_name(funcname, classname))
210-
for funcname,classname in re_success.findall(p.stderr):
211-
passing_tests.append("*" + get_pass_name(funcname, classname))
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:
211+
os.unlink(tagfile)
212212

213-
# n.b.: unittests uses the __qualname__ of the function as
214-
# pattern, which we're trying to do as well. however, sometimes
215-
# the same function is shared in multiple test classes, and
216-
# fails in some. so we always subtract the failed patterns from
217-
# the passed patterns
218-
passing_only_patterns = set(passing_tests) - set(failed_tests)
219-
with open(tagfile, "w") as f:
220-
for passing_test in passing_only_patterns:
221-
f.write(passing_test)
222-
f.write("\n")
223-
if not passing_only_patterns:
224-
os.unlink(tagfile)
225-
else:
226-
# we tried the last time and failed, so our tags don't work for
227-
# some reason
213+
if p.returncode == 0:
214+
break
215+
216+
else:
217+
# we tried the last time and failed, so our tags don't work for
218+
# some reason
219+
try:
228220
os.unlink(tagfile)
221+
except Exception:
222+
pass

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/doctest_aliases.txt

Whitespace-only changes.

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/sample_doctest_no_docstrings.txt

Whitespace-only changes.

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/sample_doctest_no_doctests.txt

Whitespace-only changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
test_attributes
2-
test_names
1+
*FutureTest.test_attributes
2+
*FutureTest.test_names
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
test_float_parsing
1+
*_LocaleTests.test_float_parsing
2+
*_LocaleTests.test_lc_numeric_basic
3+
*_LocaleTests.test_lc_numeric_localeconv
4+
*_LocaleTests.test_lc_numeric_nl_langinfo
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
test__check_for_unavailable_sdk
2-
test__find_build_tool
3-
test__get_system_version
4-
test__override_all_archs
5-
test__remove_original_values
6-
test__remove_universal_flags
7-
test__save_modified_value
8-
test__save_modified_value_unchanged
9-
test_get_platform_osx
1+
*Test_OSXSupport.test__check_for_unavailable_sdk
2+
*Test_OSXSupport.test__find_build_tool
3+
*Test_OSXSupport.test__find_executable
4+
*Test_OSXSupport.test__get_system_version
5+
*Test_OSXSupport.test__override_all_archs
6+
*Test_OSXSupport.test__remove_original_values
7+
*Test_OSXSupport.test__remove_universal_flags
8+
*Test_OSXSupport.test__save_modified_value
9+
*Test_OSXSupport.test__save_modified_value_unchanged
10+
*Test_OSXSupport.test_get_platform_osx
Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1-
test_ABC_has___slots__
2-
test_abstractmethod_basics
3-
test_all_new_methods_are_called
4-
test_isinstance_invalidation
5-
test_issubclass_bad_arguments
6-
test_metaclass_abc
7-
test_register_as_class_deco
8-
test_register_non_class
9-
test_registration_basics
10-
test_registration_builtins
11-
test_registration_edge_cases
12-
test_registration_transitiveness
13-
test_tricky_new_works
14-
test_works_with_init_subclass
15-
test_ABC_has___slots__
16-
test_abstractmethod_basics
17-
test_all_new_methods_are_called
18-
test_isinstance_invalidation
19-
test_issubclass_bad_arguments
20-
test_metaclass_abc
21-
test_register_as_class_deco
22-
test_register_non_class
23-
test_registration_basics
24-
test_registration_builtins
25-
test_registration_edge_cases
26-
test_registration_transitiveness
27-
test_tricky_new_works
28-
test_works_with_init_subclass
1+
*test_ABC_has___slots__
2+
*test_abstractmethod_basics
3+
*test_all_new_methods_are_called
4+
*test_isinstance_invalidation
5+
*test_issubclass_bad_arguments
6+
*test_metaclass_abc
7+
*test_register_as_class_deco
8+
*test_register_non_class
9+
*test_registration_basics
10+
*test_registration_builtins
11+
*test_registration_edge_cases
12+
*test_registration_transitiveness
13+
*test_tricky_new_works
14+
*test_works_with_init_subclass
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
test_complex
2-
test_float
3-
test_int
1+
*TestNumbers.test_complex
2+
*TestNumbers.test_float
3+
*TestNumbers.test_int

0 commit comments

Comments
 (0)