r""" tools/import_payer_groups.py — turning the Claim Status Dashboard's Payer Name / Payer Group Name pairs into payer_groups.json. python tests\test_import_payer_groups.py Only `build()` is exercised: the merge rules. No network file is read. """ import sys import pathlib import collections ROOT = pathlib.Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / "tools")) import import_payer_groups as tool # noqa: E402 def _pairs(**groups_by_payer): return {p.replace("_", " "): collections.Counter(g) for p, g in groups_by_payer.items()} def case_dashboard_group_wins_and_names_are_kept_exactly(): mapping, conflicts, kept = tool.build( _pairs(Medicaid={"Medicaid": 5}, Anthem={"Commercial Ins": 3}), {"Anthem": "Commercial"}) assert mapping == {"Anthem": "Commercial Ins", "Medicaid": "Medicaid"} assert conflicts == {} and kept == {} def case_a_conflict_keeps_the_group_on_most_rows_and_is_reported(): mapping, conflicts, _ = tool.build( _pairs(Humana={"Medicare": 9, "Commercial Ins": 2}), {}) assert mapping["Humana"] == "Medicare" assert conflicts == {"Humana": {"Medicare": 9, "Commercial Ins": 2}} def case_payers_missing_from_the_dashboard_are_kept_and_renamed(): mapping, _, kept = tool.build( _pairs(Medicaid={"Medicaid": 1}), {"BH ROCK MTN UB": "RAE payer", "Odd Payer": "Something Else"}) assert kept == {"BH ROCK MTN UB": "RAE (Behavioral Health)", "Odd Payer": "Something Else"} assert mapping["BH ROCK MTN UB"] == "RAE (Behavioral Health)" def case_output_is_sorted_case_insensitively(): mapping, _, _ = tool.build( _pairs(b={"X": 1}, A={"X": 1}, c={"X": 1}), {}) assert list(mapping) == ["A", "b", "c"] CASES = [v for k, v in sorted(globals().items()) if k.startswith("case_")] def main() -> int: failures = 0 for fn in CASES: name = fn.__name__[5:].replace("_", " ") try: fn() print(f" ok {name}") except AssertionError as exc: print(f" FAIL {name}: {exc}") failures += 1 except Exception as exc: print(f" ERROR {name}: {type(exc).__name__}: {exc}") failures += 1 print(f"\n{len(CASES) - failures}/{len(CASES)} passed") return 1 if failures else 0 if __name__ == "__main__": sys.exit(main())