Skip to content

Commit

Permalink
fix: Add tests to ensure date is valid format
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Mar 21, 2024
1 parent c4a8f40 commit 80b3de7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions policyengine_core/parameters/operations/uprate_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,20 @@ def construct_cadence_options(
if cadence_settings.get(key) is None:
continue

# Ensure that date is YYYY-MM-DD
date_test = cadence_settings[key].split("-")
if (
len(date_test) != 3 or
len(date_test[0]) != 4 or
len(date_test[1]) != 2 or
len(date_test[2]) != 2 or
int(date_test[1]) > 12 or
int(date_test[2]) > 31
):
raise SyntaxError(
f"Unable to uprate {parameter.name} using setting '{key}': '{key}' must be in format 'YYYY-MM-DD'"
)

cadence_options[key] = parse(cadence_settings[key])

for key in STRING_KEYS:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/parameters/operations/test_uprating.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def test_parameter_uprating_cadence_custom_effective_malformed():

from policyengine_core.parameters import uprate_parameters

with pytest.raises(ValueError):
with pytest.raises(SyntaxError):
uprated = uprate_parameters(root)


Expand Down

0 comments on commit 80b3de7

Please sign in to comment.