OpenFisca-Core-test 46.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openfisca_core/__init__.py +0 -0
- openfisca_core/commons/__init__.py +18 -0
- openfisca_core/commons/dummy.py +25 -0
- openfisca_core/commons/formulas.py +121 -0
- openfisca_core/commons/misc.py +109 -0
- openfisca_core/commons/py.typed +0 -0
- openfisca_core/commons/rates.py +114 -0
- openfisca_core/commons/tests/__init__.py +0 -0
- openfisca_core/commons/tests/test_dummy.py +9 -0
- openfisca_core/commons/tests/test_formulas.py +75 -0
- openfisca_core/commons/tests/test_rates.py +26 -0
- openfisca_core/data_storage/__init__.py +7 -0
- openfisca_core/data_storage/in_memory_storage.py +198 -0
- openfisca_core/data_storage/on_disk_storage.py +307 -0
- openfisca_core/data_storage/types.py +14 -0
- openfisca_core/entities/__init__.py +23 -0
- openfisca_core/entities/_core_entity.py +217 -0
- openfisca_core/entities/_description.py +55 -0
- openfisca_core/entities/entity.py +60 -0
- openfisca_core/entities/group_entity.py +123 -0
- openfisca_core/entities/helpers.py +165 -0
- openfisca_core/entities/py.typed +0 -0
- openfisca_core/entities/role.py +92 -0
- openfisca_core/entities/tests/__init__.py +0 -0
- openfisca_core/entities/tests/test_entity.py +10 -0
- openfisca_core/entities/tests/test_group_entity.py +70 -0
- openfisca_core/entities/tests/test_role.py +11 -0
- openfisca_core/entities/types.py +44 -0
- openfisca_core/errors/__init__.py +64 -0
- openfisca_core/errors/cycle_error.py +2 -0
- openfisca_core/errors/empty_argument_error.py +39 -0
- openfisca_core/errors/nan_creation_error.py +2 -0
- openfisca_core/errors/parameter_not_found_error.py +16 -0
- openfisca_core/errors/parameter_parsing_error.py +18 -0
- openfisca_core/errors/period_mismatch_error.py +9 -0
- openfisca_core/errors/situation_parsing_error.py +26 -0
- openfisca_core/errors/spiral_error.py +2 -0
- openfisca_core/errors/variable_name_config_error.py +2 -0
- openfisca_core/errors/variable_not_found_error.py +29 -0
- openfisca_core/experimental/__init__.py +9 -0
- openfisca_core/experimental/_errors.py +5 -0
- openfisca_core/experimental/_memory_config.py +41 -0
- openfisca_core/formula_helpers.py +9 -0
- openfisca_core/holders/__init__.py +33 -0
- openfisca_core/holders/helpers.py +93 -0
- openfisca_core/holders/holder.py +328 -0
- openfisca_core/holders/tests/__init__.py +0 -0
- openfisca_core/holders/tests/test_helpers.py +134 -0
- openfisca_core/holders/types.py +3 -0
- openfisca_core/indexed_enums/__init__.py +18 -0
- openfisca_core/indexed_enums/_enum_type.py +79 -0
- openfisca_core/indexed_enums/_errors.py +35 -0
- openfisca_core/indexed_enums/_guards.py +209 -0
- openfisca_core/indexed_enums/_utils.py +180 -0
- openfisca_core/indexed_enums/config.py +6 -0
- openfisca_core/indexed_enums/enum.py +218 -0
- openfisca_core/indexed_enums/enum_array.py +316 -0
- openfisca_core/indexed_enums/py.typed +0 -0
- openfisca_core/indexed_enums/tests/__init__.py +0 -0
- openfisca_core/indexed_enums/tests/test_enum.py +135 -0
- openfisca_core/indexed_enums/tests/test_enum_array.py +30 -0
- openfisca_core/indexed_enums/types.py +49 -0
- openfisca_core/memory_config.py +9 -0
- openfisca_core/model_api.py +71 -0
- openfisca_core/parameters/__init__.py +71 -0
- openfisca_core/parameters/at_instant_like.py +17 -0
- openfisca_core/parameters/config.py +55 -0
- openfisca_core/parameters/helpers.py +106 -0
- openfisca_core/parameters/parameter.py +217 -0
- openfisca_core/parameters/parameter_at_instant.py +75 -0
- openfisca_core/parameters/parameter_node.py +176 -0
- openfisca_core/parameters/parameter_node_at_instant.py +57 -0
- openfisca_core/parameters/parameter_scale.py +121 -0
- openfisca_core/parameters/parameter_scale_bracket.py +7 -0
- openfisca_core/parameters/values_history.py +5 -0
- openfisca_core/parameters/vectorial_parameter_node_at_instant.py +179 -0
- openfisca_core/periods/__init__.py +77 -0
- openfisca_core/periods/_errors.py +28 -0
- openfisca_core/periods/_parsers.py +122 -0
- openfisca_core/periods/config.py +20 -0
- openfisca_core/periods/date_unit.py +110 -0
- openfisca_core/periods/helpers.py +314 -0
- openfisca_core/periods/instant_.py +226 -0
- openfisca_core/periods/period_.py +919 -0
- openfisca_core/periods/py.typed +0 -0
- openfisca_core/periods/tests/__init__.py +0 -0
- openfisca_core/periods/tests/helpers/__init__.py +0 -0
- openfisca_core/periods/tests/helpers/test_helpers.py +65 -0
- openfisca_core/periods/tests/helpers/test_instant.py +73 -0
- openfisca_core/periods/tests/helpers/test_period.py +134 -0
- openfisca_core/periods/tests/test_instant.py +32 -0
- openfisca_core/periods/tests/test_parsers.py +129 -0
- openfisca_core/periods/tests/test_period.py +283 -0
- openfisca_core/populations/__init__.py +64 -0
- openfisca_core/populations/_core_population.py +454 -0
- openfisca_core/populations/_errors.py +65 -0
- openfisca_core/populations/group_population.py +326 -0
- openfisca_core/populations/population.py +142 -0
- openfisca_core/populations/tests/__init__.py +0 -0
- openfisca_core/populations/tests/test_members_position.py +116 -0
- openfisca_core/populations/types.py +110 -0
- openfisca_core/projectors/__init__.py +39 -0
- openfisca_core/projectors/entity_to_person_projector.py +12 -0
- openfisca_core/projectors/first_person_to_entity_projector.py +13 -0
- openfisca_core/projectors/helpers.py +139 -0
- openfisca_core/projectors/projector.py +38 -0
- openfisca_core/projectors/typing.py +27 -0
- openfisca_core/projectors/unique_role_to_entity_projector.py +14 -0
- openfisca_core/rates.py +9 -0
- openfisca_core/reforms/__init__.py +24 -0
- openfisca_core/reforms/in_yaml_test_reform.py +28 -0
- openfisca_core/reforms/reform.py +86 -0
- openfisca_core/scripts/__init__.py +106 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.3.3.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-310.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.3.3.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-312-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.3.3.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/find_placeholders.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/find_placeholders.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-310.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-312.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-310.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-312.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/simulation_generator.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/simulation_generator.cpython-313.pyc +0 -0
- openfisca_core/scripts/assets/__init__.py +0 -0
- openfisca_core/scripts/assets/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/assets/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/assets/index.html +140 -0
- openfisca_core/scripts/find_placeholders.py +51 -0
- openfisca_core/scripts/measure_numpy_condition_notations.py +137 -0
- openfisca_core/scripts/measure_performances.py +291 -0
- openfisca_core/scripts/measure_performances_fancy_indexing.py +89 -0
- openfisca_core/scripts/migrations/__init__.py +0 -0
- openfisca_core/scripts/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__init__.py +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/legislation.xsd +102 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_country_template.py +30 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_extension_template.py +26 -0
- openfisca_core/scripts/migrations/v24_to_25.py +156 -0
- openfisca_core/scripts/openfisca_command.py +192 -0
- openfisca_core/scripts/remove_fuzzy.py +213 -0
- openfisca_core/scripts/run_test.py +51 -0
- openfisca_core/scripts/simulation_generator.py +90 -0
- openfisca_core/simulation_builder.py +16 -0
- openfisca_core/simulations/__init__.py +45 -0
- openfisca_core/simulations/_build_default_simulation.py +158 -0
- openfisca_core/simulations/_build_from_variables.py +230 -0
- openfisca_core/simulations/_type_guards.py +298 -0
- openfisca_core/simulations/helpers.py +111 -0
- openfisca_core/simulations/simulation.py +618 -0
- openfisca_core/simulations/simulation_builder.py +855 -0
- openfisca_core/simulations/typing.py +203 -0
- openfisca_core/taxbenefitsystems/__init__.py +26 -0
- openfisca_core/taxbenefitsystems/tax_benefit_system.py +584 -0
- openfisca_core/taxscales/__init__.py +35 -0
- openfisca_core/taxscales/abstract_rate_tax_scale.py +41 -0
- openfisca_core/taxscales/abstract_tax_scale.py +53 -0
- openfisca_core/taxscales/amount_tax_scale_like.py +55 -0
- openfisca_core/taxscales/helpers.py +44 -0
- openfisca_core/taxscales/linear_average_rate_tax_scale.py +76 -0
- openfisca_core/taxscales/marginal_amount_tax_scale.py +34 -0
- openfisca_core/taxscales/marginal_rate_tax_scale.py +286 -0
- openfisca_core/taxscales/rate_tax_scale_like.py +214 -0
- openfisca_core/taxscales/single_amount_tax_scale.py +32 -0
- openfisca_core/taxscales/tax_scale_like.py +65 -0
- openfisca_core/tools/__init__.py +94 -0
- openfisca_core/tools/parallel_plugin.py +55 -0
- openfisca_core/tools/simulation_dumper.py +137 -0
- openfisca_core/tools/test_runner.py +802 -0
- openfisca_core/tracers/__init__.py +40 -0
- openfisca_core/tracers/computation_log.py +196 -0
- openfisca_core/tracers/flat_trace.py +87 -0
- openfisca_core/tracers/full_tracer.py +172 -0
- openfisca_core/tracers/performance_log.py +133 -0
- openfisca_core/tracers/simple_tracer.py +64 -0
- openfisca_core/tracers/trace_node.py +121 -0
- openfisca_core/tracers/tracing_parameter_node_at_instant.py +81 -0
- openfisca_core/types.py +548 -0
- openfisca_core/variables/__init__.py +26 -0
- openfisca_core/variables/config.py +53 -0
- openfisca_core/variables/helpers.py +67 -0
- openfisca_core/variables/tests/__init__.py +0 -0
- openfisca_core/variables/tests/test_definition_period.py +43 -0
- openfisca_core/variables/variable.py +474 -0
- openfisca_core/warnings/__init__.py +25 -0
- openfisca_core/warnings/libyaml_warning.py +2 -0
- openfisca_core/warnings/tempfile_warning.py +2 -0
- openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/CHANGELOG.md +4209 -0
- openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/README.md +152 -0
- openfisca_core_test-46.0.0.dist-info/METADATA +194 -0
- openfisca_core_test-46.0.0.dist-info/RECORD +237 -0
- openfisca_core_test-46.0.0.dist-info/WHEEL +5 -0
- openfisca_core_test-46.0.0.dist-info/entry_points.txt +3 -0
- openfisca_core_test-46.0.0.dist-info/licenses/LICENSE +661 -0
- openfisca_core_test-46.0.0.dist-info/top_level.txt +2 -0
- openfisca_web_api/__init__.py +0 -0
- openfisca_web_api/app.py +226 -0
- openfisca_web_api/errors.py +11 -0
- openfisca_web_api/handlers.py +90 -0
- openfisca_web_api/loader/__init__.py +22 -0
- openfisca_web_api/loader/entities.py +28 -0
- openfisca_web_api/loader/parameters.py +122 -0
- openfisca_web_api/loader/spec.py +168 -0
- openfisca_web_api/loader/tax_benefit_system.py +27 -0
- openfisca_web_api/loader/variables.py +121 -0
- openfisca_web_api/openAPI.yml +434 -0
- openfisca_web_api/scripts/__init__.py +0 -0
- openfisca_web_api/scripts/serve.py +99 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from openfisca_core.periods import DateUnit, Instant, Period
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize(
|
|
7
|
+
("date_unit", "instant", "size", "expected"),
|
|
8
|
+
[
|
|
9
|
+
(DateUnit.YEAR, Instant((2022, 1, 1)), 1, "2022"),
|
|
10
|
+
(DateUnit.MONTH, Instant((2022, 1, 1)), 12, "2022"),
|
|
11
|
+
(DateUnit.YEAR, Instant((2022, 3, 1)), 1, "year:2022-03"),
|
|
12
|
+
(DateUnit.MONTH, Instant((2022, 3, 1)), 12, "year:2022-03"),
|
|
13
|
+
(DateUnit.YEAR, Instant((2022, 1, 1)), 3, "year:2022:3"),
|
|
14
|
+
(DateUnit.YEAR, Instant((2022, 1, 3)), 3, "year:2022:3"),
|
|
15
|
+
],
|
|
16
|
+
)
|
|
17
|
+
def test_str_with_years(date_unit, instant, size, expected) -> None:
|
|
18
|
+
assert str(Period((date_unit, instant, size))) == expected
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.mark.parametrize(
|
|
22
|
+
("date_unit", "instant", "size", "expected"),
|
|
23
|
+
[
|
|
24
|
+
(DateUnit.MONTH, Instant((2022, 1, 1)), 1, "2022-01"),
|
|
25
|
+
(DateUnit.MONTH, Instant((2022, 1, 1)), 3, "month:2022-01:3"),
|
|
26
|
+
(DateUnit.MONTH, Instant((2022, 3, 1)), 3, "month:2022-03:3"),
|
|
27
|
+
],
|
|
28
|
+
)
|
|
29
|
+
def test_str_with_months(date_unit, instant, size, expected) -> None:
|
|
30
|
+
assert str(Period((date_unit, instant, size))) == expected
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize(
|
|
34
|
+
("date_unit", "instant", "size", "expected"),
|
|
35
|
+
[
|
|
36
|
+
(DateUnit.DAY, Instant((2022, 1, 1)), 1, "2022-01-01"),
|
|
37
|
+
(DateUnit.DAY, Instant((2022, 1, 1)), 3, "day:2022-01-01:3"),
|
|
38
|
+
(DateUnit.DAY, Instant((2022, 3, 1)), 3, "day:2022-03-01:3"),
|
|
39
|
+
],
|
|
40
|
+
)
|
|
41
|
+
def test_str_with_days(date_unit, instant, size, expected) -> None:
|
|
42
|
+
assert str(Period((date_unit, instant, size))) == expected
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@pytest.mark.parametrize(
|
|
46
|
+
("date_unit", "instant", "size", "expected"),
|
|
47
|
+
[
|
|
48
|
+
(DateUnit.WEEK, Instant((2022, 1, 1)), 1, "2021-W52"),
|
|
49
|
+
(DateUnit.WEEK, Instant((2022, 1, 1)), 3, "week:2021-W52:3"),
|
|
50
|
+
(DateUnit.WEEK, Instant((2022, 3, 1)), 1, "2022-W09"),
|
|
51
|
+
(DateUnit.WEEK, Instant((2022, 3, 1)), 3, "week:2022-W09:3"),
|
|
52
|
+
],
|
|
53
|
+
)
|
|
54
|
+
def test_str_with_weeks(date_unit, instant, size, expected) -> None:
|
|
55
|
+
assert str(Period((date_unit, instant, size))) == expected
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.mark.parametrize(
|
|
59
|
+
("date_unit", "instant", "size", "expected"),
|
|
60
|
+
[
|
|
61
|
+
(DateUnit.WEEKDAY, Instant((2022, 1, 1)), 1, "2021-W52-6"),
|
|
62
|
+
(DateUnit.WEEKDAY, Instant((2022, 1, 1)), 3, "weekday:2021-W52-6:3"),
|
|
63
|
+
(DateUnit.WEEKDAY, Instant((2022, 3, 1)), 1, "2022-W09-2"),
|
|
64
|
+
(DateUnit.WEEKDAY, Instant((2022, 3, 1)), 3, "weekday:2022-W09-2:3"),
|
|
65
|
+
],
|
|
66
|
+
)
|
|
67
|
+
def test_str_with_weekdays(date_unit, instant, size, expected) -> None:
|
|
68
|
+
assert str(Period((date_unit, instant, size))) == expected
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@pytest.mark.parametrize(
|
|
72
|
+
("date_unit", "instant", "size", "expected"),
|
|
73
|
+
[
|
|
74
|
+
(DateUnit.YEAR, Instant((2022, 12, 1)), 1, 1),
|
|
75
|
+
(DateUnit.YEAR, Instant((2022, 1, 1)), 2, 2),
|
|
76
|
+
],
|
|
77
|
+
)
|
|
78
|
+
def test_size_in_years(date_unit, instant, size, expected) -> None:
|
|
79
|
+
period = Period((date_unit, instant, size))
|
|
80
|
+
assert period.size_in_years == expected
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.mark.parametrize(
|
|
84
|
+
("date_unit", "instant", "size", "expected"),
|
|
85
|
+
[
|
|
86
|
+
(DateUnit.YEAR, Instant((2020, 1, 1)), 1, 12),
|
|
87
|
+
(DateUnit.YEAR, Instant((2022, 1, 1)), 2, 24),
|
|
88
|
+
(DateUnit.MONTH, Instant((2012, 1, 3)), 3, 3),
|
|
89
|
+
],
|
|
90
|
+
)
|
|
91
|
+
def test_size_in_months(date_unit, instant, size, expected) -> None:
|
|
92
|
+
period = Period((date_unit, instant, size))
|
|
93
|
+
assert period.size_in_months == expected
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@pytest.mark.parametrize(
|
|
97
|
+
("date_unit", "instant", "size", "expected"),
|
|
98
|
+
[
|
|
99
|
+
(DateUnit.YEAR, Instant((2022, 12, 1)), 1, 365),
|
|
100
|
+
(DateUnit.YEAR, Instant((2020, 1, 1)), 1, 366),
|
|
101
|
+
(DateUnit.YEAR, Instant((2022, 1, 1)), 2, 730),
|
|
102
|
+
(DateUnit.MONTH, Instant((2022, 12, 1)), 1, 31),
|
|
103
|
+
(DateUnit.MONTH, Instant((2020, 2, 3)), 1, 29),
|
|
104
|
+
(DateUnit.MONTH, Instant((2022, 1, 3)), 3, 31 + 28 + 31),
|
|
105
|
+
(DateUnit.MONTH, Instant((2012, 1, 3)), 3, 31 + 29 + 31),
|
|
106
|
+
(DateUnit.DAY, Instant((2022, 12, 31)), 1, 1),
|
|
107
|
+
(DateUnit.DAY, Instant((2022, 12, 31)), 3, 3),
|
|
108
|
+
(DateUnit.WEEK, Instant((2022, 12, 31)), 1, 7),
|
|
109
|
+
(DateUnit.WEEK, Instant((2022, 12, 31)), 3, 21),
|
|
110
|
+
(DateUnit.WEEKDAY, Instant((2022, 12, 31)), 1, 1),
|
|
111
|
+
(DateUnit.WEEKDAY, Instant((2022, 12, 31)), 3, 3),
|
|
112
|
+
],
|
|
113
|
+
)
|
|
114
|
+
def test_size_in_days(date_unit, instant, size, expected) -> None:
|
|
115
|
+
period = Period((date_unit, instant, size))
|
|
116
|
+
assert period.size_in_days == expected
|
|
117
|
+
assert period.size_in_days == period.days
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@pytest.mark.parametrize(
|
|
121
|
+
("date_unit", "instant", "size", "expected"),
|
|
122
|
+
[
|
|
123
|
+
(DateUnit.YEAR, Instant((2022, 12, 1)), 1, 52),
|
|
124
|
+
(DateUnit.YEAR, Instant((2020, 1, 1)), 5, 261),
|
|
125
|
+
(DateUnit.MONTH, Instant((2022, 12, 1)), 1, 4),
|
|
126
|
+
(DateUnit.MONTH, Instant((2020, 2, 3)), 1, 4),
|
|
127
|
+
(DateUnit.MONTH, Instant((2022, 1, 3)), 3, 12),
|
|
128
|
+
(DateUnit.MONTH, Instant((2012, 1, 3)), 3, 13),
|
|
129
|
+
(DateUnit.WEEK, Instant((2022, 12, 31)), 1, 1),
|
|
130
|
+
(DateUnit.WEEK, Instant((2022, 12, 31)), 3, 3),
|
|
131
|
+
],
|
|
132
|
+
)
|
|
133
|
+
def test_size_in_weeks(date_unit, instant, size, expected) -> None:
|
|
134
|
+
period = Period((date_unit, instant, size))
|
|
135
|
+
assert period.size_in_weeks == expected
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@pytest.mark.parametrize(
|
|
139
|
+
("date_unit", "instant", "size", "expected"),
|
|
140
|
+
[
|
|
141
|
+
(DateUnit.YEAR, Instant((2022, 12, 1)), 1, 364),
|
|
142
|
+
(DateUnit.YEAR, Instant((2020, 1, 1)), 1, 364),
|
|
143
|
+
(DateUnit.YEAR, Instant((2022, 1, 1)), 2, 728),
|
|
144
|
+
(DateUnit.MONTH, Instant((2022, 12, 1)), 1, 31),
|
|
145
|
+
(DateUnit.MONTH, Instant((2020, 2, 3)), 1, 29),
|
|
146
|
+
(DateUnit.MONTH, Instant((2022, 1, 3)), 3, 31 + 28 + 31),
|
|
147
|
+
(DateUnit.MONTH, Instant((2012, 1, 3)), 3, 31 + 29 + 31),
|
|
148
|
+
(DateUnit.DAY, Instant((2022, 12, 31)), 1, 1),
|
|
149
|
+
(DateUnit.DAY, Instant((2022, 12, 31)), 3, 3),
|
|
150
|
+
(DateUnit.WEEK, Instant((2022, 12, 31)), 1, 7),
|
|
151
|
+
(DateUnit.WEEK, Instant((2022, 12, 31)), 3, 21),
|
|
152
|
+
(DateUnit.WEEKDAY, Instant((2022, 12, 31)), 1, 1),
|
|
153
|
+
(DateUnit.WEEKDAY, Instant((2022, 12, 31)), 3, 3),
|
|
154
|
+
],
|
|
155
|
+
)
|
|
156
|
+
def test_size_in_weekdays(date_unit, instant, size, expected) -> None:
|
|
157
|
+
period = Period((date_unit, instant, size))
|
|
158
|
+
assert period.size_in_weekdays == expected
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@pytest.mark.parametrize(
|
|
162
|
+
("period_unit", "sub_unit", "instant", "start", "cease", "count"),
|
|
163
|
+
[
|
|
164
|
+
(
|
|
165
|
+
DateUnit.YEAR,
|
|
166
|
+
DateUnit.YEAR,
|
|
167
|
+
Instant((2022, 12, 31)),
|
|
168
|
+
Instant((2022, 1, 1)),
|
|
169
|
+
Instant((2024, 1, 1)),
|
|
170
|
+
3,
|
|
171
|
+
),
|
|
172
|
+
(
|
|
173
|
+
DateUnit.YEAR,
|
|
174
|
+
DateUnit.MONTH,
|
|
175
|
+
Instant((2022, 12, 31)),
|
|
176
|
+
Instant((2022, 12, 1)),
|
|
177
|
+
Instant((2025, 11, 1)),
|
|
178
|
+
36,
|
|
179
|
+
),
|
|
180
|
+
(
|
|
181
|
+
DateUnit.YEAR,
|
|
182
|
+
DateUnit.DAY,
|
|
183
|
+
Instant((2022, 12, 31)),
|
|
184
|
+
Instant((2022, 12, 31)),
|
|
185
|
+
Instant((2025, 12, 30)),
|
|
186
|
+
1096,
|
|
187
|
+
),
|
|
188
|
+
(
|
|
189
|
+
DateUnit.YEAR,
|
|
190
|
+
DateUnit.WEEK,
|
|
191
|
+
Instant((2022, 12, 31)),
|
|
192
|
+
Instant((2022, 12, 26)),
|
|
193
|
+
Instant((2025, 12, 15)),
|
|
194
|
+
156,
|
|
195
|
+
),
|
|
196
|
+
(
|
|
197
|
+
DateUnit.YEAR,
|
|
198
|
+
DateUnit.WEEKDAY,
|
|
199
|
+
Instant((2022, 12, 31)),
|
|
200
|
+
Instant((2022, 12, 31)),
|
|
201
|
+
Instant((2025, 12, 26)),
|
|
202
|
+
1092,
|
|
203
|
+
),
|
|
204
|
+
(
|
|
205
|
+
DateUnit.MONTH,
|
|
206
|
+
DateUnit.MONTH,
|
|
207
|
+
Instant((2022, 12, 31)),
|
|
208
|
+
Instant((2022, 12, 1)),
|
|
209
|
+
Instant((2023, 2, 1)),
|
|
210
|
+
3,
|
|
211
|
+
),
|
|
212
|
+
(
|
|
213
|
+
DateUnit.MONTH,
|
|
214
|
+
DateUnit.DAY,
|
|
215
|
+
Instant((2022, 12, 31)),
|
|
216
|
+
Instant((2022, 12, 31)),
|
|
217
|
+
Instant((2023, 3, 30)),
|
|
218
|
+
90,
|
|
219
|
+
),
|
|
220
|
+
(
|
|
221
|
+
DateUnit.DAY,
|
|
222
|
+
DateUnit.DAY,
|
|
223
|
+
Instant((2022, 12, 31)),
|
|
224
|
+
Instant((2022, 12, 31)),
|
|
225
|
+
Instant((2023, 1, 2)),
|
|
226
|
+
3,
|
|
227
|
+
),
|
|
228
|
+
(
|
|
229
|
+
DateUnit.DAY,
|
|
230
|
+
DateUnit.WEEKDAY,
|
|
231
|
+
Instant((2022, 12, 31)),
|
|
232
|
+
Instant((2022, 12, 31)),
|
|
233
|
+
Instant((2023, 1, 2)),
|
|
234
|
+
3,
|
|
235
|
+
),
|
|
236
|
+
(
|
|
237
|
+
DateUnit.WEEK,
|
|
238
|
+
DateUnit.DAY,
|
|
239
|
+
Instant((2022, 12, 31)),
|
|
240
|
+
Instant((2022, 12, 31)),
|
|
241
|
+
Instant((2023, 1, 20)),
|
|
242
|
+
21,
|
|
243
|
+
),
|
|
244
|
+
(
|
|
245
|
+
DateUnit.WEEK,
|
|
246
|
+
DateUnit.WEEK,
|
|
247
|
+
Instant((2022, 12, 31)),
|
|
248
|
+
Instant((2022, 12, 26)),
|
|
249
|
+
Instant((2023, 1, 9)),
|
|
250
|
+
3,
|
|
251
|
+
),
|
|
252
|
+
(
|
|
253
|
+
DateUnit.WEEK,
|
|
254
|
+
DateUnit.WEEKDAY,
|
|
255
|
+
Instant((2022, 12, 31)),
|
|
256
|
+
Instant((2022, 12, 31)),
|
|
257
|
+
Instant((2023, 1, 20)),
|
|
258
|
+
21,
|
|
259
|
+
),
|
|
260
|
+
(
|
|
261
|
+
DateUnit.WEEKDAY,
|
|
262
|
+
DateUnit.DAY,
|
|
263
|
+
Instant((2022, 12, 31)),
|
|
264
|
+
Instant((2022, 12, 31)),
|
|
265
|
+
Instant((2023, 1, 2)),
|
|
266
|
+
3,
|
|
267
|
+
),
|
|
268
|
+
(
|
|
269
|
+
DateUnit.WEEKDAY,
|
|
270
|
+
DateUnit.WEEKDAY,
|
|
271
|
+
Instant((2022, 12, 31)),
|
|
272
|
+
Instant((2022, 12, 31)),
|
|
273
|
+
Instant((2023, 1, 2)),
|
|
274
|
+
3,
|
|
275
|
+
),
|
|
276
|
+
],
|
|
277
|
+
)
|
|
278
|
+
def test_subperiods(period_unit, sub_unit, instant, start, cease, count) -> None:
|
|
279
|
+
period = Period((period_unit, instant, 3))
|
|
280
|
+
subperiods = period.get_subperiods(sub_unit)
|
|
281
|
+
assert len(subperiods) == count
|
|
282
|
+
assert subperiods[0] == Period((sub_unit, start, 1))
|
|
283
|
+
assert subperiods[-1] == Period((sub_unit, cease, 1))
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Transitional imports to ensure non-breaking changes.
|
|
2
|
+
# Could be deprecated in the next major release.
|
|
3
|
+
#
|
|
4
|
+
# How imports are being used today:
|
|
5
|
+
#
|
|
6
|
+
# >>> from openfisca_core.module import symbol
|
|
7
|
+
#
|
|
8
|
+
# The previous example provokes cyclic dependency problems
|
|
9
|
+
# that prevent us from modularizing the different components
|
|
10
|
+
# of the library so to make them easier to test and to maintain.
|
|
11
|
+
#
|
|
12
|
+
# How could them be used after the next major release:
|
|
13
|
+
#
|
|
14
|
+
# >>> from openfisca_core import module
|
|
15
|
+
# >>> module.symbol()
|
|
16
|
+
#
|
|
17
|
+
# And for classes:
|
|
18
|
+
#
|
|
19
|
+
# >>> from openfisca_core.module import Symbol
|
|
20
|
+
# >>> Symbol()
|
|
21
|
+
#
|
|
22
|
+
# See: https://www.python.org/dev/peps/pep-0008/#imports
|
|
23
|
+
|
|
24
|
+
from openfisca_core.projectors import (
|
|
25
|
+
EntityToPersonProjector,
|
|
26
|
+
FirstPersonToEntityProjector,
|
|
27
|
+
Projector,
|
|
28
|
+
UniqueRoleToEntityProjector,
|
|
29
|
+
)
|
|
30
|
+
from openfisca_core.projectors.helpers import get_projector_from_shortcut, projectable
|
|
31
|
+
|
|
32
|
+
from . import types
|
|
33
|
+
from ._core_population import CorePopulation
|
|
34
|
+
from ._errors import (
|
|
35
|
+
IncompatibleOptionsError,
|
|
36
|
+
InvalidArraySizeError,
|
|
37
|
+
InvalidOptionError,
|
|
38
|
+
PeriodValidityError,
|
|
39
|
+
)
|
|
40
|
+
from .group_population import GroupPopulation
|
|
41
|
+
from .population import Population
|
|
42
|
+
|
|
43
|
+
ADD, DIVIDE = types.Option
|
|
44
|
+
SinglePopulation = Population
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"ADD",
|
|
48
|
+
"DIVIDE",
|
|
49
|
+
"CorePopulation",
|
|
50
|
+
"EntityToPersonProjector",
|
|
51
|
+
"FirstPersonToEntityProjector",
|
|
52
|
+
"GroupPopulation",
|
|
53
|
+
"IncompatibleOptionsError",
|
|
54
|
+
"InvalidArraySizeError",
|
|
55
|
+
"InvalidOptionError",
|
|
56
|
+
"PeriodValidityError",
|
|
57
|
+
"Population",
|
|
58
|
+
"Projector",
|
|
59
|
+
"SinglePopulation",
|
|
60
|
+
"UniqueRoleToEntityProjector",
|
|
61
|
+
"get_projector_from_shortcut",
|
|
62
|
+
"projectable",
|
|
63
|
+
"types",
|
|
64
|
+
]
|