Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add US microsimulation test #285

Merged
merged 3 commits into from
Sep 27, 2024
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
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")
Loading