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

Make Consumption error handling be like Policy error handling #2282

Merged
merged 1 commit into from
Apr 3, 2019
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
19 changes: 16 additions & 3 deletions taxcalc/consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def __init__(self):
super().__init__()
self.initialize(Consumption.JSON_START_YEAR,
Consumption.DEFAULT_NUM_YEARS)
self.parameter_warnings = ''
self.parameter_errors = ''
self._ignore_errors = False

def update_consumption(self, revision):
def update_consumption(self, revision,
print_warnings=False, raise_errors=True):
"""
Update consumption for given revision, a dictionary consisting
of one or more year:modification dictionaries.
Expand Down Expand Up @@ -72,8 +75,10 @@ def update_consumption(self, revision):
msg = 'ERROR: {} YEAR revision provision in YEAR > end_year={}'
raise ValueError(msg.format(last_revision_year, self.end_year))
# validate revision parameter names and types
self.parameter_warnings = ''
self.parameter_errors = ''
self._validate_names_types(revision)
if self.parameter_errors:
if self.parameter_errors and not self._ignore_errors:
raise ValueError(self.parameter_errors)
# implement the revision year by year
revision_parameters = set()
Expand All @@ -84,7 +89,9 @@ def update_consumption(self, revision):
self.set_year(precall_current_year)
# validate revision parameter values
self._validate_values(revision_parameters)
if self.parameter_errors:
if self.parameter_warnings and print_warnings:
print(self.parameter_warnings) # pragma: no cover
if self.parameter_errors and raise_errors:
raise ValueError('\n' + self.parameter_errors)

RESPONSE_VARS = set(['e17500', 'e18400', 'e19800', 'e20400'])
Expand Down Expand Up @@ -124,3 +131,9 @@ def benval_params(self):
"""
return [getattr(self, 'BEN_{}_value'.format(var))
for var in Consumption.BENEFIT_VARS]

def ignore_update_errors(self):
"""
Sets self._ignore_errors to True.
"""
self._ignore_errors = True
1 change: 1 addition & 0 deletions taxcalc/tests/test_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_validity_of_consumption_vars_set():

def test_update_consumption():
consump = Consumption()
consump.ignore_update_errors()
consump.update_consumption({})
consump.update_consumption({2014: {'_MPC_e20400': [0.05],
'_BEN_mcare_value': [0.75]},
Expand Down