Skip to content

Commit

Permalink
Implement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Mar 22, 2022
1 parent 1bd0c62 commit b3a7cbd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
9 changes: 8 additions & 1 deletion openfisca_core/parameters/parameter_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 24 additions & 24 deletions tests/core/tax_scales/test_tax_scale_descendants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ def test_tax_scale_descendants_are_complete():
"first_child": {
"scale_parameter": {
"brackets": [
{
"rate": {
"2022-01-01": 0.1,
},
"threshold": {
"2022-01-01": 0,
}
{
"rate": {
"2022-01-01": 0.1,
},
"threshold": {
"2022-01-01": 0,
}
},
{
"rate": {
"2022-01-01": 0.2,
},
"threshold": {
"2022-01-01": 100,
}
}
]
},
{
"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 [
"root_node.first_child.scale_parameter[0].rate",
"root_node.first_child.scale_parameter[0].threshold",
"root_node.first_child.scale_parameter[1].rate",
"root_node.first_child.scale_parameter[1].threshold",
]), "ParameterScale descendants don't include bracket thresholds and rates"
"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"

0 comments on commit b3a7cbd

Please sign in to comment.