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/2377.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added tests that building the model and running a simulation leave the process's warning filters and numpy's error state unchanged, and that importing the package adds no filter that ignores a built-in warning category everywhere. A `ReformPeriodWarning` is no longer also written to the log, since warnings now reach the caller.
1 change: 0 additions & 1 deletion policyengine_uk/dynamics/participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import numpy as np
import pandas as pd
from policyengine_uk import Simulation
import warnings

from policyengine_uk.dynamics.demographics import benunit_age_18_composition
from policyengine_uk.model_api import WEEKS_IN_YEAR
Expand Down
19 changes: 8 additions & 11 deletions policyengine_uk/tests/test_dated_reform_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,15 @@ def test_a_bare_year_is_that_year_in_a_dict_and_onwards_in_reform_from_dict():
]


def test_a_single_day_dict_key_keeps_its_legacy_meaning_and_warns(caplog):
# Logged as well as warned: loading some variable modules switches
# warnings off for the process.
with caplog.at_level("WARNING", logger="policyengine_uk.utils.dated_reforms"):
def test_a_single_day_dict_key_keeps_its_legacy_meaning_and_warns():
# The warning is raised after the simulation loads the variable modules,
# so this also checks that loading them leaves the filters alone (#2377).
with pytest.warns(ReformPeriodWarning, match="2027-04-06.2100-12-31"):
april = via_reform_dict({BASIC_RATE: {"2027-04-06": 0.21}})
assert "2027-04-06.2100-12-31" in caplog.text
assert [annual(april, BASIC_RATE, y) for y in YEARS] == [0.20] * len(YEARS)
caplog.clear()
with caplog.at_level("WARNING", logger="policyengine_uk.utils.dated_reforms"):
with warnings.catch_warnings():
warnings.simplefilter("error", ReformPeriodWarning)
january = via_reform_dict({BASIC_RATE: {"2027-01-01": 0.21}})
assert caplog.text == ""
assert [annual(january, BASIC_RATE, y) for y in (2026, 2027, 2028)] == [
0.20,
0.21,
Expand Down Expand Up @@ -910,12 +908,11 @@ def test_two_changes_that_need_projection_see_each_other():
)


def test_mixed_single_day_and_dated_keys_warn_and_apply_single_days_last(caplog):
with caplog.at_level("WARNING", logger="policyengine_uk.utils.dated_reforms"):
def test_mixed_single_day_and_dated_keys_warn_and_apply_single_days_last():
with pytest.warns(ReformPeriodWarning, match="mixes single-day keys"):
simulation = via_reform_dict(
{BASIC_RATE: {"2027-01-01": 0.21, "2026-01-01.2100-12-31": 0.22}}
)
assert "mixes single-day keys" in caplog.text
assert annual(simulation, BASIC_RATE, 2027) == 0.21
assert annual(simulation, BASIC_RATE, 2028) == 0.22

Expand Down
Loading
Loading