Skip to content

Commit

Permalink
fix: Add default_calculation_period to test runner simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Sep 27, 2024
1 parent 78a431c commit 3ae4383
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
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

0 comments on commit 3ae4383

Please sign in to comment.