From 64ed8c3ab177adb0ccd2f182647dfda69099281f Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 5 Oct 2024 10:56:58 +0200 Subject: [PATCH] add test for relative paths breaking out of current directory --- tests/functional/syntax/test_import.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/functional/syntax/test_import.py b/tests/functional/syntax/test_import.py index fc07d8fab6..e405b78981 100644 --- a/tests/functional/syntax/test_import.py +++ b/tests/functional/syntax/test_import.py @@ -86,3 +86,30 @@ def foo(): {"top.vy": top, "subdir0/lib0.vy": lib0, "subdir0/subdir1/lib1.vy": lib1} ) compiler.compile_code(top, input_bundle=input_bundle) + +def test_relative_paths_stay_in_current_directory(make_input_bundle): + top = """ +from subdir import b as b +@external +def foo(): + b.foo() + """ + + a = """ +def foo(): + pass + """ + + b = """ +from . import a as a + +def foo(): + a.foo() + """ + + input_bundle = make_input_bundle( + {"top.vy": top, "a.vy": a, "subdir/b.vy": b } + ) + + with pytest.raises(ModuleNotFound): + compiler.compile_code(top, input_bundle=input_bundle)