|
| 1 | +# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 3 | +# |
| 4 | +# The Universal Permissive License (UPL), Version 1.0 |
| 5 | +# |
| 6 | +# Subject to the condition set forth below, permission is hereby granted to any |
| 7 | +# person obtaining a copy of this software, associated documentation and/or |
| 8 | +# data (collectively the "Software"), free of charge and under any and all |
| 9 | +# copyright rights in the Software, and any and all patent rights owned or |
| 10 | +# freely licensable by each licensor hereunder covering either (i) the |
| 11 | +# unmodified Software as contributed to or provided by such licensor, or (ii) |
| 12 | +# the Larger Works (as defined below), to deal in both |
| 13 | +# |
| 14 | +# (a) the Software, and |
| 15 | +# |
| 16 | +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
| 17 | +# one is included with the Software each a "Larger Work" to which the Software |
| 18 | +# is contributed by such licensors), |
| 19 | +# |
| 20 | +# without restriction, including without limitation the rights to copy, create |
| 21 | +# derivative works of, display, perform, and distribute the Software and make, |
| 22 | +# use, sell, offer for sale, import, export, have made, and have sold the |
| 23 | +# Software and the Larger Work(s), and to sublicense the foregoing rights on |
| 24 | +# either these or other terms. |
| 25 | +# |
| 26 | +# This license is subject to the following condition: |
| 27 | +# |
| 28 | +# The above copyright notice and either this complete permission notice or at a |
| 29 | +# minimum a reference to the UPL must be included in all copies or substantial |
| 30 | +# portions of the Software. |
| 31 | +# |
| 32 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 33 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 34 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 35 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 36 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 37 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 38 | +# SOFTWARE. |
| 39 | + |
| 40 | +import os |
| 41 | +import subprocess |
| 42 | +import sys |
| 43 | +import test |
| 44 | + |
| 45 | + |
| 46 | +TAGS_FILE = os.path.join(os.path.dirname(__file__), "working_unittests.txt") |
| 47 | + |
| 48 | + |
| 49 | +def working_tests(): |
| 50 | + working_tests = [] |
| 51 | + |
| 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) |
| 69 | + |
| 70 | + return working_tests |
| 71 | + |
| 72 | + |
| 73 | +for working_test in working_tests(): |
| 74 | + def make_test_func(working_test): |
| 75 | + def fun(): |
| 76 | + if isinstance(working_test, str): |
| 77 | + subprocess.check_call([sys.executable, "-m", working_test]) |
| 78 | + else: |
| 79 | + cmd = [sys.executable, "-m", "unittest"] |
| 80 | + for testpattern in working_test[1]: |
| 81 | + cmd.extend(["-k", testpattern]) |
| 82 | + testmod = working_test[0].rpartition(".")[2] |
| 83 | + cmd.append(os.path.join(os.path.dirname(test.__file__), "%s.py" % testmod)) |
| 84 | + subprocess.check_call(cmd) |
| 85 | + |
| 86 | + fun.__name__ = working_test if isinstance(working_test, str) else working_test[0] |
| 87 | + return fun |
| 88 | + |
| 89 | + test_f = make_test_func(working_test) |
| 90 | + globals()[test_f.__name__] = test_f |
| 91 | + del test_f |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + # find working tests |
| 96 | + import glob |
| 97 | + import re |
| 98 | + |
| 99 | + 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] |
| 104 | + print("Testing", testmod) |
| 105 | + try: |
| 106 | + subprocess.check_call(["/usr/bin/timeout", "100"] + 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", "100", sys.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") |
0 commit comments