Skip to content

Commit

Permalink
Merge pull request #415 from online-judge-tools/fix/importing-stdlib-…
Browse files Browse the repository at this point in the history
…in-python

Don't look into stdlib (Python)
  • Loading branch information
koba-e964 authored Aug 12, 2023
2 parents b2c74ad + 27f70b3 commit 8625fa7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion onlinejudge_verify/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'))])

0 comments on commit 8625fa7

Please sign in to comment.