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)
{ 1: 80, 2: 90, }, ) return result # TaxBenefitSystem instance declared after formulas tax_benefit_system = CountryTaxBenefitSystem() tax_benefit_system.add_variables(choice, uses_multiplication, uses_switch) month = '2013-01' scenario = tax_benefit_system.new_scenario().init_from_attributes( period=month, input_variables={ # 'choice': [1, 1, 1, 2], 'choice': np.random.randint(2, size=1000) + 1, }, ) def test_switch(): simulation = scenario.new_simulation(debug=True) uses_switch = simulation.calculate('uses_switch', period=month) assert isinstance(uses_switch, np.ndarray) def test_multiplication(): simulation = scenario.new_simulation(debug=True) uses_multiplication = simulation.calculate('uses_multiplication', period=month)
entity = Person base_function = requested_period_last_value definition_period = MONTH def formula(self, simulation, period, choice): return self.zeros() + choice # TaxBenefitSystem instance declared after formulas tax_benefit_system = CountryTaxBenefitSystem() tax_benefit_system.add_variables(formula_1, formula_2, formula_3, formula_4) reference_period = periods.period(u'2013-01') simulation = tax_benefit_system.new_scenario().init_from_attributes( period = reference_period.first_month, ).new_simulation(debug = True) formula_1_result = simulation.calculate('formula_1', period = reference_period) formula_2_result = simulation.calculate('formula_2', period = reference_period) formula_3_holder = simulation.person.get_holder('formula_3') def test_cache(): assert_near(formula_1_result, [0]) assert_near(formula_2_result, [1]) def test_get_extra_param_names(): assert formula_3_holder.get_extra_param_names(reference_period) == ('choice',)
# -*- coding: utf-8 -*- from openfisca_country_template import CountryTaxBenefitSystem from openfisca_core.formulas import Formula from openfisca_core.simulations import Simulation tax_benefit_system = CountryTaxBenefitSystem() scenario = tax_benefit_system.new_scenario().init_from_attributes( period=2014 ) def test_calculate_with_trace(): simulation = scenario.new_simulation(trace=True) simulation.calculate('disposable_income', "2014-01") def test_calculate__holder_attribute_content(): simulation = scenario.new_simulation() variable_name = 'disposable_income' period = "2014-01" simulation.calculate(variable_name, period) # numpy.ndarray simulation_holder = simulation.person.get_holder(variable_name) assert issubclass(simulation_holder.formula.__class__, Formula) assert len(simulation_holder.formula.dated_formulas) > 0 # contains formulas instances def test_clone():