Skip to content

Commit 4b88ff0

Browse files
committed
add tagfiles
1 parent 6a91e50 commit 4b88ff0

File tree

218 files changed

+4857
-136
lines changed

Some content is hidden

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

218 files changed

+4857
-136
lines changed

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

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,38 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939

40+
import glob
4041
import os
4142
import subprocess
4243
import sys
4344
import test
4445

4546

46-
TAGS_FILE = os.path.join(os.path.dirname(__file__), "working_unittests.txt")
47+
TAGS_DIR = os.path.join(os.path.dirname(__file__), "unittest_tags")
4748

4849

49-
def working_tests():
50-
working_tests = []
50+
def working_selectors(tagfile):
51+
if os.path.exists(tagfile):
52+
with open(tagfile) as f:
53+
return [line.strip() for line in f if line]
54+
else:
55+
return []
5156

52-
def parse_line(iterator, line):
53-
line = line.strip()
54-
if line.endswith(":"):
55-
test_selectors = []
56-
for testline in iterator:
57-
if testline.startswith(" "):
58-
test_selectors.append(testline.strip())
59-
else:
60-
parse_line(iterator, testline)
61-
working_tests.append((line[:-1], test_selectors))
62-
elif line:
63-
working_tests.append(line)
64-
65-
with open(TAGS_FILE) as f:
66-
fiter = iter(f)
67-
for line in fiter:
68-
parse_line(fiter, line)
6957

58+
def working_tests():
59+
working_tests = []
60+
for tagfile in glob.glob(os.path.join(TAGS_DIR, "*.txt")):
61+
test = os.path.splitext(os.path.basename(tagfile))[0]
62+
working_tests.append((test, working_selectors(tagfile)))
7063
return working_tests
7164

7265

7366
for working_test in working_tests():
7467
def make_test_func(working_test):
7568
def fun():
76-
if isinstance(working_test, str):
77-
subprocess.check_call([sys.executable, "-m", working_test])
69+
if not working_test[1]: # no selectors, run entire test module
70+
# TODO: remove branch
71+
subprocess.check_call([sys.executable, "-m", "test." + working_test[0]])
7872
else:
7973
cmd = [sys.executable, "-m", "unittest"]
8074
for testpattern in working_test[1]:
@@ -83,7 +77,7 @@ def fun():
8377
cmd.append(os.path.join(os.path.dirname(test.__file__), "%s.py" % testmod))
8478
subprocess.check_call(cmd)
8579

86-
fun.__name__ = working_test if isinstance(working_test, str) else working_test[0]
80+
fun.__name__ = working_test[0]
8781
return fun
8882

8983
test_f = make_test_func(working_test)
@@ -93,36 +87,53 @@ def fun():
9387

9488
if __name__ == "__main__":
9589
# find working tests
96-
import glob
9790
import re
9891

9992
executable = sys.executable.split(" ") # HACK: our sys.executable on Java is a cmdline
100-
re_success = re.compile("(test[^ ]+).* ... ok")
101-
with open(TAGS_FILE, "w") as f:
102-
for testfile in glob.glob(os.path.join(os.path.dirname(test.__file__), "test_*.py")):
103-
testmod = "test.%s" % os.path.splitext(os.path.basename(testfile))[0]
93+
re_success = re.compile("^(test\S+)[^\r\n]* \.\.\. ok$", re.MULTILINE)
94+
kwargs = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE, "text": True, "check": False}
95+
96+
if len(sys.argv) > 1:
97+
glob_pattern = sys.argv[1]
98+
else:
99+
glob_pattern = os.path.join(os.path.dirname(test.__file__), "test_*.py")
100+
101+
for testfile in glob.glob(glob_pattern):
102+
testfile_stem = os.path.splitext(os.path.basename(testfile))[0]
103+
testmod = "test." + testfile_stem
104+
cmd = ["/usr/bin/timeout", "-s", "9", "60"] + executable + ["-m"]
105+
tagfile = os.path.join(TAGS_DIR, testfile_stem + ".txt")
106+
test_selectors = working_selectors(tagfile)
107+
108+
if not test_selectors:
109+
# TODO: remove branch
104110
print("Testing", testmod)
105-
try:
106-
subprocess.check_call(["/usr/bin/timeout", "-s", "9", "60"] + executable + ["-m", testmod, "-f"])
107-
f.write(testmod)
108-
f.write("\n")
109-
except BaseException as e:
110-
print(e)
111-
p = subprocess.run(["/usr/bin/timeout", "-s", "9", "60"] + executable + ["-m", testmod, "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False)
112-
print("***")
113-
print(p.stdout)
114-
print("***")
115-
print(p.stderr)
116-
print("***")
117-
passing_tests = []
118-
for m in re_success.findall(p.stdout):
119-
passing_tests.append(m)
120-
for m in re_success.findall(p.stderr):
121-
passing_tests.append(m)
122-
if passing_tests:
123-
f.write(testmod)
124-
f.write(":\n")
125-
for passing_test in passing_tests:
126-
f.write(" ")
127-
f.write(passing_test)
128-
f.write("\n")
111+
cmd += [testmod, "-v"]
112+
else:
113+
print("Testing tagged subset of", testmod)
114+
cmd += ["unittest", "-v"]
115+
for selector in test_selectors:
116+
cmd += ["-k", selector]
117+
cmd.append(testfile)
118+
119+
p = subprocess.run(cmd, **kwargs)
120+
print("*stdout*")
121+
print(p.stdout)
122+
print("*stderr*")
123+
print(p.stderr)
124+
125+
if p.returncode == 0:
126+
with open(tagfile, "w") as f:
127+
pass
128+
else:
129+
passing_tests = []
130+
for m in re_success.findall(p.stdout):
131+
passing_tests.append(m)
132+
for m in re_success.findall(p.stderr):
133+
passing_tests.append(m)
134+
with open(tagfile, "w") as f:
135+
for passing_test in passing_tests:
136+
f.write(passing_test)
137+
f.write("\n")
138+
if not passing_tests:
139+
os.unlink(tagfile)

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.

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

Whitespace-only changes.

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

Whitespace-only changes.

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

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

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

Whitespace-only changes.

0 commit comments

Comments
 (0)