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
1 change: 1 addition & 0 deletions changelog.d/650.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The UK Budget reform contract's household route imports the UK model module directly, so it runs in the qualification gate, whose scripts skip the country imports that set `policyengine.uk`; every household-route row there had errored.
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,13 @@ class _WrapperHouseholdRoute:
route = "wrapper.household"

def _call(self, case: Case, year: int, reform, variables: Sequence[str]):
import policyengine as pe
# The module ``policyengine.uk`` names, imported directly: a process
# that sets POLICYENGINE_SKIP_COUNTRY_IMPORTS, as the qualification
# scripts do, leaves ``policyengine.uk`` as None.
from policyengine.tax_benefit_models import uk

household = case.household
return pe.uk.calculate_household(
return uk.calculate_household(
people=[dict(person) for person in household.people],
benunit=dict(household.benunit),
household=dict(household.household),
Expand Down
15 changes: 15 additions & 0 deletions tests/test_uk_budget_reform_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2004,3 +2004,18 @@ def array(tag, variable, year):
order = status[(population.POPULATION_QUERY_ORDER, "unreformed")]
assert order["status"] == "fail"
assert order["detail"]["income_tax:2026_matches"] is False


def test_the_household_route_runs_where_country_imports_are_skipped(monkeypatch):
"""scripts/check_uk_candidate.py sets POLICYENGINE_SKIP_COUNTRY_IMPORTS, so
``policyengine.uk`` is None in the qualification gate; every household-route
row there errored with "'NoneType' object has no attribute
'calculate_household'"."""
import policyengine

monkeypatch.setattr(policyengine, "uk", None)
case = next(case for case in CASES if case.id == "april_rate_change")
rows = evaluate_case(case, "wrapper.household")
statuses = {row["status"] for row in rows}
# The route reads variables, not parameters, which it reports unsupported.
assert "pass" in statuses and statuses <= {"pass", "unsupported"}, rows
Loading