def new_simulation(self, debug=False, opt_out_cache=False, use_baseline=False, trace=False): # Legacy from scenarios, used in reforms tax_benefit_system = self.tax_benefit_system if use_baseline: while True: baseline = tax_benefit_system.baseline if baseline is None: break tax_benefit_system = baseline builder = SimulationBuilder() if self.attributes: variables = self.attributes.get('input_variables') or {} period = self.attributes.get('period') builder.set_default_period(period) simulation = builder.build_from_variables( tax_benefit_system, variables) else: builder.set_default_period(self.period) simulation = builder.build_from_entities( tax_benefit_system, self.dict) simulation.trace = trace simulation.debug = debug simulation.opt_out_cache = opt_out_cache return simulation
def test_add_person_values_with_default_period_old_syntax(persons): persons_json = {'Alicia': {'salary': 3000}, 'Javier': {}} simulation_builder = SimulationBuilder() simulation_builder.set_default_period('month:2018-11') simulation_builder.add_person_entity(persons, persons_json) tools.assert_near(simulation_builder.get_input('salary', '2018-11'), [3000, 0])
def test_input_with_wrong_period(tax_benefit_system): year = str(PERIOD.this_year) variables = {"basic_income": {year: 12000}} simulation_builder = SimulationBuilder() simulation_builder.set_default_period(PERIOD) with pytest.raises(ValueError): simulation_builder.build_from_variables(tax_benefit_system, variables)
def test_add_axis_without_period(persons): simulation_builder = SimulationBuilder() simulation_builder.set_default_period('2018-11') simulation_builder.add_person_entity(persons, {'Alicia': {}}) simulation_builder.register_variable('salary', persons) simulation_builder.add_parallel_axis({'count': 3, 'name': 'salary', 'min': 0, 'max': 3000}) simulation_builder.expand_axes() assert simulation_builder.get_input('salary', '2018-11') == pytest.approx([0, 1500, 3000])
def new_simulation(tax_benefit_system, test_case, period = MONTH): simulation_builder = SimulationBuilder() simulation_builder.set_default_period(period) return simulation_builder.build_from_entities(tax_benefit_system, test_case)