Skip to content

Commit dd2a6a0

Browse files
committed
Cover enum self-dispatch detection
1 parent e862a4e commit dd2a6a0

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_refactor_advisor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,29 @@ def test_detects_enum_strategy_dispatch_with_abc_guidance(tmp_path: Path) -> Non
22932293
assert "runner = ModeRunner.for_mode(mode)" in strategy_finding.codemod_patch
22942294

22952295

2296+
def test_detects_enum_strategy_dispatch_inside_enum_method(tmp_path: Path) -> None:
2297+
_write_module(
2298+
tmp_path,
2299+
"pkg/mod.py",
2300+
'\nfrom enum import Enum\n\n\nclass Scope(Enum):\n CX5 = "EDDU_CX5"\n METAXPRESS = "EDDU_metaxpress"\n\n def read_results(self, workbook):\n if self is Scope.CX5:\n return read_cx5(workbook)\n if self is Scope.METAXPRESS:\n return read_metaxpress(workbook)\n raise AssertionError(self)\n\n def features(self, raw_df):\n if self is Scope.CX5:\n return cx5_features(raw_df)\n if self is Scope.METAXPRESS:\n return metaxpress_features(raw_df)\n raise AssertionError(self)\n',
2301+
)
2302+
2303+
findings = analyze_path(tmp_path)
2304+
enum_dispatch_summaries = [
2305+
finding.summary
2306+
for finding in findings
2307+
if finding.detector_id == "enum_strategy_dispatch"
2308+
]
2309+
assert any("Scope.read_results" in summary for summary in enum_dispatch_summaries)
2310+
assert any("Scope.features" in summary for summary in enum_dispatch_summaries)
2311+
assert any(
2312+
finding.detector_id == "repeated_enum_strategy_dispatch"
2313+
and "Scope.read_results" in finding.summary
2314+
and "Scope.features" in finding.summary
2315+
for finding in findings
2316+
)
2317+
2318+
22962319
def test_detects_literal_match_dispatch_with_autoregistermeta_guidance(
22972320
tmp_path: Path,
22982321
) -> None:

0 commit comments

Comments
 (0)