fix(sp41): test has_overridden_visits + clarify pipeline_b forward-compat helper

This commit is contained in:
Nora
2026-07-07 21:37:48 -06:00
parent 4d396d40b6
commit 39f578aa5e
2 changed files with 46 additions and 4 deletions
+35 -1
View File
@@ -38,4 +38,38 @@ def test_override_relaxes_timely_filing():
out_default = build_pipeline_b_batches(visits, as_of=date(2026, 7, 7), override=False)
out_overridden = build_pipeline_b_batches(visits, as_of=date(2026, 7, 7), override=True)
assert out_default == []
assert len(out_overridden) == 1
assert len(out_overridden) == 1
def test_override_flag_set_on_past_window_visit_batch():
# Same member "OLD" with one past-window visit (187 days old, ISO
# week 1) and one within-window visit (10 days old, ISO week 26).
# With override=True the past-window visit survives and the batch
# for week 1 must be flagged has_overridden_visits=True because the
# override saved an otherwise-excluded visit.
visits = [
_v(date(2026, 1, 1), "OLD", "T1019", "2.32"), # 187 days old (past window, W01)
_v(date(2026, 6, 27), "OLD", "T1019", "2.32"), # 10 days old (within window, W26)
]
out_overridden = build_pipeline_b_batches(
visits, as_of=date(2026, 7, 7), override=True,
)
# Two batches: one per (member, ISO-week) — the past-window visit and
# the within-window visit land in different weeks.
assert len(out_overridden) == 2
by_week = {b.iso_week: b for b in out_overridden}
assert by_week[1].member_id == "OLD"
assert by_week[1].has_overridden_visits is True # the override saved this batch
assert by_week[26].member_id == "OLD"
assert by_week[26].has_overridden_visits is False # no override needed here
# With override=False the past-window visit is dropped. The surviving
# within-window batch (W26) must NOT carry the override flag, and the
# past-window batch (W01) is absent.
out_default = build_pipeline_b_batches(
visits, as_of=date(2026, 7, 7), override=False,
)
assert len(out_default) == 1
assert out_default[0].member_id == "OLD"
assert out_default[0].iso_week == 26
assert out_default[0].has_overridden_visits is False