From fb13af049765e3afa4df20ac9eb67dc8d02169b7 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 6 Sep 2018 14:28:23 +0200 Subject: [PATCH] Refactor tests/make_test_list.py --- test/make_test_list.py | 46 ++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/test/make_test_list.py b/test/make_test_list.py index d77d59032..971b835cd 100644 --- a/test/make_test_list.py +++ b/test/make_test_list.py @@ -5,24 +5,36 @@ Generate a list of test modules in the CPython distribution. import os from pathlib import Path -tests = [] -TEST_DIR = Path("../cpython/build/3.6.4/host/lib/python3.6/test") +TEST_DIR = (Path(__file__).parent + / "cpython/build/3.6.4/host/lib/python3.6/test") -for root, dirs, files in os.walk( - "../cpython/build/3.6.4/host/lib/python3.6/test"): - root = Path(root).relative_to(TEST_DIR) - if root == '.': - root = '' - else: - root = '.'.join(root.split('/')) + '.' - for filename in files: - filename = Path(filename) - if str(filename).startswith("test_") and filename.suffix == ".py": - tests.append(str(root / filename.stem)) +def collect_tests(base_dir): + """Collect CPython unit tests""" + # Note: this functionality is somewhat equivalent to pytest test + # collection. + tests = [] -tests.sort() -with open("python_tests.txt", "w") as fp: - for test in tests: - fp.write(test + '\n') + for root, dirs, files in os.walk(base_dir): + root = Path(root).relative_to(base_dir) + + if str(root) == '.': + root = '' + else: + root = '.'.join(str(root).split('/')) + '.' + + for filename in files: + filename = Path(filename) + if str(filename).startswith("test_") and filename.suffix == ".py": + tests.append(root + filename.stem) + + tests.sort() + return tests + + +if __name__ == '__main__': + tests = collect_tests(TEST_DIR) + with open("python_tests.txt", "w") as fp: + for test in tests: + fp.write(test + '\n')