diff --git a/onlinejudge_verify/languages/python.py b/onlinejudge_verify/languages/python.py index d31d2f54..cd3c1a25 100644 --- a/onlinejudge_verify/languages/python.py +++ b/onlinejudge_verify/languages/python.py @@ -57,7 +57,7 @@ def _python_list_depending_files(path: pathlib.Path, basedir: pathlib.Path) -> L ) try: executor = concurrent.futures.ThreadPoolExecutor() - future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)]) + future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)], trim=True) if platform.uname().system == 'Windows': timeout = 5.0 # 1.0 sec causes timeout on CI using Windows else: diff --git a/tests/test_python.py b/tests/test_python.py index 8485edde..8b07b2ae 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -66,6 +66,20 @@ def main() -> None: main() """ +TESTS_MAIN_PY_WITH_STDLIB = rb"""\ +# verify-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_B +from library.imported import solve +import os + +def main() -> None: + x = int(input()) + ans = solve(x) + print(ans) + +if __name__ == "__main__": + main() +""" + class TestPythonVerification(unittest.TestCase): """TestPythonListDependencies has end-to-end tests for the verification of Python files. @@ -88,3 +102,23 @@ def test_separated_dir(self) -> None: with open(timestamps_path) as fh: timestamps = json.load(fh) self.assertEqual(list(timestamps.keys()), [str(pathlib.Path('tests', 'main.py'))]) + + def test_separated_dir_with_stdlib(self) -> None: + """`test_separated_dir_with_stdlib` is a test for the case when the library files exist at the separate directory of the test file. + In this test, main.py has an import of a module in stdlib. + """ + + files = { + pathlib.Path('library', '__init__.py'): b"", + pathlib.Path('library', 'imported.py'): LIBRARY_IMPORTED_PY, + pathlib.Path('tests', 'main.py'): TESTS_MAIN_PY_WITH_STDLIB, + } + path = pathlib.Path('tests', 'main.py') + with tests.utils.load_files_pathlib(files) as tempdir: + with tests.utils.chdir(tempdir): + timestamps_path = tempdir / 'timestamps.json' + with onlinejudge_verify.marker.VerificationMarker(json_path=timestamps_path, use_git_timestamp=False) as marker: + self.assertEqual(verify.main([path], marker=marker).failed_test_paths, []) + with open(timestamps_path) as fh: + timestamps = json.load(fh) + self.assertEqual(list(timestamps.keys()), [str(pathlib.Path('tests', 'main.py'))])