Skip to content

Commit 3fe8383

Browse files
committed
[GR-23080] Do not pollute source tree with generated test artifacts.
PullRequest: graalpython/1128
2 parents 1da8a60 + 950440b commit 3fe8383

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

.gitignore

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,12 @@ language
5252
/org.eclipse.jdt.core.prefs
5353
Python3.g4.stamp
5454
*.orig
55-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/Py*.c
56-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/_Py*.c
57-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/Test*.c
58-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/*.sha256
59-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/PointerEquality_Primitive.c
60-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/buffer.c
61-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/dealloc.c
62-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/format_specifier_w_star.c
63-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/memoryview_member_flags.c
64-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_H.c
65-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_I.c
66-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_K.c
67-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_O_conv.c
68-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_O_typecheck.c
69-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_S.c
70-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_U.c
71-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_Y.c
72-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/parseargs_valist.c
7355
/*.diff
7456
/testenv
7557
## generated from: pyhocon -i ci.hocon -f json -o ci.json
7658
/ci.json
7759
/*.err
7860
/graalpython/include/*
79-
/graalpython/com.oracle.graal.python.test/src/tests/cpyext/As_FileDescriptor_Testfile
8061
/.*.csv*
8162
/graal_dumps
8263
*.jfr

docs/contributor/CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ substituting TEST-PATTERN (and possibly the file glob on the third line) with
141141
the test you want to run. Note that you can insert `-d` to debug on the Java
142142
level or use `--inspect` to debug in the Chrome debugger.
143143

144-
mx [-d] python3 [--inspect] \
145-
graalpython/com.oracle.graal.python.test/src/graalpytest.py \
146-
graalpython/com.oracle.graal.python.test/src/tests/test_*.py \
144+
mx [-d] graalpytest [--inspect] test_*.py \
147145
-k TEST-PATTERN
148146

149147
To run the JUnit tests, you can use this command:

mx.graalpython/mx_graalpython.py

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -478,33 +478,46 @@ def _graalpytest_driver():
478478

479479

480480
def _graalpytest_root():
481-
return os.path.join(SUITE.dir, "graalpython", "com.oracle.graal.python.test", "src", "tests")
481+
return os.path.join(mx.dependency("com.oracle.graal.python.test").get_output_root(), "bin", "tests")
482482

483483

484484
def _hpy_test_root():
485485
return os.path.join(_get_core_home(), "modules", "hpy", "test")
486486

487487

488-
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=True, exclude=None, env=None):
489-
args = args or []
490-
args = ["--experimental-options=true",
491-
"--python.CatchAllExceptions=true"] + args
492-
exclude = exclude or []
493-
paths = paths or [_graalpytest_root()]
494-
if env is None:
495-
env = os.environ.copy()
488+
def graalpytest(args):
489+
parser = ArgumentParser(prog='mx graalpytest')
490+
parser.add_argument('--python', type=str, action='store', default="", help='Run tests with custom Python binary.')
491+
parser.add_argument('-v', "--verbose", action="store_true", help='Verbose output.')
492+
parser.add_argument('-k', dest="filter", default=[], help='Test pattern.')
493+
parser.add_argument('test', nargs="*", default=[], help='Test file to run (specify absolute or relative; e.g. "/path/to/test_file.py" or "cpyext/test_object.py") ')
494+
args, unknown_args = parser.parse_known_args(args)
495+
496+
# ensure that the test distribution is up-to-date
497+
mx.command_function("build")(["--dep", "com.oracle.graal.python.test"])
498+
499+
testfiles = _list_graalpython_unittests(args.test)
500+
# we assume that unknown args are polyglot arguments and just prepend them to the test driver
501+
cmd_args = unknown_args + [_graalpytest_driver()]
502+
if args.verbose:
503+
cmd_args += ["-v"]
504+
cmd_args += testfiles
505+
if args.filter:
506+
cmd_args += ["-k", args.filter]
507+
if args.python:
508+
return mx.run([args.python] + cmd_args, nonZeroIsFatal=True)
509+
else:
510+
return do_run_python(cmd_args)
496511

497-
# list of excluded tests
498-
if aot_compatible:
499-
exclude += AOT_INCOMPATIBLE_TESTS
500512

513+
def _list_graalpython_unittests(paths=None, exclude=[]):
514+
paths = paths or [_graalpytest_root()]
501515
def is_included(path):
502516
if path.endswith(".py"):
503517
basename = os.path.basename(path)
504518
return basename.startswith("test_") and basename not in exclude
505519
return False
506520

507-
# list all 1st-level tests and exclude the SVM-incompatible ones
508521
testfiles = []
509522
for path in paths:
510523
if not os.path.exists(path):
@@ -519,6 +532,26 @@ def is_included(path):
519532
for testfile in glob.glob(os.path.join(path, "test_*.py")):
520533
if is_included(testfile):
521534
testfiles.append(testfile)
535+
return testfiles
536+
537+
538+
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=True, exclude=None, env=None):
539+
# ensure that the test distribution is up-to-date
540+
mx.command_function("build")(["--dep", "com.oracle.graal.python.test"])
541+
542+
args = args or []
543+
args = ["--experimental-options=true",
544+
"--python.CatchAllExceptions=true"] + args
545+
exclude = exclude or []
546+
if env is None:
547+
env = os.environ.copy()
548+
549+
# list of excluded tests
550+
if aot_compatible:
551+
exclude += AOT_INCOMPATIBLE_TESTS
552+
553+
# list all 1st-level tests and exclude the SVM-incompatible ones
554+
testfiles = _list_graalpython_unittests(paths, exclude)
522555

523556
args += [_graalpytest_driver(), "-v"]
524557

@@ -1903,6 +1936,7 @@ def import_files(from_dir, to_dir):
19031936
'python-src-import': [import_python_sources, ''],
19041937
'python-coverage': [python_coverage, ''],
19051938
'punittest': [punittest, ''],
1939+
'graalpytest': [graalpytest, '[-h] [-v] [--python PYTHON] [-k TEST_PATTERN] [TESTS]'],
19061940
'clean': [python_clean, ''],
19071941
'python-update-hpy-import': [update_hpy_import_cmd, '[--no-pull] PATH_TO_HPY'],
19081942
})

0 commit comments

Comments
 (0)