Skip to content

Commit

Permalink
Add US microsimulation test (#285)
Browse files Browse the repository at this point in the history
* fix: Add default_calculation_period to test runner simulation

* Add test for US microsimulation

* Rename test file

---------

Co-authored-by: Anthony Volk <[email protected]>
  • Loading branch information
nikhilwoodruff and anth-volk authored Sep 27, 2024
1 parent 78a431c commit b989ecd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ format:

install:
pip install -e .[dev]
pip install policyengine-us
pip install policyengine-uk

test-country-template:
policyengine-core test policyengine_core/country_template/tests -c policyengine_core.country_template
Expand Down
5 changes: 5 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- bump: patch
changes:
changed:
- Set test runner's default period as underlying simulation's default period
- Prevented crashing when absolutely no date is provided anywhere for tests
5 changes: 5 additions & 0 deletions policyengine_core/simulations/simulation_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)

from policyengine_core.variables import Variable
from datetime import datetime


class SimulationBuilder:
Expand Down Expand Up @@ -507,6 +508,10 @@ def add_group_entity(
def set_default_period(self, period_str: str) -> None:
if period_str:
self.default_period = str(periods.period(period_str))
else:
# If at absolute worst, no period is specified anywhere,
# use current year
self.default_period = periods.period(datetime.now().year)

def get_input(self, variable: str, period_str: str) -> Any:
if variable not in self.input_buffer:
Expand Down
1 change: 1 addition & 0 deletions policyengine_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def apply(self):
self.simulation = builder.build_from_dict(
self.tax_benefit_system, input
)
self.simulation.default_calculation_period = builder.default_period
except (VariableNotFoundError, SituationParsingError):
raise
except Exception as e:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_us.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def test_policyengine_us_microsimulation_runs():
from policyengine_us import Microsimulation

baseline = Microsimulation()
baseline.subsample(100)

baseline.calculate("household_net_income")

0 comments on commit b989ecd

Please sign in to comment.