Exemplo n.º 1
0
def test_no_period():
    year = 2016

    buggy_tbf = CountryTaxBenefitSystem()
    buggy_tbf.add_variable(income_tax_no_period)

    simulation = buggy_tbf.new_scenario().init_from_attributes(
        period=year,
        input_variables=dict(salary=2000, ),
    ).new_simulation()
    simulation.calculate_add('income_tax_no_period', year)
Exemplo n.º 2
0
def test_inflate_scale():
    """
        Test parameters inflator on a scale parameter as the social security contributions tax_scale
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    inflate_parameters(parameters, inflator=.3, base_year=2015, last_year=2016)
    for (threshold_2016, threshold_2015) in zip(
            parameters.taxes.social_security_contribution(2016).thresholds,
            parameters.taxes.social_security_contribution(2015).thresholds):
        assert threshold_2016 == threshold_2015 * 1.3
Exemplo n.º 3
0
def test_inflate_simple_parameter():
    """
        Test parameters inflator on a simple parameter as the basic income
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    basic_income_2016 = parameters.benefits.basic_income(2016)
    basic_income_2017 = parameters.benefits.basic_income(2017)
    assert basic_income_2017 == basic_income_2016
    inflate_parameters(parameters, inflator=.1, base_year=2016, last_year=2017)

    assert basic_income_2016 == parameters.benefits.basic_income(2016)
    assert 1.1 * basic_income_2016 == parameters.benefits.basic_income(2017)
Exemplo n.º 4
0
def test_asof_simple_annual_parameter():
    """
        Test parameters_asof on a simple parameter
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    income_tax_rate_2014 = parameters.taxes.income_tax_rate(2014)
    income_tax_rate_2015 = parameters.taxes.income_tax_rate(2015)
    assert income_tax_rate_2015 != income_tax_rate_2014
    parameters_asof(parameters, instant="2014")
    assert parameters.taxes.income_tax_rate(
        2014) == income_tax_rate_2014, "{} != {}".format(
            parameters.taxes.income_tax_rate(2014), income_tax_rate_2014)
    assert parameters.taxes.income_tax_rate(
        2015) == income_tax_rate_2014, "{} != {}".format(
            parameters.taxes.income_tax_rate(2015), income_tax_rate_2014)
Exemplo n.º 5
0
def test_asof_scale_parameters():
    """
        Test parameters_asof on a scale parameter
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    social_security_contribution_2016 = parameters.taxes.social_security_contribution(
        2016).thresholds[1]
    social_security_contribution_2017 = parameters.taxes.social_security_contribution(
        2017).thresholds[1]
    assert social_security_contribution_2016 != social_security_contribution_2017
    parameters_asof(parameters, instant="2016")
    assert parameters.taxes.social_security_contribution(
        2016).thresholds[1] == social_security_contribution_2016
    assert parameters.taxes.social_security_contribution(
        2017).thresholds[1] == social_security_contribution_2016
Exemplo n.º 6
0
def test_inflate_scale_with_changing_number_of_brackets():
    """
        Test parameters inflator on a scale parameter when the number of brackets changes

        Use parameters_asof to use the present legislation the future pre-inflated legislation
        Test on the social security contributions tax_scale
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    parameters_asof(
        parameters,
        instant=periods.instant(2016))  # Remove post 2016 legislation changes
    inflate_parameters(parameters, inflator=.3, base_year=2016, last_year=2017)
    for (threshold_2017, threshold_2016) in zip(
            parameters.taxes.social_security_contribution(2017).thresholds,
            parameters.taxes.social_security_contribution(2016).thresholds):
        assert threshold_2017 == threshold_2016 * 1.3, "{} != {}".format(
            threshold_2017, threshold_2016 * 1.3)
Exemplo n.º 7
0
def test_variable_with_reference(make_isolated_simulation):
    tax_benefit_system = CountryTaxBenefitSystem()  # Work in isolation

    simulation_base = make_isolated_simulation(tax_benefit_system,
                                               {'salary': 4000})

    revenu_disponible_avant_reforme = simulation_base.calculate(
        'disposable_income', "2016-01")
    assert (revenu_disponible_avant_reforme > 0)

    class disposable_income(Variable):
        definition_period = MONTH

        def formula(household, period):
            return household.empty_array()

    tax_benefit_system.update_variable(disposable_income)

    simulation_reform = make_isolated_simulation(tax_benefit_system,
                                                 {'salary': 4000})
    revenu_disponible_apres_reforme = simulation_reform.calculate(
        'disposable_income', "2016-01")

    assert (revenu_disponible_apres_reforme == 0)
Exemplo n.º 8
0
def test_variable_with_reference():
    tax_benefit_system = CountryTaxBenefitSystem()  # Work in isolation

    def new_simulation():
        return tax_benefit_system.new_scenario().init_from_attributes(
            period="2016-01",
            input_variables=dict(salary=4000, ),
        ).new_simulation()

    revenu_disponible_avant_reforme = new_simulation().calculate(
        'disposable_income', "2016-01")
    assert (revenu_disponible_avant_reforme > 0)

    class disposable_income(Variable):
        definition_period = MONTH

        def formula(self, simulation, period):
            return self.zeros()

    tax_benefit_system.update_variable(disposable_income)
    revenu_disponible_apres_reforme = new_simulation().calculate(
        'disposable_income', "2016-01")

    assert (revenu_disponible_apres_reforme == 0)
Exemplo n.º 9
0
def tax_benefit_system():
    return CountryTaxBenefitSystem()
Exemplo n.º 10
0
from __future__ import unicode_literals, print_function, division, absolute_import
from nose.tools import raises

from openfisca_country_template import CountryTaxBenefitSystem

tbs = CountryTaxBenefitSystem()


def test_extension_not_already_loaded():
    assert tbs.get_variable('local_town_child_allowance') is None


def test_load_extension():
    tbs.load_extension('openfisca_extension_template')
    assert tbs.get_variable('local_town_child_allowance') is not None


def test_unload_extensions():
    tbs = CountryTaxBenefitSystem()
    assert tbs.get_variable('local_town_child_allowance') is None


@raises(ValueError)
def test_failure_to_load_extension_when_directory_doesnt_exist():
    tbs.load_extension('/this/is/not/a/real/path')
Exemplo n.º 11
0
def test_variables_as_of():
    tax_benefit_system = CountryTaxBenefitSystem()
    instant = periods.instant("2015-12-31")
    variables_asof(tax_benefit_system, instant)
Exemplo n.º 12
0
def test_parameters_as_of():
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    instant = periods.instant("2012-12-31")
    parameters_asof(parameters, instant)
    check_max_instant(parameters, instant)
Exemplo n.º 13
0
import pytest

from openfisca_country_template import CountryTaxBenefitSystem

original_tbs = CountryTaxBenefitSystem()


def test_load_extension():
    tbs = original_tbs.clone()
    assert tbs.get_variable('local_town_child_allowance') is None

    tbs.load_extension('openfisca_extension_template')

    assert tbs.get_variable('local_town_child_allowance') is not None
    assert original_tbs.get_variable('local_town_child_allowance') is None


def test_access_to_parameters():
    tbs = original_tbs.clone()
    tbs.load_extension('openfisca_extension_template')

    assert tbs.parameters('2016-01').local_town.child_allowance.amount == 100.0
    assert tbs.parameters.local_town.child_allowance.amount('2016-01') == 100.0


def test_failure_to_load_extension_when_directory_doesnt_exist():
    with pytest.raises(ValueError):
        original_tbs.load_extension('/this/is/not/a/real/path')
Exemplo n.º 14
0
def get_filled_tbs():
    tax_benefit_system = CountryTaxBenefitSystem()
    tax_benefit_system.add_variables(input, intermediate, output)

    return tax_benefit_system
Exemplo n.º 15
0
def test_unload_extensions():
    tbs = CountryTaxBenefitSystem()
    assert tbs.get_variable('local_town_child_allowance') is None
Exemplo n.º 16
0
            'salary': {
                '2011-01': 1000
            }
        },
        'Paul': {},
        'Leila': {},
        'Javier': {}
    },
    'households': {
        'h1': {
            'children': ['Leila'],
            'parents': ['Ari', 'Paul'],
            'rent': {
                '2011-01': 300
            }
        },
        'h2': {
            'parents': ['Javier']
        }
    },
}

tax_benefit_system = CountryTaxBenefitSystem()

simulation_builder = SimulationBuilder()
simulation = simulation_builder.build_from_entities(tax_benefit_system,
                                                    TEST_CASE)

housing_allowance = simulation.calculate('housing_allowance', '2011-01')
print("housing_allowance", housing_allowance)
Exemplo n.º 17
0
def isolated_tax_benefit_system():
    return CountryTaxBenefitSystem()