def test_basics(): for scenario_arguments in scenarios_arguments: scenario = tax_benefit_system.new_scenario() init_single_entity(scenario, **scenario_arguments) simulation = scenario.new_simulation(debug=False) period = scenario_arguments['period'] yield check_run, simulation, period
def test_basics(scenario_arguments): scenario = tax_benefit_system.new_scenario() init_single_entity(scenario, **scenario_arguments) simulation = scenario.new_simulation(debug=False) period = scenario_arguments['period'] assert simulation.calculate( 'revenu_disponible', period=period ) is not None, "Can't compute revenu_disponible on period {}".format( period) assert simulation.calculate_add('salaire_super_brut', period = period) is not None, \ "Can't compute salaire_super_brut on period {}".format(period)
def test_init_single_entity_parallel_axes(): """Test parallel axes scenario initialisation.""" year = 2019 count = 3 indexes = [0, 1, 2] salaire_de_base_axes = [ dict( count=count, index=index, min=0, max=15000, name='salaire_de_base', period=year, ) for index in indexes ] axes = [salaire_de_base_axes] scenario_kwargs = dict(parent1=dict(age=40), parent2=dict(age=40), enfants=[dict(age=20)], axes=axes, period=year) simulation = init_single_entity(tax_benefit_system.new_scenario(), **scenario_kwargs).new_simulation() assert simulation.calculate_add('salaire_de_base', year) == pytest.approx( [0, 0, 0, 7500, 7500, 7500, 15000, 15000, 15000])
def test(year = 2013): max_sal = 18000 count = 2 people = 1 reform = plf2015(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = count, max = max_sal, min = 0, name = 'salaire_imposable', ), ]], period = periods.period(year), parent1 = dict(date_naissance = datetime.date(year - 40, 1, 1)), parent2 = dict(date_naissance = datetime.date(year - 40, 1, 1)) if people >= 2 else None, enfants = [ dict(date_naissance = datetime.date(year - 9, 1, 1)) if people >= 3 else None, dict(date_naissance = datetime.date(year - 9, 1, 1)) if people >= 4 else None, ] if people >= 3 else None, ) reference_simulation = scenario.new_simulation(use_baseline = True) reform_simulation = scenario.new_simulation() error_margin = 1 impots_directs = reference_simulation.calculate('impots_directs', period = year) reform_impots_directs = reform_simulation.calculate('impots_directs', period = year) ir_plaf_qf = reference_simulation.calculate('ir_plaf_qf', period = year) reform_ir_plaf_qf = reform_simulation.calculate('ir_plaf_qf', period = year) assert max(abs([0, 918] - ir_plaf_qf)) < error_margin assert max(abs([0, 911.4] - reform_ir_plaf_qf)) < error_margin assert max(abs([0, -869] - impots_directs)) < error_margin assert max(abs([0, -911.4 + (1135 - 911.4)] - reform_impots_directs)) < error_margin
def test_parametric_reform(): reform = ir_100_tranche_1(tax_benefit_system) scenario = init_single_entity( reform.new_scenario(), axes=[[ dict( count=3, name='salaire_imposable', max=100000, min=0, ), ]], period=simulation_period, parent1=dict(date_naissance=datetime.date(simulation_year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(use_baseline=True) assert_near(reference_simulation.calculate('impots_directs', period=simulation_period), [0, -7889.20019531, -23435.52929688], absolute_error_margin=1) reform_simulation = scenario.new_simulation() assert_near( reform_simulation.calculate('impots_directs', simulation_period), [0, -13900.20019531, -29446.52929688], absolute_error_margin=1, )
def test(): year = 2013 reform = landais_piketty_saez(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = 3, max = 30000, min = 0, name = 'salaire_de_base', ), ]], period = periods.period(year), parent1 = dict(date_naissance = datetime.date(year - 40, 1, 1)), # parent2 = dict(date_naissance = datetime.date(year - 40, 1, 1)), # enfants = [ # dict(date_naissance = datetime.date(year - 9, 1, 1)), # dict(date_naissance = datetime.date(year - 9, 1, 1)), # ], ) # reference_simulation = scenario.new_simulation(use_baseline = True) # reform_simulation = scenario.new_simulation() reform_assiette_csg = reform_simulation.calculate('assiette_csg', period = year) reform_impot_revenu_lps = reform_simulation.calculate('impot_revenu_lps', period = year) assert_near( -reform_impot_revenu_lps, ((reform_assiette_csg - 10000) * .25 / 30000 + .25) * reform_assiette_csg, absolute_error_margin = 0.01, ) reform_simulation.calculate('revenu_disponible', period = year)
def test_parametric_reform(): reform = ir_100_tranche_1(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = 3, name = 'salaire_imposable', max = 100000, min = 0, ), ]], period = simulation_period, parent1 = dict(date_naissance = datetime.date(simulation_year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(use_baseline = True) assert_near(reference_simulation.calculate('impots_directs', period = simulation_period), [0, -7889.20019531, -23435.52929688], absolute_error_margin = 1) reform_simulation = scenario.new_simulation() assert_near( reform_simulation.calculate('impots_directs', simulation_period), [0, -13900.20019531, -29446.52929688], absolute_error_margin = 1, )
def test_cesthra_invalidee(): year = 2012 period = periods.period(year) reform = cesthra_invalidee(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = 10, max = 30000, min = 0, name = 'salaire_imposable', ), ]], period = period, parent1 = dict(date_naissance = datetime.date(year - 40, 1, 1)), parent2 = dict(date_naissance = datetime.date(year - 40, 1, 1)), enfants = [ dict(date_naissance = datetime.date(year - 9, 1, 1)), dict(date_naissance = datetime.date(year - 9, 1, 1)), ], ) reference_simulation = scenario.new_simulation(use_baseline = True) reference_impo = reference_simulation.calculate('impots_directs', period = period) assert reference_impo is not None reference_revenu_disponible = reference_simulation.calculate('revenu_disponible', period = period) assert reference_revenu_disponible is not None reform_simulation = scenario.new_simulation() reform_impots_directs = reform_simulation.calculate('impots_directs', period = period) assert reform_impots_directs is not None reform_revenu_disponible = reform_simulation.calculate('revenu_disponible', period = period) assert reform_revenu_disponible is not None
def test_coefficient_proratisation_only_contract_periods_wide(): tax_benefit_system = FranceTaxBenefitSystem() scenario = tax_benefit_system.new_scenario() init_single_entity(scenario, period='2017', # wide: we simulate for the year parent1=dict(salaire_de_base={'2017-11': 2300}, effectif_entreprise=1, code_postal_entreprise="75001", categorie_salarie=u'prive_non_cadre', contrat_de_travail_debut={2017: '2017-11-01'}, contrat_de_travail_fin={2017: '2017-12-01'}, allegement_fillon_mode_recouvrement=u'progressif')) simulation = scenario.new_simulation() assert simulation.calculate('coefficient_proratisation', '2017-11') == 1 assert simulation.calculate('coefficient_proratisation', '2017-12') == 0 assert simulation.calculate('coefficient_proratisation', '2017-10') == 0 assert simulation.calculate_add('coefficient_proratisation', '2017') == 1
def test_charge_loyer(): year = 2013 reform = trannoy_wasmer(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = 10, max = 30000, min = 0, name = 'salaire_de_base', ), ]], period = periods.period(year), parent1 = dict(date_naissance = datetime.date(year - 40, 1, 1)), parent2 = dict(date_naissance = datetime.date(year - 40, 1, 1)), enfants = [ dict(date_naissance = datetime.date(year - 9, 1, 1)), dict(date_naissance = datetime.date(year - 9, 1, 1)), ], menage = dict( loyer = 1000, ), ) reform_simulation = scenario.new_simulation() absolute_error_margin = 0.01 reform_charge_loyer = reform_simulation.calculate('charge_loyer', period = year) assert_near(reform_charge_loyer, [1000] * 10, absolute_error_margin = absolute_error_margin)
def run(reform_class, year): max_sal = 18000 count = 2 people = 1 reform = reform_class(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = count, max = max_sal, min = 0, name = 'salaire_imposable', ), ]], period = periods.period(year), parent1 = dict(date_naissance = datetime.date(year - 40, 1, 1)), parent2 = dict(date_naissance = datetime.date(year - 40, 1, 1)) if people >= 2 else None, enfants = [ dict(date_naissance = datetime.date(year - 9, 1, 1)) if people >= 3 else None, dict(date_naissance = datetime.date(year - 9, 1, 1)) if people >= 4 else None, ] if people >= 3 else None, ) reference_simulation = scenario.new_simulation(use_baseline = True) reform_simulation = scenario.new_simulation() # error_margin = 1 impo = reference_simulation.calculate('impots_directs', period = year) # noqa F841 reform_impo = reform_simulation.calculate('impots_directs', period = year) # noqa F841
def test(year=2013): max_sal = 18000 count = 2 people = 1 reform = plfr2014(tax_benefit_system) scenario = init_single_entity( reform.new_scenario(), axes=[[ dict( count=count, max=max_sal, min=0, name='salaire_imposable', ), ]], period=periods.period(year), parent1=dict(date_naissance=datetime.date(year - 40, 1, 1)), parent2=dict( date_naissance=datetime.date(year - 40, 1, 1)) if people >= 2 else None, enfants=[ dict(date_naissance=datetime.date(year - 9, 1, 1)) if people >= 3 else None, dict(date_naissance=datetime.date(year - 9, 1, 1)) if people >= 4 else None, ] if people >= 3 else None, ) reference_simulation = scenario.new_simulation(use_baseline=True) reform_simulation = scenario.new_simulation() # error_margin = 1 impots_directs = reference_simulation.calculate('impots_directs', period=year) # noqa F841 reform_impots_directs = reform_simulation.calculate( 'impots_directs', period=year) # noqa F841
def test_coefficient_proratisation_only_contract_periods_wide(): tax_benefit_system = FranceTaxBenefitSystem() scenario = tax_benefit_system.new_scenario() init_single_entity( scenario, period='2017', # wide: we simulate for the year parent1=dict(salaire_de_base={'2017-11': 2300}, effectif_entreprise=1, code_postal_entreprise="75001", categorie_salarie=u'prive_non_cadre', contrat_de_travail_debut='2017-11-01', contrat_de_travail_fin='2017-12-01', allegement_fillon_mode_recouvrement=u'progressif')) simulation = scenario.new_simulation() assert simulation.calculate('coefficient_proratisation', '2017-11') == 1 assert simulation.calculate('coefficient_proratisation', '2017-12') == 0 assert simulation.calculate('coefficient_proratisation', '2017-10') == 0 assert simulation.calculate_add('coefficient_proratisation', '2017') == 1
def _scenario(reform: Reform, count: int, _max: int, _min: int, name: str, year: int, people: int) -> object: return init_single_entity( reform.new_scenario(), axes=axes(count, _max, _min, name), period=periods.period(year), parent1=parent1(year), parent2=parent2(year, people), enfants=enfants(year, people), )
def test_allocations_familiales_imposables(): year = 2012 reform = allocations_familiales_imposables(tax_benefit_system) scenario = init_single_entity( reform.new_scenario(), axes=[[ dict( count=10, max=30000, min=0, name='salaire_imposable', ), ]], period=periods.period(year), parent1=dict(date_naissance=datetime.date(year - 40, 1, 1)), parent2=dict(date_naissance=datetime.date(year - 40, 1, 1)), enfants=[ dict(date_naissance=datetime.date(year - 9, 1, 1)), dict(date_naissance=datetime.date(year - 9, 1, 1)), ], ) reference_simulation = scenario.new_simulation(use_baseline=True) absolute_error_margin = 0.01 af = reference_simulation.calculate_add('af', year) expected_af = [(12 * 399.0) * .32 ] * 10 # Pas de hangement de BMAF en cours d'année assert_near(expected_af, af, absolute_error_margin=absolute_error_margin) rbg = reference_simulation.calculate('rbg', year) reform_simulation = scenario.new_simulation() reform_af = reform_simulation.calculate_add('af', year) assert_near(expected_af, reform_af, absolute_error_margin=absolute_error_margin) reform_af_imposables = reform_simulation.calculate( 'allocations_familiales_imposables', year) assert_near(expected_af, reform_af_imposables, absolute_error_margin=absolute_error_margin) reform_rbg = reform_simulation.calculate('rbg', year) expected_rbg = rbg + af assert_near(expected_rbg, reform_rbg, absolute_error_margin=absolute_error_margin)
def test_average_tax_rate(): year = 2013 simulation = init_single_entity(tax_benefit_system.new_scenario(), axes = [[ dict( count = 100, name = 'salaire_imposable', max = 24000, min = 0, ), ]], period = year, parent1 = dict(age = 40), ).new_simulation() assert (average_rate( target = simulation.calculate('revenu_disponible', period = year), varying = simulation.calculate('revenu_disponible', period = year), ) == 0).all()
def test_average_tax_rate(): year = 2013 simulation = init_single_entity(tax_benefit_system.new_scenario(), axes = [[ dict( count = 100, name = 'salaire_imposable', max = 24000, min = 0, ), ]], period = year, parent1 = dict(age = 40), ).new_simulation() assert (average_rate( target = simulation.calculate('revenu_disponible', period = year), varying = simulation.calculate('revenu_disponible', period = year), ) == 0).all()
def test(year=2013): max_sal = 18000 count = 2 people = 1 reform = plf2015(tax_benefit_system) scenario = init_single_entity( reform.new_scenario(), axes=[[ dict( count=count, max=max_sal, min=0, name='salaire_imposable', ), ]], period=periods.period(year), parent1=dict(date_naissance=datetime.date(year - 40, 1, 1)), parent2=dict( date_naissance=datetime.date(year - 40, 1, 1)) if people >= 2 else None, enfants=[ dict(date_naissance=datetime.date(year - 9, 1, 1)) if people >= 3 else None, dict(date_naissance=datetime.date(year - 9, 1, 1)) if people >= 4 else None, ] if people >= 3 else None, ) reference_simulation = scenario.new_simulation(use_baseline=True) reform_simulation = scenario.new_simulation() error_margin = 1 impots_directs = reference_simulation.calculate('impots_directs', period=year) reform_impots_directs = reform_simulation.calculate('impots_directs', period=year) ir_plaf_qf = reference_simulation.calculate('ir_plaf_qf', period=year) reform_ir_plaf_qf = reform_simulation.calculate('ir_plaf_qf', period=year) assert max(abs([0, 918] - ir_plaf_qf)) < error_margin assert max(abs([0, 911.4] - reform_ir_plaf_qf)) < error_margin assert max(abs([0, -869] - impots_directs)) < error_margin assert max(abs([0, -911.4 + (1135 - 911.4)] - reform_impots_directs)) < error_margin
def test_allocations_familiales_imposables(): year = 2012 reform = allocations_familiales_imposables(tax_benefit_system) scenario = init_single_entity(reform.new_scenario(), axes = [[ dict( count = 10, max = 30000, min = 0, name = 'salaire_imposable', ), ]], period = periods.period(year), parent1 = dict(date_naissance = datetime.date(year - 40, 1, 1)), parent2 = dict(date_naissance = datetime.date(year - 40, 1, 1)), enfants = [ dict(date_naissance = datetime.date(year - 9, 1, 1)), dict(date_naissance = datetime.date(year - 9, 1, 1)), ], ) reference_simulation = scenario.new_simulation(use_baseline = True) absolute_error_margin = 0.01 af = reference_simulation.calculate_add('af', year) expected_af = [(12 * 399.0) * .32] * 10 # Pas de hangement de BMAF en cours d'année assert_near(expected_af, af, absolute_error_margin = absolute_error_margin) rbg = reference_simulation.calculate('rbg', year) reform_simulation = scenario.new_simulation() reform_af = reform_simulation.calculate_add('af', year) assert_near(expected_af, reform_af, absolute_error_margin = absolute_error_margin) reform_af_imposables = reform_simulation.calculate('allocations_familiales_imposables', year) assert_near(expected_af, reform_af_imposables, absolute_error_margin = absolute_error_margin) reform_rbg = reform_simulation.calculate('rbg', year) expected_rbg = rbg + af assert_near(expected_rbg, reform_rbg, absolute_error_margin = absolute_error_margin)