|
1 | | -# -*- coding: utf-8 -*- |
| 1 | +import pytest |
2 | 2 |
|
3 | | -from pytest import fixture |
4 | | - |
5 | | -from openfisca_core.simulation_builder import SimulationBuilder |
6 | | -from openfisca_country_template import CountryTaxBenefitSystem |
7 | 3 | from openfisca_country_template.entities import Person |
8 | | -from openfisca_core.variables import Variable |
9 | | -from openfisca_core.periods import MONTH |
10 | | - |
11 | 4 |
|
12 | | -@fixture |
13 | | -def month(): |
14 | | - return '2016-05' |
| 5 | +from openfisca_core import periods |
| 6 | +from openfisca_core.periods import MONTH |
| 7 | +from openfisca_core.variables import Variable |
15 | 8 |
|
16 | 9 |
|
17 | | -@fixture |
18 | | -def make_isolated_simulation(month): |
19 | | - def _make_simulation(tbs, data): |
20 | | - builder = SimulationBuilder() |
21 | | - builder.default_period = month |
22 | | - return builder.build_from_variables(tbs, data) |
23 | | - return _make_simulation |
| 10 | +PERIOD = periods.period("2016-01") |
24 | 11 |
|
25 | 12 |
|
26 | 13 | class input(Variable): |
@@ -50,43 +37,34 @@ def formula(person, period): |
50 | 37 | return person('intermediate', period) |
51 | 38 |
|
52 | 39 |
|
53 | | -def get_filled_tbs(): |
54 | | - tax_benefit_system = CountryTaxBenefitSystem() |
| 40 | +@pytest.fixture(scope = "module", autouse = True) |
| 41 | +def add_variables_to_tax_benefit_system(tax_benefit_system): |
55 | 42 | tax_benefit_system.add_variables(input, intermediate, output) |
56 | 43 |
|
57 | | - return tax_benefit_system |
58 | | - |
59 | 44 |
|
60 | | -# TaxBenefitSystem instance declared after formulas |
| 45 | +@pytest.fixture(scope = "module", autouse = True) |
| 46 | +def add_variables_to_cache_blakclist(tax_benefit_system): |
| 47 | + tax_benefit_system.cache_blacklist = set(['intermediate']) |
61 | 48 |
|
62 | 49 |
|
63 | | -tax_benefit_system = get_filled_tbs() |
64 | | - |
65 | | - |
66 | | -tax_benefit_system.cache_blacklist = set(['intermediate']) |
67 | | - |
68 | | - |
69 | | -def test_without_cache_opt_out(make_isolated_simulation, month): |
70 | | - simulation = make_isolated_simulation(tax_benefit_system, {'input': 1}) |
71 | | - simulation.calculate('output', period = month) |
| 50 | +@pytest.mark.parametrize("simulation", [({'input': 1}, PERIOD)], indirect = True) |
| 51 | +def test_without_cache_opt_out(simulation): |
| 52 | + simulation.calculate('output', period = PERIOD) |
72 | 53 | intermediate_cache = simulation.persons.get_holder('intermediate') |
73 | | - assert(intermediate_cache.get_array(month) is not None) |
| 54 | + assert(intermediate_cache.get_array(PERIOD) is not None) |
74 | 55 |
|
75 | 56 |
|
76 | | -def test_with_cache_opt_out(make_isolated_simulation, month): |
77 | | - simulation = make_isolated_simulation(tax_benefit_system, {'input': 1}) |
| 57 | +@pytest.mark.parametrize("simulation", [({'input': 1}, PERIOD)], indirect = True) |
| 58 | +def test_with_cache_opt_out(simulation): |
78 | 59 | simulation.debug = True |
79 | 60 | simulation.opt_out_cache = True |
80 | | - simulation.calculate('output', period = month) |
| 61 | + simulation.calculate('output', period = PERIOD) |
81 | 62 | intermediate_cache = simulation.persons.get_holder('intermediate') |
82 | | - assert(intermediate_cache.get_array(month) is None) |
83 | | - |
84 | | - |
85 | | -tax_benefit_system2 = get_filled_tbs() |
| 63 | + assert(intermediate_cache.get_array(PERIOD) is None) |
86 | 64 |
|
87 | 65 |
|
88 | | -def test_with_no_blacklist(make_isolated_simulation, month): |
89 | | - simulation = make_isolated_simulation(tax_benefit_system2, {'input': 1}) |
90 | | - simulation.calculate('output', period = month) |
| 66 | +@pytest.mark.parametrize("simulation", [({'input': 1}, PERIOD)], indirect = True) |
| 67 | +def test_with_no_blacklist(simulation): |
| 68 | + simulation.calculate('output', period = PERIOD) |
91 | 69 | intermediate_cache = simulation.persons.get_holder('intermediate') |
92 | | - assert(intermediate_cache.get_array(month) is not None) |
| 70 | + assert(intermediate_cache.get_array(PERIOD) is not None) |
0 commit comments