diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2020-02-11 16:56:57 -0800 |
---|---|---|
committer | Zhizhou Yang <zhizhouy@google.com> | 2020-02-13 06:50:19 +0000 |
commit | 43c9066b1889baaa0a6077399deb6a4d503551e6 (patch) | |
tree | db4575b4aea577e3da2d7bfb3ac17f386b257733 /run_tests_for.py | |
parent | c4615d189f6b0dc4c116fc0a78ac295f7427170e (diff) | |
download | toolchain-utils-43c9066b1889baaa0a6077399deb6a4d503551e6.tar.gz |
toolchain-utils: migrate all in-use projects to python 3
This patch migrates all in-use projects left to python 3.
BUG=chromium:1011676
TEST=Passed unittests and launched scripts manually.
Change-Id: I7f2de4e1131c05bacfac80667f3064da8adaebfd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2051397
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Auto-Submit: Zhizhou Yang <zhizhouy@google.com>
Diffstat (limited to 'run_tests_for.py')
-rwxr-xr-x | run_tests_for.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/run_tests_for.py b/run_tests_for.py index cb8e6430..19f81722 100755 --- a/run_tests_for.py +++ b/run_tests_for.py @@ -37,6 +37,12 @@ import sys TestSpec = collections.namedtuple('TestSpec', ['directory', 'command']) +# List of python scripts that are not test with relative path to +# toolchain-utils. +non_test_py_files = { + 'debug_info_test/debug_info_test.py', +} + def _make_relative_to_toolchain_utils(toolchain_utils, path): """Cleans & makes a path relative to toolchain_utils. @@ -52,13 +58,26 @@ def _make_relative_to_toolchain_utils(toolchain_utils, path): return result -def _gather_python_tests_in(subdir): +def _filter_python_tests(test_files, toolchain_utils): + """Returns all files that are real python tests.""" + python_tests = [] + for test_file in test_files: + rel_path = _make_relative_to_toolchain_utils(toolchain_utils, test_file) + if rel_path not in non_test_py_files: + python_tests.append(_python_test_to_spec(test_file)) + else: + print('## %s ... NON_TEST_PY_FILE' % rel_path) + return python_tests + + +def _gather_python_tests_in(rel_subdir, toolchain_utils): """Returns all files that appear to be Python tests in a given directory.""" + subdir = os.path.join(toolchain_utils, rel_subdir) test_files = ( os.path.join(subdir, file_name) for file_name in os.listdir(subdir) if file_name.endswith('_test.py') or file_name.endswith('_unittest.py')) - return [_python_test_to_spec(test_file) for test_file in test_files] + return _filter_python_tests(test_files, toolchain_utils) def _run_test(test_spec): @@ -91,7 +110,7 @@ def _python_test_to_spec(test_file): return TestSpec(directory=test_directory, command=command) -def _autodetect_python_tests_for(test_file): +def _autodetect_python_tests_for(test_file, toolchain_utils): """Given a test file, detect if there may be related tests.""" if not test_file.endswith('.py'): return [] @@ -103,8 +122,7 @@ def _autodetect_python_tests_for(test_file): base = test_file[:-3] candidates = (base + x for x in test_suffixes) test_files = (x for x in candidates if os.path.exists(x)) - - return [_python_test_to_spec(test_file) for test_file in test_files] + return _filter_python_tests(test_files, toolchain_utils) def _run_test_scripts(all_tests, show_successful_output=False): @@ -195,7 +213,7 @@ def _find_forced_subdir_python_tests(test_paths, toolchain_utils): results = [] for d in sorted(gather_test_dirs): - results += _gather_python_tests_in(os.path.join(toolchain_utils, d)) + results += _gather_python_tests_in(d, toolchain_utils) return results @@ -241,7 +259,7 @@ def main(argv): tests_to_run = _find_forced_subdir_python_tests(modified_files, toolchain_utils) for f in modified_files: - tests_to_run += _autodetect_python_tests_for(f) + tests_to_run += _autodetect_python_tests_for(f, toolchain_utils) tests_to_run += _find_go_tests(modified_files) # TestSpecs have lists, so we can't use a set. We'd likely want to keep them |