def test(year=2013): max_sal = 18000 count = 2 people = 1 reform = base.get_cached_reform( reform_key='plfr2014', tax_benefit_system=base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes=[ dict( count=count, max=max_sal, min=0, name='salaire_imposable', ), ], period=periods.period('year', 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(reference=True) reform_simulation = scenario.new_simulation() # error_margin = 1 impots_directs = reference_simulation.calculate('impots_directs') reform_impots_directs = reform_simulation.calculate('impots_directs')
def test_charge_loyer(): year = 2013 reform = base.get_cached_reform( reform_key = 'trannoy_wasmer', tax_benefit_system = base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = 10, max = 30000, min = 0, name = 'salaire_de_base', ), ], period = periods.period('year', 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') assert_near(reform_charge_loyer, [1000] * 10, absolute_error_margin = absolute_error_margin)
def run(reform_key, year): max_sal = 18000 count = 2 people = 1 reform = base.get_cached_reform( reform_key = reform_key, tax_benefit_system = base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = count, max = max_sal, min = 0, name = 'salaire_imposable', ), ], period = periods.period('year', 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(reference = True) reform_simulation = scenario.new_simulation() # error_margin = 1 impo = reference_simulation.calculate('impo') reform_impo = reform_simulation.calculate('impo')
def test(year=2013): max_sal = 18000 count = 2 people = 1 reform = base.get_cached_reform(reform_key="plf2015", tax_benefit_system=base.tax_benefit_system) scenario = reform.new_scenario().init_single_entity( axes=[dict(count=count, max=max_sal, min=0, name="salaire_imposable")], period=periods.period("year", year), parent1=dict(birth=datetime.date(year - 40, 1, 1)), parent2=dict(birth=datetime.date(year - 40, 1, 1)) if people >= 2 else None, enfants=[ dict(birth=datetime.date(year - 9, 1, 1)) if people >= 3 else None, dict(birth=datetime.date(year - 9, 1, 1)) if people >= 4 else None, ] if people >= 3 else None, ) reference_simulation = scenario.new_simulation(debug=True, reference=True) reform_simulation = scenario.new_simulation(debug=True) error_margin = 1 impo = reference_simulation.calculate("impo") reform_impo = reform_simulation.calculate("impo") ir_plaf_qf = reference_simulation.calculate("ir_plaf_qf") reform_ir_plaf_qf = reform_simulation.calculate("ir_plaf_qf") assert_less(max(abs([0, 918] - ir_plaf_qf)), error_margin) assert_less(max(abs([0, 911.4] - reform_ir_plaf_qf)), error_margin) assert_less(max(abs([0, -869] - impo)), error_margin) assert_less(max(abs([0, -911.4 + (1135 - 911.4)] - reform_impo)), error_margin)
def test_allocations_familiales_imposables(): year = 2012 reform = base.get_cached_reform( reform_key='allocations_familiales_imposables', tax_benefit_system=base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes=[ dict( count=10, max=30000, min=0, name='salaire_imposable', ), ], period=periods.period('year', 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(reference=True) absolute_error_margin = 0.01 af = reference_simulation.calculate_add('af') 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') reform_simulation = scenario.new_simulation() reform_af = reform_simulation.calculate_add('af') assert_near(expected_af, reform_af, absolute_error_margin=absolute_error_margin) reform_af_imposables = reform_simulation.calculate( 'allocations_familiales_imposables') assert_near(expected_af, reform_af_imposables, absolute_error_margin=absolute_error_margin) reform_rbg = reform_simulation.calculate('rbg') assert_near(reform_rbg, rbg + af, absolute_error_margin=absolute_error_margin)
def test_charge_loyer(): year = 2013 reform = base.get_cached_reform(reform_key="trannoy_wasmer", tax_benefit_system=base.tax_benefit_system) scenario = reform.new_scenario().init_single_entity( axes=[dict(count=10, max=30000, min=0, name="salaire_de_base")], period=periods.period("year", year), parent1=dict(birth=datetime.date(year - 40, 1, 1)), parent2=dict(birth=datetime.date(year - 40, 1, 1)), enfants=[dict(birth=datetime.date(year - 9, 1, 1)), dict(birth=datetime.date(year - 9, 1, 1))], menage=dict(loyer=1000), ) reform_simulation = scenario.new_simulation(debug=True) absolute_error_margin = 0.01 reform_charge_loyer = reform_simulation.calculate("charge_loyer") assert_near(reform_charge_loyer, [1000] * 10, absolute_error_margin=absolute_error_margin)
def test_plfr2014(): year = 2013 reform = base.get_cached_reform(reform_key="plfr2014", tax_benefit_system=base.tax_benefit_system) scenario = reform.new_scenario().init_single_entity( axes=[ dict( count=10, max=13795 * (1 + 0.1) * (1 + 0.03), min=13795 * (1 + 0.1) * (1 - 0.03), name="salaire_imposable", ) ], period=year, parent1=dict(birth=datetime.date(year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(debug=True, reference=True) absolute_error_margin = 1 rfr = reference_simulation.calculate("rfr") expected_rfr = [13247, 13338, 13429, 13520, 13611, 13703, 13793, 13884, 13975, 14066] assert_near(expected_rfr, rfr, absolute_error_margin=absolute_error_margin) impo = reference_simulation.calculate("impo") expected_impo = [-249.11, -268.22, -287.33, -306.44, -325.55, -344.87, -363.77, -382.88, -401.99, -421.1] assert_near(expected_impo, impo, absolute_error_margin=absolute_error_margin) reform_simulation = scenario.new_simulation(debug=True) reform_reduction_impot_exceptionnelle = reform_simulation.calculate("reduction_impot_exceptionnelle") expected_reform_reduction_impot_exceptionnelle = [350, 350, 350, 350, 350, 350, 350, 261, 170, 79] assert_near( expected_reform_reduction_impot_exceptionnelle, reform_reduction_impot_exceptionnelle, absolute_error_margin=absolute_error_margin, ) reform_rfr = reform_simulation.calculate("rfr") # rfr must be the same than before reform. assert_near(expected_rfr, reform_rfr, absolute_error_margin=absolute_error_margin) reform_impo = reform_simulation.calculate("impo") expected_reform_impo = [0, 0, 0, 0, 0, 0, 0, -121.88, -231.99, -342.1] assert_near(expected_reform_impo, reform_impo, absolute_error_margin=absolute_error_margin)
def test_allocations_familiales_imposables(): year = 2012 reform = base.get_cached_reform( reform_key = 'allocations_familiales_imposables', tax_benefit_system = base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = 10, max = 30000, min = 0, name = 'salaire_imposable', ), ], period = periods.period('year', 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(reference = True) absolute_error_margin = 0.01 af = reference_simulation.calculate_add('af') expected_af = [1528.35] * 10 assert_near(expected_af, af, absolute_error_margin = absolute_error_margin) rbg = reference_simulation.calculate('rbg') reform_simulation = scenario.new_simulation() reform_af = reform_simulation.calculate_add('af') assert_near(expected_af, reform_af, absolute_error_margin = absolute_error_margin) reform_af_imposables = reform_simulation.calculate('allocations_familiales_imposables') assert_near(expected_af, reform_af_imposables, absolute_error_margin = absolute_error_margin) reform_rbg = reform_simulation.calculate('rbg') assert_near(reform_rbg, rbg + af, absolute_error_margin = absolute_error_margin)
def test(year = 2013): max_sal = 18000 count = 2 people = 1 reform = base.get_cached_reform( reform_key = 'plf2015', tax_benefit_system = base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = count, max = max_sal, min = 0, name = 'salaire_imposable', ), ], period = periods.period('year', 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(reference = True) reform_simulation = scenario.new_simulation() error_margin = 1 impo = reference_simulation.calculate('impo') reform_impo = reform_simulation.calculate('impo') ir_plaf_qf = reference_simulation.calculate('ir_plaf_qf') reform_ir_plaf_qf = reform_simulation.calculate('ir_plaf_qf') assert_less(max(abs([0, 918] - ir_plaf_qf)), error_margin) assert_less(max(abs([0, 911.4] - reform_ir_plaf_qf)), error_margin) assert_less(max(abs([0, -869] - impo)), error_margin) assert_less(max(abs([0, -911.4 + (1135 - 911.4)] - reform_impo)), error_margin)
def test_cesthra_invalidee(): year = 2012 period = periods.period('year', year) reform = base.get_cached_reform( reform_key='cesthra_invalidee', tax_benefit_system=base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( 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(reference=True) reference_impo = reference_simulation.calculate('impo') assert reference_impo is not None reference_revdisp = reference_simulation.calculate('revdisp', period=period) assert reference_revdisp is not None reform_simulation = scenario.new_simulation() reform_impo = reform_simulation.calculate('impo') assert reform_impo is not None reform_revdisp = reform_simulation.calculate('revdisp', period=period) assert reform_revdisp is not None
def test_cesthra_invalidee(): year = 2012 period = periods.period('year', year) reform = base.get_cached_reform( reform_key = 'cesthra_invalidee', tax_benefit_system = base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = 10, max = 30000, min = 0, name = 'salaire_imposable', ), ], period = period, parent1 = dict(birth = datetime.date(year - 40, 1, 1)), parent2 = dict(birth = datetime.date(year - 40, 1, 1)), enfants = [ dict(birth = datetime.date(year - 9, 1, 1)), dict(birth = datetime.date(year - 9, 1, 1)), ], ) reference_simulation = scenario.new_simulation(debug = True, reference = True) reference_impo = reference_simulation.calculate('impo') assert reference_impo is not None reference_revdisp = reference_simulation.calculate('revdisp', period = period) assert reference_revdisp is not None reform_simulation = scenario.new_simulation(debug = True) reform_impo = reform_simulation.calculate('impo') assert reform_impo is not None reform_revdisp = reform_simulation.calculate('revdisp', period = period) assert reform_revdisp is not None
def test(year = 2014): max_sal = 20000 count = 2 people = 1 reform = base.get_cached_reform( reform_key = 'plf2015', tax_benefit_system = base.tax_benefit_system, ) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = count, max = max_sal, min = 0, name = 'salaire_imposable', ), ], period = periods.period('year', year), parent1 = dict(birth = datetime.date(year - 40, 1, 1)), parent2 = dict(birth = datetime.date(year - 40, 1, 1)) if people >= 2 else None, enfants = [ dict(birth = datetime.date(year - 9, 1, 1)) if people >= 3 else None, dict(birth = datetime.date(year - 9, 1, 1)) if people >= 4 else None, ] if people >= 3 else None, ) reference_simulation = scenario.new_simulation(debug = True, reference = True) reform_simulation = scenario.new_simulation(debug = True) error_margin = 0.1 impo = reference_simulation.calculate('impo') reform_impo = reform_simulation.calculate('impo') print impo print reform_impo boum assert_less(max(abs(impo - reform_impo)), error_margin)