Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop `test_an_edit_to_a_loaded_tree_reaches_the_next_simulation` requiring policyengine-core to load scale brackets without a parent. The test now detaches the bracket it edits, so it checks the same case whether or not core links a loaded tree's brackets to their scale.
21 changes: 12 additions & 9 deletions policyengine_us/tests/test_pinned_tbs_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def parameter(value):
def change_small_tree(tree, change, index, value):
"""Change ``tree`` in one of the ways it can change.

Only ``update`` clears a cache, and on a loaded tree it stops at a scale's
bracket, which has no parent.
Only ``update`` clears a cache. From a scale's bracket on a loaded tree, it
goes further up only if this version of core links the bracket to its scale.
"""
credit = tree.credit
named_parent = tree.categories.group.children["parent"]
Expand Down Expand Up @@ -543,23 +543,26 @@ def result():


def test_an_edit_to_a_loaded_tree_reaches_the_next_simulation(monkeypatch):
"""A loaded tree's scale brackets have no parent, unlike a clone's.
"""An edit to a scale bracket on a loaded tree reaches a pin.

So this edit clears no cache above the bracket, and a pin has to read the
parameter itself. The EITC's 2021 pin keeps this amount, so its result
moves with the edit.
The test detaches the bracket from its scale before the edit, so the edit
clears no cache above the bracket on any version of core, and the source
tree's cached views stay stale. A pin has to read the parameter itself. The
EITC's 2021 pin keeps this amount, so its result moves with the edit.
"""
loaded = CountryTaxBenefitSystem()
assert loaded.parameters.gov.irs.credits.eitc.max.brackets[1].parent is None
edited_bracket = loaded.parameters.gov.irs.credits.eitc.max.brackets[1]
# Older versions of core load a bracket without a parent, and newer ones
# link it to its scale. Detaching it gives the same case on both.
edited_bracket.parent = None

def result():
situation = household(2021, earnings=15_000, interest=0)
simulation = Simulation(situation=situation, tax_benefit_system=loaded)
return simulation.calculate("ny_eitc", 2021)[0]

before = result()
amount = loaded.parameters.gov.irs.credits.eitc.max.brackets[1].amount
amount.update(period="year:2021:1", value=5_000)
edited_bracket.amount.update(period="year:2021:1", value=5_000)
edited = result()

assert edited != before
Expand Down
Loading