Skip to content

Commit

Permalink
test: get holder (#1238 #1276 #1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 16, 2024
1 parent e33ef55 commit 19b7598
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions openfisca_core/populations/_core_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,51 @@ def check_period_validity(
# Helpers

def get_holder(self, variable_name: t.VariableName) -> t.Holder:
"""Return the holder of a variable.
Args:
variable_name: The name of the variable.
Returns:
Holder: The holder of the variable.
Examples:
>>> from openfisca_core import (
... entities,
... holders,
... periods,
... populations,
... simulations,
... taxbenefitsystems,
... simulations,
... variables,
... )
>>> class Person(entities.SingleEntity): ...
>>> person = Person("person", "people", "", "")
>>> class Salary(variables.Variable):
... definition_period = periods.WEEK
... entity = person
... value_type = int
>>> tbs = taxbenefitsystems.TaxBenefitSystem([person])
>>> person.set_tax_benefit_system(tbs)
>>> population = populations.SinglePopulation(person)
>>> simulation = simulations.Simulation(tbs, {person.key: population})
>>> population.get_holder("income_tax")
Traceback (most recent call last):
VariableNotFoundError: You tried to calculate or to set a value ...
>>> tbs.add_variable(Salary)
<openfisca_core.populations._core_population.Salary object at...
>>> salary = Salary()
>>> population.get_holder(salary.name)
<openfisca_core.holders.holder.Holder object at ...
"""
self.entity.check_variable_defined_for_entity(variable_name)
holder = self._holders.get(variable_name)
if holder:
Expand Down

0 comments on commit 19b7598

Please sign in to comment.