Skip to content

Commit

Permalink
add a test for forward references
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Oct 17, 2023
1 parent 86acd8c commit af04c6e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,51 @@ def test_tidy_imports_sorting():
sympy
""").strip().format(f=f)
assert result == expected


def test_tidy_imports_forward_references():
with tempfile.TemporaryDirectory() as temp_dir:
foo = os.path.join(temp_dir, "foo.py")
with open(foo, "w") as foo_fp:
foo_fp.write(dedent("""
from __future__ import annotations
class A:
param1: str
param2: B
class B:
param1: str
""").lstrip())
foo_fp.flush()

dot_pyflyby = os.path.join(temp_dir, ".pyflyby")
with open(dot_pyflyby, "w") as dot_pyflyby_fp:
dot_pyflyby_fp.write(dedent("""
from foo import A, B
""").lstrip())
dot_pyflyby_fp.flush()

os.chdir(temp_dir)
result = pipe([
BIN_DIR+"/tidy-imports", foo_fp.name
], env={
"PYFLYBY_PATH": dot_pyflyby
})

expected = dedent(f"""
[PYFLYBY] {foo}: added 'from foo import B'
from __future__ import annotations
from foo import B
class A:
param1: str
param2: B
class B:
param1: str
""").strip().format()
assert result == expected

0 comments on commit af04c6e

Please sign in to comment.