diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af91899d7..dea2a9a195 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 35.7.9 [#1113](https://github.com/openfisca/openfisca-core/pull/1113) + +### Technical changes + +- Fixed a bug where `get_descendants` would not return rates and thresholds from `ParameterScale`s. + ### 35.7.8 [#1086](https://github.com/openfisca/openfisca-core/pull/1086) #### Technical changes diff --git a/openfisca_core/parameters/parameter_scale.py b/openfisca_core/parameters/parameter_scale.py index d1cfc26379..285e3cc85b 100644 --- a/openfisca_core/parameters/parameter_scale.py +++ b/openfisca_core/parameters/parameter_scale.py @@ -62,7 +62,14 @@ def __repr__(self): ) def get_descendants(self): - return iter(()) + returned_any_results = False + for bracket in self.brackets: + for allowed_key_name in bracket._allowed_keys: + if hasattr(bracket, allowed_key_name): + yield getattr(bracket, allowed_key_name) + returned_any_results = True + if not returned_any_results: + return iter(()) def clone(self): clone = commons.empty_clone(self) diff --git a/setup.py b/setup.py index 98904fe43b..2fc19f626f 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.8', + version = '35.7.9', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ diff --git a/tests/core/tax_scales/test_tax_scale_descendants.py b/tests/core/tax_scales/test_tax_scale_descendants.py new file mode 100644 index 0000000000..2ae2e25cd7 --- /dev/null +++ b/tests/core/tax_scales/test_tax_scale_descendants.py @@ -0,0 +1,47 @@ +def test_tax_scale_descendants_are_complete(): + """Tests that calling the `get_descendant` function of a ParameterScale returns the rates and thresholds as Parameters. + """ + + from openfisca_core.parameters import ParameterNode, Parameter + + parameters = ParameterNode("parameters", data={ + "root_node": { + "first_child": { + "scale_parameter": { + "brackets": [ + { + "rate": { + "2022-01-01": 0.1, + }, + "threshold": { + "2022-01-01": 0, + } + }, + { + "rate": { + "2022-01-01": 0.2, + }, + "threshold": { + "2022-01-01": 100, + } + } + ] + }, + "normal_parameter": { + "2022-01-01": 5 + } + } + } + }) + + # Get descendants which are parameters (ignore nodes) + parameter_descendants = list(filter(lambda p: isinstance(p, Parameter), parameters.get_descendants())) + + # Check that the expected names are in the descendants + parameter_names = list(map(lambda p: p.name, parameter_descendants)) + assert all(name in parameter_names for name in [ + "parameters.root_node.first_child.scale_parameter[0].rate", + "parameters.root_node.first_child.scale_parameter[0].threshold", + "parameters.root_node.first_child.scale_parameter[1].rate", + "parameters.root_node.first_child.scale_parameter[1].threshold", + ]), "ParameterScale descendants don't include bracket thresholds and rates"