-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression on YAML tests runner cache for tax benefit systems wit…
…h reforms or extensions Merge pull request #825 from openfisca/yaml-reform-format
- Loading branch information
Showing
5 changed files
with
104 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from openfisca_core.tools.test_runner import _run_test, _get_tax_benefit_system | ||
from openfisca_core.errors import VariableNotFound | ||
|
||
|
||
import pytest | ||
|
||
|
||
class TaxBenefitSystem: | ||
def __init__(self): | ||
self.variables = {} | ||
|
||
def get_package_metadata(self): | ||
return {"name": "Test", "version": "Test"} | ||
|
||
def apply_reform(self, path): | ||
return Reform(self) | ||
|
||
def load_extension(self, extension): | ||
pass | ||
|
||
def clone(self): | ||
return TaxBenefitSystem() | ||
|
||
|
||
class Reform(TaxBenefitSystem): | ||
def __init__(self, baseline): | ||
self.baseline = baseline | ||
|
||
|
||
class Simulation: | ||
def __init__(self): | ||
self.tax_benefit_system = TaxBenefitSystem() | ||
self.entities = {} | ||
|
||
def get_entity(self, plural = None): | ||
return None | ||
|
||
|
||
def test_variable_not_found(): | ||
test = {"output": {"unknown_variable": 0}} | ||
with pytest.raises(VariableNotFound) as excinfo: | ||
_run_test(Simulation(), test) | ||
assert excinfo.value.variable_name == "unknown_variable" | ||
|
||
|
||
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', []) | ||
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'], []) | ||
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'], []) | ||
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') | ||
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']) | ||
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']) | ||
assert xy_tax_benefit_system == yx_tax_benefit_system # extensions order is ignored in cache |