Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux committed Feb 5, 2018
1 parent a29d203 commit 028cfd5
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,30 @@ def _run_test(period_str, test, verbose = False, only_variables = None, ignore_v
scenario.suggest()
simulation = scenario.new_simulation(trace = verbose)
output_variables = test.get(u'output_variables')
tested_variables = output_variables.keys()
if only_variables is not None and ignore_variables is None:
tested_variables = only_variables
if only_variables is None and ignore_variables is not None:
tested_variables = list(set(output_variables.keys()).difference(set(ignore_variables)))
if only_variables is not None and ignore_variables is not None:
tested_variables = list(set(only_variables).difference(set(ignore_variables)))
if output_variables is not None:
try:
if only_variables is not None:
for variable in only_variables:
assert variable in output_variables.keys(), "La variable {} n'est pas présente dans les outputs variables du test".format(variable)
for variable_name, expected_value in output_variables.iteritems():
if variable_name in tested_variables:
if isinstance(expected_value, dict):
for requested_period, expected_value_at_period in expected_value.iteritems():
assert_near(
simulation.calculate(variable_name, requested_period),
expected_value_at_period,
absolute_error_margin = absolute_error_margin,
message = u'{}@{}: '.format(variable_name, requested_period),
relative_error_margin = relative_error_margin,
)
else:
variable_ignored = ignore_variables is not None and variable_name in ignore_variables
variable_not_tested = only_variables is not None and variable_name not in only_variables
if variable_ignored or variable_not_tested:
continue # Skip this variable
if isinstance(expected_value, dict):
for requested_period, expected_value_at_period in expected_value.iteritems():
assert_near(
simulation.calculate(variable_name),
expected_value,
simulation.calculate(variable_name, requested_period),
expected_value_at_period,
absolute_error_margin = absolute_error_margin,
message = u'{}@{}: '.format(variable_name, period_str),
message = u'{}@{}: '.format(variable_name, requested_period),
relative_error_margin = relative_error_margin,
)
else:
continue
assert_near(
simulation.calculate(variable_name),
expected_value,
absolute_error_margin = absolute_error_margin,
message = u'{}@{}: '.format(variable_name, period_str),
relative_error_margin = relative_error_margin,
)
finally:
if verbose:
print("Computation log:")
Expand Down

0 comments on commit 028cfd5

Please sign in to comment.