Skip to content

Commit 663cf6a

Browse files
stroxlermeta-codesync[bot]
authored andcommitted
Add an integration test for relative imports
Summary: After skimming the implementation of relative imports, it was all tests that required trusting the test assertions; it's nice to have a test that actually runs the code. Reviewed By: alexmalyshev Differential Revision: D96400606 fbshipit-source-id: f801fe836e05f6f583ed7f673d6a761a1114dd51
1 parent 5aab98b commit 663cf6a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

cinderx/PythonLib/test_cinderx/test_compiler/test_static/decl_visitor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,20 @@ def g(x: C):
393393
comp = self.compiler(**{"pkg.foo": foo_code, "pkg.mod": mod_code})
394394
f = self.find_code(comp.compile_module("pkg.mod"), "g")
395395
self.assertInBytecode(f, "INVOKE_METHOD", ((("pkg.foo", "C"), "f"), 0))
396+
397+
def test_relative_import_executes_compiled_code(self) -> None:
398+
"""Relative import should work at runtime when executing compiled module."""
399+
foo_code = """
400+
class C:
401+
def f(self) -> int:
402+
return 42
403+
"""
404+
mod_code = """
405+
from .foo import C
406+
407+
def g() -> int:
408+
return C().f()
409+
"""
410+
comp = self.compiler(**{"pkg.foo": foo_code, "pkg.mod": mod_code})
411+
with comp.in_module("pkg.mod") as mod:
412+
self.assertEqual(mod.g(), 42)

0 commit comments

Comments
 (0)