Skip to content

Commit 8625fa7

Browse files
authored
Merge pull request #415 from online-judge-tools/fix/importing-stdlib-in-python
Don't look into stdlib (Python)
2 parents b2c74ad + 27f70b3 commit 8625fa7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

onlinejudge_verify/languages/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _python_list_depending_files(path: pathlib.Path, basedir: pathlib.Path) -> L
5757
)
5858
try:
5959
executor = concurrent.futures.ThreadPoolExecutor()
60-
future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)])
60+
future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)], trim=True)
6161
if platform.uname().system == 'Windows':
6262
timeout = 5.0 # 1.0 sec causes timeout on CI using Windows
6363
else:

tests/test_python.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ def main() -> None:
6666
main()
6767
"""
6868

69+
TESTS_MAIN_PY_WITH_STDLIB = rb"""\
70+
# verify-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_B
71+
from library.imported import solve
72+
import os
73+
74+
def main() -> None:
75+
x = int(input())
76+
ans = solve(x)
77+
print(ans)
78+
79+
if __name__ == "__main__":
80+
main()
81+
"""
82+
6983

7084
class TestPythonVerification(unittest.TestCase):
7185
"""TestPythonListDependencies has end-to-end tests for the verification of Python files.
@@ -88,3 +102,23 @@ def test_separated_dir(self) -> None:
88102
with open(timestamps_path) as fh:
89103
timestamps = json.load(fh)
90104
self.assertEqual(list(timestamps.keys()), [str(pathlib.Path('tests', 'main.py'))])
105+
106+
def test_separated_dir_with_stdlib(self) -> None:
107+
"""`test_separated_dir_with_stdlib` is a test for the case when the library files exist at the separate directory of the test file.
108+
In this test, main.py has an import of a module in stdlib.
109+
"""
110+
111+
files = {
112+
pathlib.Path('library', '__init__.py'): b"",
113+
pathlib.Path('library', 'imported.py'): LIBRARY_IMPORTED_PY,
114+
pathlib.Path('tests', 'main.py'): TESTS_MAIN_PY_WITH_STDLIB,
115+
}
116+
path = pathlib.Path('tests', 'main.py')
117+
with tests.utils.load_files_pathlib(files) as tempdir:
118+
with tests.utils.chdir(tempdir):
119+
timestamps_path = tempdir / 'timestamps.json'
120+
with onlinejudge_verify.marker.VerificationMarker(json_path=timestamps_path, use_git_timestamp=False) as marker:
121+
self.assertEqual(verify.main([path], marker=marker).failed_test_paths, [])
122+
with open(timestamps_path) as fh:
123+
timestamps = json.load(fh)
124+
self.assertEqual(list(timestamps.keys()), [str(pathlib.Path('tests', 'main.py'))])

0 commit comments

Comments
 (0)