66
77from openfisca_core import periods
88from openfisca_core .periods import Instant
9- from openfisca_core .simulation_builder import SimulationBuilder
109from openfisca_core .tools import assert_near
1110from openfisca_core .parameters import ValuesHistory , ParameterNode
1211from openfisca_country_template .entities import Household , Person
1312from openfisca_core .model_api import * # noqa analysis:ignore
14- from openfisca_country_template import CountryTaxBenefitSystem
15- tax_benefit_system = CountryTaxBenefitSystem ()
1613
1714
1815@fixture
19- def make_simulation ():
16+ def make_simulation (simulation_builder ):
2017 def _make_simulation (tbs , period , data ):
21- builder = SimulationBuilder ()
22- builder .default_period = period
23- return builder .build_from_variables (tbs , data )
18+ simulation_builder .default_period = period
19+ return simulation_builder .build_from_variables (tbs , data )
2420 return _make_simulation
2521
2622
27- class goes_to_school (Variable ):
28- value_type = bool
29- default_value = True
30- entity = Person
31- label = "The person goes to school (only relevant for children)"
32- definition_period = MONTH
33-
34-
35- tax_benefit_system .add_variable (goes_to_school )
36-
37-
3823class WithBasicIncomeNeutralized (Reform ):
3924 def apply (self ):
4025 self .neutralize_variable ('basic_income' )
4126
4227
43- def test_formula_neutralization (make_simulation ):
28+ def test_formula_neutralization (tax_benefit_system , make_simulation ):
4429 reform = WithBasicIncomeNeutralized (tax_benefit_system )
4530
4631 period = '2017-01'
@@ -61,21 +46,31 @@ def test_formula_neutralization(make_simulation):
6146 assert_near (disposable_income_reform , 0 )
6247
6348
64- def test_neutralization_variable_with_default_value (make_simulation ):
49+ def test_neutralization_variable_with_default_value (tax_benefit_system , make_simulation ):
50+
51+ class goes_to_school (Variable ):
52+ value_type = bool
53+ default_value = True
54+ entity = Person
55+ label = "The person goes to school (only relevant for children)"
56+ definition_period = MONTH
57+
6558 class test_goes_to_school_neutralization (Reform ):
6659 def apply (self ):
6760 self .neutralize_variable ('goes_to_school' )
6861
62+ tax_benefit_system .add_variable (goes_to_school )
63+
6964 reform = test_goes_to_school_neutralization (tax_benefit_system )
7065
7166 period = "2017-01"
7267 simulation = make_simulation (reform .base_tax_benefit_system , period , {})
7368
74- goes_to_school = simulation .calculate ('goes_to_school' , period )
75- assert_near (goes_to_school , [True ], absolute_error_margin = 0 )
69+ goes_to_school_result = simulation .calculate ('goes_to_school' , period )
70+ assert_near (goes_to_school_result , [True ], absolute_error_margin = 0 )
7671
7772
78- def test_neutralization_optimization (make_simulation ):
73+ def test_neutralization_optimization (tax_benefit_system , make_simulation ):
7974 reform = WithBasicIncomeNeutralized (tax_benefit_system )
8075
8176 period = '2017-01'
@@ -90,7 +85,7 @@ def test_neutralization_optimization(make_simulation):
9085 assert basic_income_holder .get_known_periods () == []
9186
9287
93- def test_input_variable_neutralization (make_simulation ):
88+ def test_input_variable_neutralization (tax_benefit_system , make_simulation ):
9489
9590 class test_salary_neutralization (Reform ):
9691 def apply (self ):
@@ -111,7 +106,7 @@ def apply(self):
111106 assert_near (disposable_income_reform , [600 , 600 ])
112107
113108
114- def test_permanent_variable_neutralization (make_simulation ):
109+ def test_permanent_variable_neutralization (tax_benefit_system , make_simulation ):
115110
116111 class test_date_naissance_neutralization (Reform ):
117112 def apply (self ):
@@ -223,7 +218,7 @@ def check_update_items(description, value_history, start_instant, stop_instant,
223218 )
224219
225220
226- def test_add_variable (make_simulation ):
221+ def test_add_variable (tax_benefit_system , make_simulation ):
227222 class new_variable (Variable ):
228223 value_type = int
229224 label = "Nouvelle variable introduite par la réforme"
@@ -247,7 +242,7 @@ def apply(self):
247242 assert_near (new_variable1 , 10 , absolute_error_margin = 0 )
248243
249244
250- def test_add_dated_variable (make_simulation ):
245+ def test_add_dated_variable (tax_benefit_system , make_simulation ):
251246 class new_dated_variable (Variable ):
252247 value_type = int
253248 label = "Nouvelle variable introduite par la réforme"
@@ -272,7 +267,7 @@ def apply(self):
272267 assert_near (new_dated_variable1 , 15 , absolute_error_margin = 0 )
273268
274269
275- def test_update_variable (make_simulation ):
270+ def test_update_variable (tax_benefit_system , make_simulation ):
276271
277272 class disposable_income (Variable ):
278273 definition_period = MONTH
@@ -303,7 +298,7 @@ def apply(self):
303298 assert (disposable_income2 > 100 )
304299
305300
306- def test_replace_variable ():
301+ def test_replace_variable (tax_benefit_system ):
307302
308303 class disposable_income (Variable ):
309304 definition_period = MONTH
@@ -324,7 +319,7 @@ def apply(self):
324319 assert disposable_income_reform .get_formula ('2017' ) is None
325320
326321
327- def test_wrong_reform ():
322+ def test_wrong_reform (tax_benefit_system ):
328323 class wrong_reform (Reform ):
329324 # A Reform must implement an `apply` method
330325 pass
@@ -333,7 +328,7 @@ class wrong_reform(Reform):
333328 wrong_reform (tax_benefit_system )
334329
335330
336- def test_modify_parameters ():
331+ def test_modify_parameters (tax_benefit_system ):
337332
338333 def modify_parameters (reference_parameters ):
339334 reform_parameters_subtree = ParameterNode (
@@ -361,7 +356,7 @@ def apply(self):
361356 assert parameters_at_instant .new_node .new_param is True
362357
363358
364- def test_attributes_conservation ():
359+ def test_attributes_conservation (tax_benefit_system ):
365360
366361 class some_variable (Variable ):
367362 value_type = int
@@ -391,7 +386,7 @@ def apply(self):
391386 assert reform_variable .calculate_output == baseline_variable .calculate_output
392387
393388
394- def test_formulas_removal ():
389+ def test_formulas_removal (tax_benefit_system ):
395390 class reform (Reform ):
396391 def apply (self ):
397392
0 commit comments