Skip to content

Commit

Permalink
Fix generated test imports for nested identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
pschanely committed Nov 9, 2023
1 parent a5aa555 commit 6949691
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crosshair/path_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def import_statements_for_references(references: Set[ReferencedIdentifier]) -> S
if ref.modulename == "builtins":
continue
if "." in ref.qualname:
class_name, _ = ref.qualname.split(".", 2)
class_name, _ = ref.qualname.split(".", 1)
imports.add(f"from {ref.modulename} import {class_name}")
else:
imports.add(f"from {ref.modulename} import {ref.qualname}")
Expand Down
12 changes: 5 additions & 7 deletions crosshair/path_cover_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ def _has_no_successful_paths(x: int) -> None:
context_statespace().defer_assumption("fail", lambda: False)


class Color(Enum):
RED = 0


@dataclass
class Train:
class Color(Enum):
RED = 0

color: Color


def _paint_train(train: Train, color: Color) -> Train:
def _paint_train(train: Train, color: Train.Color) -> Train:
return Train(color=color)


Expand Down Expand Up @@ -130,11 +129,10 @@ def test_path_cover_pytest_output() -> None:
imports, lines = output_pytest_paths(_paint_train, paths)
assert lines == [
"def test__paint_train():",
" assert _paint_train(Train(Color.RED), Color.RED) == Train(color=Color.RED)",
" assert _paint_train(Train(Train.Color.RED), Train.Color.RED) == Train(color=Train.Color.RED)",
"",
]
assert imports == {
"from crosshair.path_cover_test import _paint_train",
"from crosshair.path_cover_test import Color",
"from crosshair.path_cover_test import Train",
}

0 comments on commit 6949691

Please sign in to comment.