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 default_calculation_period to test runner simulation #284

Closed
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
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
Loading