Skip to content

Commit

Permalink
fixup! Add tbs with neutralized variables to yaml tbs cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sandcha committed Jun 7, 2021
1 parent 3b9271f commit 1bd796e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def runtest(self):
raise ValueError("Unexpected keys {} in test '{}' in file '{}'".format(unexpected_keys, self.name, self.fspath))

self.tax_benefit_system = _get_tax_benefit_system(
self.baseline_tax_benefit_system,
self.test.get('reforms', []),
self.baseline_tax_benefit_system,
self.test.get('reforms', []),
self.test.get('extensions', []),
self.test.get('neutralized_variables', [])
)
Expand All @@ -167,7 +167,6 @@ def runtest(self):
performance_graph = self.options.get('performance_graph')
performance_tables = self.options.get('performance_tables')


try:
builder.set_default_period(period)
self.simulation = builder.build_from_dict(self.tax_benefit_system, input)
Expand Down Expand Up @@ -289,7 +288,7 @@ def _get_tax_benefit_system(baseline, reforms, extensions, neutralized_variables
if not isinstance(extensions, list):
extensions = [extensions]
if not isinstance(neutralized_variables, list):
neutralized_variables = [neutralized_variables]
neutralized_variables = [neutralized_variables]

# keep reforms order in cache, ignore extensions order
key = hash((id(baseline), ':'.join(reforms), frozenset(extensions), ':'.join(neutralized_variables)))
Expand Down
24 changes: 12 additions & 12 deletions tests/core/tools/test_runner/test_yaml_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,48 +95,48 @@ def test_variable_not_found():
def test_tax_benefit_systems_with_reform_cache():
baseline = TaxBenefitSystem()

ab_tax_benefit_system = _get_tax_benefit_system(baseline, 'ab', [])
ba_tax_benefit_system = _get_tax_benefit_system(baseline, 'ba', [])
ab_tax_benefit_system = _get_tax_benefit_system(baseline, 'ab', [], [])
ba_tax_benefit_system = _get_tax_benefit_system(baseline, 'ba', [], [])
assert ab_tax_benefit_system != ba_tax_benefit_system


def test_reforms_formats():
baseline = TaxBenefitSystem()

lonely_reform_tbs = _get_tax_benefit_system(baseline, 'lonely_reform', [])
list_lonely_reform_tbs = _get_tax_benefit_system(baseline, ['lonely_reform'], [])
lonely_reform_tbs = _get_tax_benefit_system(baseline, 'lonely_reform', [], [])
list_lonely_reform_tbs = _get_tax_benefit_system(baseline, ['lonely_reform'], [], [])
assert lonely_reform_tbs == list_lonely_reform_tbs


def test_reforms_order():
baseline = TaxBenefitSystem()

abba_tax_benefit_system = _get_tax_benefit_system(baseline, ['ab', 'ba'], [])
baab_tax_benefit_system = _get_tax_benefit_system(baseline, ['ba', 'ab'], [])
abba_tax_benefit_system = _get_tax_benefit_system(baseline, ['ab', 'ba'], [], [])
baab_tax_benefit_system = _get_tax_benefit_system(baseline, ['ba', 'ab'], [], [])
assert abba_tax_benefit_system != baab_tax_benefit_system # keep reforms order in cache


def test_tax_benefit_systems_with_extensions_cache():
baseline = TaxBenefitSystem()

xy_tax_benefit_system = _get_tax_benefit_system(baseline, [], 'xy')
yx_tax_benefit_system = _get_tax_benefit_system(baseline, [], 'yx')
xy_tax_benefit_system = _get_tax_benefit_system(baseline, [], 'xy', [])
yx_tax_benefit_system = _get_tax_benefit_system(baseline, [], 'yx', [])
assert xy_tax_benefit_system != yx_tax_benefit_system


def test_extensions_formats():
baseline = TaxBenefitSystem()

lonely_extension_tbs = _get_tax_benefit_system(baseline, [], 'lonely_extension')
list_lonely_extension_tbs = _get_tax_benefit_system(baseline, [], ['lonely_extension'])
lonely_extension_tbs = _get_tax_benefit_system(baseline, [], 'lonely_extension', [])
list_lonely_extension_tbs = _get_tax_benefit_system(baseline, [], ['lonely_extension'], [])
assert lonely_extension_tbs == list_lonely_extension_tbs


def test_extensions_order():
baseline = TaxBenefitSystem()

xy_tax_benefit_system = _get_tax_benefit_system(baseline, [], ['x', 'y'])
yx_tax_benefit_system = _get_tax_benefit_system(baseline, [], ['y', 'x'])
xy_tax_benefit_system = _get_tax_benefit_system(baseline, [], ['x', 'y'], [])
yx_tax_benefit_system = _get_tax_benefit_system(baseline, [], ['y', 'x'], [])
assert xy_tax_benefit_system == yx_tax_benefit_system # extensions order is ignored in cache


Expand Down

0 comments on commit 1bd796e

Please sign in to comment.