|
1 |
| -def test_microsim_runs_cps(): |
2 |
| - import numpy as np |
3 |
| - from fiscalsim_us import Microsimulation |
| 1 | +import numpy as np |
| 2 | +from fiscalsim_us import Microsimulation |
| 3 | +from policyengine_core.reforms import Reform |
| 4 | +from policyengine_core.periods import instant |
| 5 | +import pytest |
| 6 | + |
| 7 | + |
| 8 | +# @pytest.mark.skipif(True, reason="This test temporarily suspended.") |
| 9 | + |
| 10 | +""" |
| 11 | +In US nationwide simulations, use reported state income tax liabilities |
| 12 | +""" |
| 13 | + |
4 | 14 |
|
5 |
| - sim = Microsimulation() |
6 |
| - hnet = sim.calc("household_net_income") |
| 15 | +def use_reported_state_income_tax(parameters): |
| 16 | + parameters.simulation.reported_state_income_tax.update( |
| 17 | + start=instant("2024-01-01"), stop=instant("2100-12-31"), value=True |
| 18 | + ) |
| 19 | + return parameters |
| 20 | + |
| 21 | + |
| 22 | +class baseline_reform(Reform): |
| 23 | + def apply(self): |
| 24 | + self.modify_parameters(use_reported_state_income_tax) |
| 25 | + |
| 26 | + |
| 27 | +def test_microsim_runs_cps(): |
| 28 | + sim = Microsimulation(reform=baseline_reform) |
| 29 | + hnet = sim.calc("household_net_income", period=2024, map_to="person") |
7 | 30 | assert not hnet.isna().any(), "Some households have NaN net income."
|
8 |
| - # Deciles are 1-10, with -1 for negative income. |
9 |
| - DECILES = [ |
10 |
| - "household_income_decile", |
11 |
| - "spm_unit_income_decile", |
12 |
| - "income_decile", |
13 |
| - ] |
14 |
| - for decile_var in DECILES: |
15 |
| - decile = sim.calc(decile_var) |
16 |
| - assert np.all(decile >= -1) and np.all( |
17 |
| - decile <= 10 |
18 |
| - ), f"{decile_var} out of bounds." |
19 |
| - |
20 |
| - # Check that the microsim calculates important variables as nonzero in current year. |
21 |
| - for var in ["employment_income", "self_employment_income"]: |
22 |
| - assert sim.calc(var, period=2024).sum() > 0, f"{var} is zero in 2024." |
| 31 | + hidecile = sim.calc( |
| 32 | + "household_income_decile", period=2024, map_to="person" |
| 33 | + ) |
| 34 | + assert np.all(hidecile >= 1) and np.all(hidecile <= 10) |
| 35 | + sidecile = sim.calc("spm_unit_income_decile", period=2024, map_to="person") |
| 36 | + assert np.all(sidecile >= 1) and np.all(sidecile <= 10) |
| 37 | + idecile = sim.calc("income_decile", period=2024, map_to="person") |
| 38 | + assert np.all(idecile >= 1) and np.all(idecile <= 10) |
0 commit comments