diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py index 5522393d95..0e08461e8f 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py @@ -1325,7 +1325,15 @@ def _added(rows: list[tuple[str, str, str]]) -> dict: ], } - _ANCHORS = {"bea_nipa.cy2024.private_group_health_insurance"} + #: The pin test's three B4923C record sets, one for each year of the + #: banked series. Each anchor case below runs once for each of them, so a + #: check that reads only some of the three lets one of those cases + #: through. + _ANCHORS = { + "bea_nipa.cy2023.private_group_health_insurance", + "bea_nipa.cy2024.private_group_health_insurance", + "bea_nipa.cy2025.private_group_health_insurance", + } def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: later = self._later_report( @@ -1347,8 +1355,32 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: declared_namespace="ed_fsa.", ) == ("new", 12) + def test_a_later_report_may_relabel_rows_and_add_none(self) -> None: + # As microcosm#1343's re-pin did: label changes, the record-set hash + # that covers them, and no added row. + later = self._later_report( + added_keys=[], + changed_fields={ + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + "layout/groupby_value_label": {"rows": 1, "by_record_set": {"x": 1}}, + "layout/record_set_spec_hash": {"rows": 2, "by_record_set": {"x": 2}}, + }, + ) + assert _follow_later_repin_report( + later, + feed_sha256="old", + feed_rows=10, + anchor_record_sets=self._ANCHORS, + ) == ("new", 10) + # Each refusing case below names the check that must refuse it, so a check - # moved ahead of another fails the case it takes over. + # moved ahead of another fails the case it takes over. A check that reads + # only the first entry of a list or a mapping, or only the last, lets + # through each case whose comment puts its bad entry between two good + # ones. @pytest.mark.parametrize( ( "added_keys", @@ -1360,10 +1392,15 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: [ # Rows added with no declaration. (["k1"], None, None, None, "adds rows without declaring them"), - # A row from a source the re-pin did not declare. + # A row from a source the re-pin did not declare, between two rows + # from the declared source. ( - ["k1", "k2"], - [("k1", "ed_fsa", "ed_fsa.a"), ("k2", "irs_soi", "x")], + ["k1", "k2", "k3"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "irs_soi", "x"), + ("k3", "ed_fsa", "ed_fsa.b"), + ], "ed_fsa", "ed_fsa.", "an added row from another source", @@ -1385,13 +1422,21 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "added keys differ", ), # A declared row in a B4923C anchor record set, which also sits - # outside the declared namespace. - ( - ["k1"], - [("k1", "ed_fsa", "bea_nipa.cy2024.private_group_health_insurance")], - "ed_fsa", - "ed_fsa.", - "an added row in a B4923C record set", + # outside the declared namespace, between two rows that sit inside + # it: one case for each anchor. + *( + ( + ["k1", "k2", "k3"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "ed_fsa", anchor), + ("k3", "ed_fsa", "ed_fsa.b"), + ], + "ed_fsa", + "ed_fsa.", + "an added row in a B4923C record set", + ) + for anchor in sorted(_ANCHORS) ), # A listing with no declared source. ( @@ -1402,10 +1447,14 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "declares added rows without a source", ), # A row the listing labels with the declared source, in a record - # set outside the declared namespace. + # set outside the declared namespace, between two rows inside it. ( - ["k1"], - [("k1", "ed_fsa", "irs_soi.ty2023.table_1_4")], + ["k1", "k2", "k3"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "ed_fsa", "irs_soi.ty2023.table_1_4"), + ("k3", "ed_fsa", "ed_fsa.b"), + ], "ed_fsa", "ed_fsa.", "an added row outside the namespace", @@ -1433,7 +1482,9 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "other-source", "listing-short", "listing-extra", - "anchor-record-set", + "anchor-record-set-cy2023", + "anchor-record-set-cy2024", + "anchor-record-set-cy2025", "no-source", "outside-namespace", "namespace-not-leading", @@ -1464,10 +1515,19 @@ def test_a_later_report_refuses_rows_added_outside_its_declaration( lambda a: a["new_feed"].update(sha256="other"), "a listing of another feed", ), + # A listing whose digest sorts before the report's new feed. + ( + lambda a: a["new_feed"].update(sha256="aaa"), + "a listing of another feed", + ), # A listing that names one added key twice. (lambda a: a["rows"].append(dict(a["rows"][0])), "an added key twice"), ], - ids=["listing-other-feed", "listing-repeats-key"], + ids=[ + "listing-other-feed", + "listing-other-feed-sorts-first", + "listing-repeats-key", + ], ) def test_a_later_report_refuses_a_listing_it_cannot_follow( self, mutate, refusal @@ -1493,9 +1553,27 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( lambda r: r["rows"].update(new_rows=r["rows"]["new_rows"] + 1), "a new row count that does not add up", ), + # A new row count one short. The four checks of a feed's digest or + # row count each have a case above the expected value and one below + # it. + ( + lambda r: r["rows"].update(new_rows=r["rows"]["new_rows"] - 1), + "a new row count that does not add up", + ), + # A value change, between a hash change and a label change. ( lambda r: r["rows"]["changed_fields"].update( - value={"rows": 1, "by_record_set": {"x": 1}} + { + "layout/record_set_spec_hash": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + "value": {"rows": 1, "by_record_set": {"x": 1}}, + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + } ), "changes more than labels", ), @@ -1503,33 +1581,59 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( lambda r: r["feeds"]["old"].update(sha256="other"), "starts from another feed", ), + # An old feed whose digest sorts before the expected one. + ( + lambda r: r["feeds"]["old"].update(sha256="aaa"), + "starts from another feed", + ), # An old feed of another size, with a new count that still adds up. ( lambda r: r["rows"].update(old_rows=11, new_rows=12), "an old feed of another size", ), - # A label change in a B4923C record set. + # An old feed one row short, with a new count that still adds up. ( - lambda r: r["rows"]["changed_fields"].update( - { - "layout/groupby_value_label": { - "rows": 1, - "by_record_set": { - "bea_nipa.cy2024.private_group_health_insurance": 1 + lambda r: r["rows"].update(old_rows=9, new_rows=10), + "an old feed of another size", + ), + # A label change in a B4923C record set, between two record sets + # outside the anchors, in the second of three changed fields: one + # case for each anchor, which the default argument binds. + *( + ( + lambda r, anchor=anchor: r["rows"]["changed_fields"].update( + { + "layout/record_set_spec_hash": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + "layout/groupby_value_label": { + "rows": 3, + "by_record_set": {"x": 1, anchor: 1, "z": 1}, + }, + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"z": 1}, }, } - } - ), - "changes a B4923C record set", + ), + "changes a B4923C record set", + ) + for anchor in sorted(_ANCHORS) ), ], ids=[ "dropped-row", "row-count", + "row-count-short", "value-change", "wrong-base", + "wrong-base-sorts-first", "old-row-count", - "anchor-label", + "old-row-count-short", + "anchor-label-cy2023", + "anchor-label-cy2024", + "anchor-label-cy2025", ], ) def test_a_later_report_still_refuses_dropped_or_changed_rows(