def test_entity_variables_with_constructor():
    simulation_yaml = """
        persons:
          bill: {}
          bob: {}
          claudia: {}
          janet: {}
          tom: {}
        households:
          first_household:
            parents:
            - bill
            - bob
            children:
            - janet
            - tom
            rent:
              2017-06: 800
          second_household:
            parents:
            - claudia
            rent:
              2017-06: 600
    """

    simulation = SimulationBuilder().build_from_dict(tax_benefit_system, yaml.safe_load(simulation_yaml))
    household = simulation.household
    assert_near(household('rent', "2017-06"), [800, 600])
def test_entity_structure_with_constructor():
    simulation_yaml = """
        persons:
          bill: {}
          bob: {}
          claudia: {}
          janet: {}
          tom: {}
        households:
          first_household:
            parents:
            - bill
            - bob
            children:
            - janet
            - tom
          second_household:
            parents:
            - claudia
    """

    simulation = SimulationBuilder().build_from_dict(tax_benefit_system, yaml.safe_load(simulation_yaml))

    household = simulation.household

    assert_near(household.members_entity_id, [0, 0, 1, 0, 0])
    assert((household.members_role == [FIRST_PARENT, SECOND_PARENT, FIRST_PARENT, CHILD, CHILD]).all())
    assert_near(household.members_position, [0, 1, 0, 2, 3])
def test_person_variable_with_constructor():
    simulation_yaml = """
        persons:
          bill:
            salary:
              2017-11: 1500
              2017-12: 2000
          bob:
            salary: {}
          claudia:
            salary:
              2017-11: 3000
              2017-12: 4000
          janet: {}
          tom: {}
        households:
          first_household:
            parents:
            - bill
            - bob
            children:
            - janet
            - tom
          second_household:
            parents:
            - claudia
    """

    simulation = SimulationBuilder().build_from_dict(tax_benefit_system, yaml.safe_load(simulation_yaml))
    person = simulation.person
    assert_near(person('salary', "2017-11"), [1500, 0, 3000, 0, 0])
    assert_near(person('salary', "2017-12"), [2000, 0, 4000, 0, 0])
def test_entity_variables_with_constructor():
    simulation_yaml = """
        persons:
          bill: {}
          bob: {}
          claudia: {}
          janet: {}
          tom: {}
        households:
          first_household:
            parents:
            - bill
            - bob
            children:
            - janet
            - tom
            rent:
              2017-06: 800
          second_household:
            parents:
            - claudia
            rent:
              2017-06: 600
    """

    simulation = SimulationBuilder().build_from_dict(
        tax_benefit_system, yaml.safe_load(simulation_yaml))
    household = simulation.household
    assert_near(household('rent', "2017-06"), [800, 600])
def test_entity_structure_with_constructor():
    simulation_yaml = """
        persons:
          bill: {}
          bob: {}
          claudia: {}
          janet: {}
          tom: {}
        households:
          first_household:
            parents:
            - bill
            - bob
            children:
            - janet
            - tom
          second_household:
            parents:
            - claudia
    """

    simulation = SimulationBuilder().build_from_dict(
        tax_benefit_system, yaml.safe_load(simulation_yaml))

    household = simulation.household

    assert_near(household.members_entity_id, [0, 0, 1, 0, 0])
    assert ((household.members_role == [
        FIRST_PARENT, SECOND_PARENT, FIRST_PARENT, CHILD, CHILD
    ]).all())
    assert_near(household.members_position, [0, 1, 0, 2, 3])
def test_person_variable_with_constructor():
    simulation_yaml = """
        persons:
          bill:
            salary:
              2017-11: 1500
              2017-12: 2000
          bob:
            salary: {}
          claudia:
            salary:
              2017-11: 3000
              2017-12: 4000
          janet: {}
          tom: {}
        households:
          first_household:
            parents:
            - bill
            - bob
            children:
            - janet
            - tom
          second_household:
            parents:
            - claudia
    """

    simulation = SimulationBuilder().build_from_dict(
        tax_benefit_system, yaml.safe_load(simulation_yaml))
    person = simulation.person
    assert_near(person('salary', "2017-11"), [1500, 0, 3000, 0, 0])
    assert_near(person('salary', "2017-12"), [2000, 0, 4000, 0, 0])
Beispiel #7
0
def test_inconsistent_input(simulation_builder):
    input_yaml = """
        salary:
            2016-10: [12000, 20000]
        income_tax:
            2016-10: [100, 200, 300]
    """
    with raises(ValueError) as error:
        simulation_builder.build_from_dict(tax_benefit_system,
                                           yaml.safe_load(input_yaml))
    assert "its length is 3 while there are 2" in error.value.args[0]
Beispiel #8
0
def test_single_entity_shortcut(simulation_builder):
    input_yaml = """
        persons:
          Alicia: {}
          Javier: {}
        household:
          parents: [Alicia, Javier]
    """

    simulation = simulation_builder.build_from_dict(tax_benefit_system,
                                                    yaml.safe_load(input_yaml))
    assert simulation.household.count == 1
Beispiel #9
0
def test_vectorial_input(simulation_builder):
    input_yaml = """
        salary:
            2016-10: [12000, 20000]
    """

    simulation = simulation_builder.build_from_dict(tax_benefit_system,
                                                    yaml.safe_load(input_yaml))

    assert_near(simulation.get_array("salary", "2016-10"), [12000, 20000])
    simulation.calculate("income_tax", "2016-10")
    simulation.calculate("total_taxes", "2016-10")
Beispiel #10
0
def test_simulation(simulation_builder):
    input_yaml = """
        salary:
            2016-10: 12000
    """

    simulation = simulation_builder.build_from_dict(tax_benefit_system,
                                                    yaml.safe_load(input_yaml))

    assert simulation.get_array("salary", "2016-10") == 12000
    simulation.calculate("income_tax", "2016-10")
    simulation.calculate("total_taxes", "2016-10")
Beispiel #11
0
def test_some_person_without_household(simulation_builder):
    input_yaml = """
        persons: {'Alicia': {}, 'Bob': {}}
        household: {'parents': ['Alicia']}
    """
    simulation = simulation_builder.build_from_dict(tax_benefit_system,
                                                    yaml.safe_load(input_yaml))
    assert simulation.household.count == 2
    parents_in_households = simulation.household.nb_persons(
        role=Household.PARENT)
    assert parents_in_households.tolist() == [
        1, 1
    ]  # household member default role is first_parent
Beispiel #12
0
def test_order_preserved(simulation_builder):
    input_yaml = """
        persons:
          Javier: {}
          Alicia: {}
          Sarah: {}
          Tom: {}
        household:
          parents: [Alicia, Javier]
          children: [Tom, Sarah]
    """

    data = yaml.safe_load(input_yaml)
    simulation = simulation_builder.build_from_dict(tax_benefit_system, data)

    assert simulation.persons.ids == ['Javier', 'Alicia', 'Sarah', 'Tom']