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
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from openfisca_core import periods
|
|
6
|
+
from openfisca_core.periods import DateUnit, Instant, Period
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.parametrize(
|
|
10
|
+
("arg", "expected"),
|
|
11
|
+
[
|
|
12
|
+
(None, None),
|
|
13
|
+
(Instant((1, 1, 1)), datetime.date(1, 1, 1)),
|
|
14
|
+
(Instant((4, 2, 29)), datetime.date(4, 2, 29)),
|
|
15
|
+
((1, 1, 1), datetime.date(1, 1, 1)),
|
|
16
|
+
],
|
|
17
|
+
)
|
|
18
|
+
def test_instant_date(arg, expected) -> None:
|
|
19
|
+
assert periods.instant_date(arg) == expected
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.parametrize(
|
|
23
|
+
("arg", "error"),
|
|
24
|
+
[
|
|
25
|
+
(Instant((-1, 1, 1)), ValueError),
|
|
26
|
+
(Instant((1, -1, 1)), ValueError),
|
|
27
|
+
(Instant((1, 13, -1)), ValueError),
|
|
28
|
+
(Instant((1, 1, -1)), ValueError),
|
|
29
|
+
(Instant((1, 1, 32)), ValueError),
|
|
30
|
+
(Instant((1, 2, 29)), ValueError),
|
|
31
|
+
(Instant(("1", 1, 1)), TypeError),
|
|
32
|
+
((1,), TypeError),
|
|
33
|
+
((1, 1), TypeError),
|
|
34
|
+
],
|
|
35
|
+
)
|
|
36
|
+
def test_instant_date_with_an_invalid_argument(arg, error) -> None:
|
|
37
|
+
with pytest.raises(error):
|
|
38
|
+
periods.instant_date(arg)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.mark.parametrize(
|
|
42
|
+
("arg", "expected"),
|
|
43
|
+
[
|
|
44
|
+
(Period((DateUnit.WEEKDAY, Instant((1, 1, 1)), 5)), "100_5"),
|
|
45
|
+
(Period((DateUnit.WEEK, Instant((1, 1, 1)), 26)), "200_26"),
|
|
46
|
+
(Period((DateUnit.DAY, Instant((1, 1, 1)), 365)), "100_365"),
|
|
47
|
+
(Period((DateUnit.MONTH, Instant((1, 1, 1)), 12)), "200_12"),
|
|
48
|
+
(Period((DateUnit.YEAR, Instant((1, 1, 1)), 2)), "300_2"),
|
|
49
|
+
(Period((DateUnit.ETERNITY, Instant((1, 1, 1)), 1)), "400_1"),
|
|
50
|
+
],
|
|
51
|
+
)
|
|
52
|
+
def test_key_period_size(arg, expected) -> None:
|
|
53
|
+
assert periods.key_period_size(arg) == expected
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@pytest.mark.parametrize(
|
|
57
|
+
("arg", "error"),
|
|
58
|
+
[
|
|
59
|
+
((DateUnit.DAY, None, 1), AttributeError),
|
|
60
|
+
((DateUnit.MONTH, None, -1000), AttributeError),
|
|
61
|
+
],
|
|
62
|
+
)
|
|
63
|
+
def test_key_period_size_when_an_invalid_argument(arg, error):
|
|
64
|
+
with pytest.raises(error):
|
|
65
|
+
periods.key_period_size(arg)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from openfisca_core import periods
|
|
6
|
+
from openfisca_core.periods import DateUnit, Instant, InstantError, Period
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.parametrize(
|
|
10
|
+
("arg", "expected"),
|
|
11
|
+
[
|
|
12
|
+
(datetime.date(1, 1, 1), Instant((1, 1, 1))),
|
|
13
|
+
(Instant((1, 1, 1)), Instant((1, 1, 1))),
|
|
14
|
+
(Period((DateUnit.DAY, Instant((1, 1, 1)), 365)), Instant((1, 1, 1))),
|
|
15
|
+
(-1, Instant((-1, 1, 1))),
|
|
16
|
+
(0, Instant((0, 1, 1))),
|
|
17
|
+
(1, Instant((1, 1, 1))),
|
|
18
|
+
(999, Instant((999, 1, 1))),
|
|
19
|
+
(1000, Instant((1000, 1, 1))),
|
|
20
|
+
("1000", Instant((1000, 1, 1))),
|
|
21
|
+
("1000-01", Instant((1000, 1, 1))),
|
|
22
|
+
("1000-01-01", Instant((1000, 1, 1))),
|
|
23
|
+
((-1,), Instant((-1, 1, 1))),
|
|
24
|
+
((-1, -1), Instant((-1, -1, 1))),
|
|
25
|
+
((-1, -1, -1), Instant((-1, -1, -1))),
|
|
26
|
+
],
|
|
27
|
+
)
|
|
28
|
+
def test_instant(arg, expected) -> None:
|
|
29
|
+
assert periods.instant(arg) == expected
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.parametrize(
|
|
33
|
+
("arg", "error"),
|
|
34
|
+
[
|
|
35
|
+
(None, InstantError),
|
|
36
|
+
(DateUnit.YEAR, ValueError),
|
|
37
|
+
(DateUnit.ETERNITY, ValueError),
|
|
38
|
+
("1000-0", ValueError),
|
|
39
|
+
("1000-0-0", ValueError),
|
|
40
|
+
("1000-1", ValueError),
|
|
41
|
+
("1000-1-1", ValueError),
|
|
42
|
+
("1", ValueError),
|
|
43
|
+
("a", ValueError),
|
|
44
|
+
("year", ValueError),
|
|
45
|
+
("eternity", ValueError),
|
|
46
|
+
("999", ValueError),
|
|
47
|
+
("1:1000-01-01", ValueError),
|
|
48
|
+
("a:1000-01-01", ValueError),
|
|
49
|
+
("year:1000-01-01", ValueError),
|
|
50
|
+
("year:1000-01-01:1", ValueError),
|
|
51
|
+
("year:1000-01-01:3", ValueError),
|
|
52
|
+
("1000-01-01:a", ValueError),
|
|
53
|
+
("1000-01-01:1", ValueError),
|
|
54
|
+
((), InstantError),
|
|
55
|
+
({}, InstantError),
|
|
56
|
+
("", InstantError),
|
|
57
|
+
((None,), InstantError),
|
|
58
|
+
((None, None), InstantError),
|
|
59
|
+
((None, None, None), InstantError),
|
|
60
|
+
((None, None, None, None), InstantError),
|
|
61
|
+
(("-1",), InstantError),
|
|
62
|
+
(("-1", "-1"), InstantError),
|
|
63
|
+
(("-1", "-1", "-1"), InstantError),
|
|
64
|
+
(("1-1",), InstantError),
|
|
65
|
+
(("1-1-1",), InstantError),
|
|
66
|
+
((datetime.date(1, 1, 1),), InstantError),
|
|
67
|
+
((Instant((1, 1, 1)),), InstantError),
|
|
68
|
+
((Period((DateUnit.DAY, Instant((1, 1, 1)), 365)),), InstantError),
|
|
69
|
+
],
|
|
70
|
+
)
|
|
71
|
+
def test_instant_with_an_invalid_argument(arg, error) -> None:
|
|
72
|
+
with pytest.raises(error):
|
|
73
|
+
periods.instant(arg)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from openfisca_core import periods
|
|
6
|
+
from openfisca_core.periods import DateUnit, Instant, Period, PeriodError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.parametrize(
|
|
10
|
+
("arg", "expected"),
|
|
11
|
+
[
|
|
12
|
+
("eternity", Period((DateUnit.ETERNITY, Instant((-1, -1, -1)), -1))),
|
|
13
|
+
("ETERNITY", Period((DateUnit.ETERNITY, Instant((-1, -1, -1)), -1))),
|
|
14
|
+
(
|
|
15
|
+
DateUnit.ETERNITY,
|
|
16
|
+
Period((DateUnit.ETERNITY, Instant((-1, -1, -1)), -1)),
|
|
17
|
+
),
|
|
18
|
+
(datetime.date(1, 1, 1), Period((DateUnit.DAY, Instant((1, 1, 1)), 1))),
|
|
19
|
+
(Instant((1, 1, 1)), Period((DateUnit.DAY, Instant((1, 1, 1)), 1))),
|
|
20
|
+
(
|
|
21
|
+
Period((DateUnit.DAY, Instant((1, 1, 1)), 365)),
|
|
22
|
+
Period((DateUnit.DAY, Instant((1, 1, 1)), 365)),
|
|
23
|
+
),
|
|
24
|
+
(-1, Period((DateUnit.YEAR, Instant((-1, 1, 1)), 1))),
|
|
25
|
+
(0, Period((DateUnit.YEAR, Instant((0, 1, 1)), 1))),
|
|
26
|
+
(1, Period((DateUnit.YEAR, Instant((1, 1, 1)), 1))),
|
|
27
|
+
(999, Period((DateUnit.YEAR, Instant((999, 1, 1)), 1))),
|
|
28
|
+
(1000, Period((DateUnit.YEAR, Instant((1000, 1, 1)), 1))),
|
|
29
|
+
("1001", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
30
|
+
("1001-01", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 1))),
|
|
31
|
+
("1001-01-01", Period((DateUnit.DAY, Instant((1001, 1, 1)), 1))),
|
|
32
|
+
("1004-02-29", Period((DateUnit.DAY, Instant((1004, 2, 29)), 1))),
|
|
33
|
+
("1001-W01", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 1))),
|
|
34
|
+
("1001-W01-1", Period((DateUnit.WEEKDAY, Instant((1000, 12, 29)), 1))),
|
|
35
|
+
("year:1001", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
36
|
+
("year:1001-01", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
37
|
+
("year:1001-01-01", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
38
|
+
("year:1001-W01", Period((DateUnit.YEAR, Instant((1000, 12, 29)), 1))),
|
|
39
|
+
("year:1001-W01-1", Period((DateUnit.YEAR, Instant((1000, 12, 29)), 1))),
|
|
40
|
+
("year:1001:1", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
41
|
+
("year:1001-01:1", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
42
|
+
("year:1001-01-01:1", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
43
|
+
("year:1001-W01:1", Period((DateUnit.YEAR, Instant((1000, 12, 29)), 1))),
|
|
44
|
+
("year:1001-W01-1:1", Period((DateUnit.YEAR, Instant((1000, 12, 29)), 1))),
|
|
45
|
+
("year:1001:3", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 3))),
|
|
46
|
+
("year:1001-01:3", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 3))),
|
|
47
|
+
("year:1001-01-01:3", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 3))),
|
|
48
|
+
("year:1001-W01:3", Period((DateUnit.YEAR, Instant((1000, 12, 29)), 3))),
|
|
49
|
+
("year:1001-W01-1:3", Period((DateUnit.YEAR, Instant((1000, 12, 29)), 3))),
|
|
50
|
+
("month:1001-01", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 1))),
|
|
51
|
+
("month:1001-01-01", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 1))),
|
|
52
|
+
("week:1001-W01", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 1))),
|
|
53
|
+
("week:1001-W01-1", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 1))),
|
|
54
|
+
("month:1001-01:1", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 1))),
|
|
55
|
+
("month:1001-01:3", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 3))),
|
|
56
|
+
("month:1001-01-01:3", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 3))),
|
|
57
|
+
("week:1001-W01:1", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 1))),
|
|
58
|
+
("week:1001-W01:3", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 3))),
|
|
59
|
+
("week:1001-W01-1:3", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 3))),
|
|
60
|
+
("day:1001-01-01", Period((DateUnit.DAY, Instant((1001, 1, 1)), 1))),
|
|
61
|
+
("day:1001-01-01:3", Period((DateUnit.DAY, Instant((1001, 1, 1)), 3))),
|
|
62
|
+
("weekday:1001-W01-1", Period((DateUnit.WEEKDAY, Instant((1000, 12, 29)), 1))),
|
|
63
|
+
(
|
|
64
|
+
"weekday:1001-W01-1:3",
|
|
65
|
+
Period((DateUnit.WEEKDAY, Instant((1000, 12, 29)), 3)),
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
|
+
def test_period(arg, expected) -> None:
|
|
70
|
+
assert periods.period(arg) == expected
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize(
|
|
74
|
+
("arg", "error"),
|
|
75
|
+
[
|
|
76
|
+
(None, PeriodError),
|
|
77
|
+
(DateUnit.YEAR, PeriodError),
|
|
78
|
+
("1", PeriodError),
|
|
79
|
+
("999", PeriodError),
|
|
80
|
+
("1000-0", PeriodError),
|
|
81
|
+
("1000-13", PeriodError),
|
|
82
|
+
("1000-W0", PeriodError),
|
|
83
|
+
("1000-W54", PeriodError),
|
|
84
|
+
("1000-0-0", PeriodError),
|
|
85
|
+
("1000-1-0", PeriodError),
|
|
86
|
+
("1000-2-31", PeriodError),
|
|
87
|
+
("1000-W0-0", PeriodError),
|
|
88
|
+
("1000-W1-0", PeriodError),
|
|
89
|
+
("1000-W1-8", PeriodError),
|
|
90
|
+
("a", PeriodError),
|
|
91
|
+
("year", PeriodError),
|
|
92
|
+
("1:1000", PeriodError),
|
|
93
|
+
("a:1000", PeriodError),
|
|
94
|
+
("month:1000", PeriodError),
|
|
95
|
+
("week:1000", PeriodError),
|
|
96
|
+
("day:1000-01", PeriodError),
|
|
97
|
+
("weekday:1000-W1", PeriodError),
|
|
98
|
+
("1000:a", PeriodError),
|
|
99
|
+
("1000:1", PeriodError),
|
|
100
|
+
("1000-01:1", PeriodError),
|
|
101
|
+
("1000-01-01:1", PeriodError),
|
|
102
|
+
("1000-W1:1", PeriodError),
|
|
103
|
+
("1000-W1-1:1", PeriodError),
|
|
104
|
+
("month:1000:1", PeriodError),
|
|
105
|
+
("week:1000:1", PeriodError),
|
|
106
|
+
("day:1000:1", PeriodError),
|
|
107
|
+
("day:1000-01:1", PeriodError),
|
|
108
|
+
("weekday:1000:1", PeriodError),
|
|
109
|
+
("weekday:1000-W1:1", PeriodError),
|
|
110
|
+
((), PeriodError),
|
|
111
|
+
({}, PeriodError),
|
|
112
|
+
("", PeriodError),
|
|
113
|
+
((None,), PeriodError),
|
|
114
|
+
((None, None), PeriodError),
|
|
115
|
+
((None, None, None), PeriodError),
|
|
116
|
+
((None, None, None, None), PeriodError),
|
|
117
|
+
((Instant((1, 1, 1)),), PeriodError),
|
|
118
|
+
((Period((DateUnit.DAY, Instant((1, 1, 1)), 365)),), PeriodError),
|
|
119
|
+
((1,), PeriodError),
|
|
120
|
+
((1, 1), PeriodError),
|
|
121
|
+
((1, 1, 1), PeriodError),
|
|
122
|
+
((-1,), PeriodError),
|
|
123
|
+
((-1, -1), PeriodError),
|
|
124
|
+
((-1, -1, -1), PeriodError),
|
|
125
|
+
(("-1",), PeriodError),
|
|
126
|
+
(("-1", "-1"), PeriodError),
|
|
127
|
+
(("-1", "-1", "-1"), PeriodError),
|
|
128
|
+
(("1-1",), PeriodError),
|
|
129
|
+
(("1-1-1",), PeriodError),
|
|
130
|
+
],
|
|
131
|
+
)
|
|
132
|
+
def test_period_with_an_invalid_argument(arg, error) -> None:
|
|
133
|
+
with pytest.raises(error):
|
|
134
|
+
periods.period(arg)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from openfisca_core.periods import DateUnit, Instant
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize(
|
|
7
|
+
("instant", "offset", "unit", "expected"),
|
|
8
|
+
[
|
|
9
|
+
(Instant((2020, 2, 29)), "first-of", DateUnit.YEAR, Instant((2020, 1, 1))),
|
|
10
|
+
(Instant((2020, 2, 29)), "first-of", DateUnit.MONTH, Instant((2020, 2, 1))),
|
|
11
|
+
(Instant((2020, 2, 29)), "first-of", DateUnit.WEEK, Instant((2020, 2, 24))),
|
|
12
|
+
(Instant((2020, 2, 29)), "first-of", DateUnit.DAY, None),
|
|
13
|
+
(Instant((2020, 2, 29)), "first-of", DateUnit.WEEKDAY, None),
|
|
14
|
+
(Instant((2020, 2, 29)), "last-of", DateUnit.YEAR, Instant((2020, 12, 31))),
|
|
15
|
+
(Instant((2020, 2, 29)), "last-of", DateUnit.MONTH, Instant((2020, 2, 29))),
|
|
16
|
+
(Instant((2020, 2, 29)), "last-of", DateUnit.WEEK, Instant((2020, 3, 1))),
|
|
17
|
+
(Instant((2020, 2, 29)), "last-of", DateUnit.DAY, None),
|
|
18
|
+
(Instant((2020, 2, 29)), "last-of", DateUnit.WEEKDAY, None),
|
|
19
|
+
(Instant((2020, 2, 29)), -3, DateUnit.YEAR, Instant((2017, 2, 28))),
|
|
20
|
+
(Instant((2020, 2, 29)), -3, DateUnit.MONTH, Instant((2019, 11, 29))),
|
|
21
|
+
(Instant((2020, 2, 29)), -3, DateUnit.WEEK, Instant((2020, 2, 8))),
|
|
22
|
+
(Instant((2020, 2, 29)), -3, DateUnit.DAY, Instant((2020, 2, 26))),
|
|
23
|
+
(Instant((2020, 2, 29)), -3, DateUnit.WEEKDAY, Instant((2020, 2, 26))),
|
|
24
|
+
(Instant((2020, 2, 29)), 3, DateUnit.YEAR, Instant((2023, 2, 28))),
|
|
25
|
+
(Instant((2020, 2, 29)), 3, DateUnit.MONTH, Instant((2020, 5, 29))),
|
|
26
|
+
(Instant((2020, 2, 29)), 3, DateUnit.WEEK, Instant((2020, 3, 21))),
|
|
27
|
+
(Instant((2020, 2, 29)), 3, DateUnit.DAY, Instant((2020, 3, 3))),
|
|
28
|
+
(Instant((2020, 2, 29)), 3, DateUnit.WEEKDAY, Instant((2020, 3, 3))),
|
|
29
|
+
],
|
|
30
|
+
)
|
|
31
|
+
def test_offset(instant, offset, unit, expected) -> None:
|
|
32
|
+
assert instant.offset(offset, unit) == expected
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from openfisca_core.periods import (
|
|
4
|
+
DateUnit,
|
|
5
|
+
Instant,
|
|
6
|
+
InstantError,
|
|
7
|
+
ParserError,
|
|
8
|
+
Period,
|
|
9
|
+
PeriodError,
|
|
10
|
+
_parsers,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.mark.parametrize(
|
|
15
|
+
("arg", "expected"),
|
|
16
|
+
[
|
|
17
|
+
("1001", Instant((1001, 1, 1))),
|
|
18
|
+
("1001-01", Instant((1001, 1, 1))),
|
|
19
|
+
("1001-12", Instant((1001, 12, 1))),
|
|
20
|
+
("1001-01-01", Instant((1001, 1, 1))),
|
|
21
|
+
("2028-02-29", Instant((2028, 2, 29))),
|
|
22
|
+
("1001-W01", Instant((1000, 12, 29))),
|
|
23
|
+
("1001-W52", Instant((1001, 12, 21))),
|
|
24
|
+
("1001-W01-1", Instant((1000, 12, 29))),
|
|
25
|
+
],
|
|
26
|
+
)
|
|
27
|
+
def test_parse_instant(arg, expected) -> None:
|
|
28
|
+
assert _parsers.parse_instant(arg) == expected
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.mark.parametrize(
|
|
32
|
+
("arg", "error"),
|
|
33
|
+
[
|
|
34
|
+
(None, InstantError),
|
|
35
|
+
({}, InstantError),
|
|
36
|
+
((), InstantError),
|
|
37
|
+
([], InstantError),
|
|
38
|
+
(1, InstantError),
|
|
39
|
+
("", InstantError),
|
|
40
|
+
("à", InstantError),
|
|
41
|
+
("1", InstantError),
|
|
42
|
+
("-1", InstantError),
|
|
43
|
+
("999", InstantError),
|
|
44
|
+
("1000-0", InstantError),
|
|
45
|
+
("1000-1", ParserError),
|
|
46
|
+
("1000-1-1", InstantError),
|
|
47
|
+
("1000-00", InstantError),
|
|
48
|
+
("1000-13", InstantError),
|
|
49
|
+
("1000-01-00", InstantError),
|
|
50
|
+
("1000-01-99", InstantError),
|
|
51
|
+
("2029-02-29", ParserError),
|
|
52
|
+
("1000-W0", InstantError),
|
|
53
|
+
("1000-W1", InstantError),
|
|
54
|
+
("1000-W99", InstantError),
|
|
55
|
+
("1000-W1-0", InstantError),
|
|
56
|
+
("1000-W1-1", InstantError),
|
|
57
|
+
("1000-W1-99", InstantError),
|
|
58
|
+
("1000-W01-0", InstantError),
|
|
59
|
+
("1000-W01-00", InstantError),
|
|
60
|
+
],
|
|
61
|
+
)
|
|
62
|
+
def test_parse_instant_with_invalid_argument(arg, error) -> None:
|
|
63
|
+
with pytest.raises(error):
|
|
64
|
+
_parsers.parse_instant(arg)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.mark.parametrize(
|
|
68
|
+
("arg", "expected"),
|
|
69
|
+
[
|
|
70
|
+
("1001", Period((DateUnit.YEAR, Instant((1001, 1, 1)), 1))),
|
|
71
|
+
("1001-01", Period((DateUnit.MONTH, Instant((1001, 1, 1)), 1))),
|
|
72
|
+
("1001-12", Period((DateUnit.MONTH, Instant((1001, 12, 1)), 1))),
|
|
73
|
+
("1001-01-01", Period((DateUnit.DAY, Instant((1001, 1, 1)), 1))),
|
|
74
|
+
("1001-W01", Period((DateUnit.WEEK, Instant((1000, 12, 29)), 1))),
|
|
75
|
+
("1001-W52", Period((DateUnit.WEEK, Instant((1001, 12, 21)), 1))),
|
|
76
|
+
("1001-W01-1", Period((DateUnit.WEEKDAY, Instant((1000, 12, 29)), 1))),
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
def test_parse_period(arg, expected) -> None:
|
|
80
|
+
assert _parsers.parse_period(arg) == expected
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.mark.parametrize(
|
|
84
|
+
("arg", "error"),
|
|
85
|
+
[
|
|
86
|
+
(None, PeriodError),
|
|
87
|
+
({}, PeriodError),
|
|
88
|
+
((), PeriodError),
|
|
89
|
+
([], PeriodError),
|
|
90
|
+
(1, PeriodError),
|
|
91
|
+
("", PeriodError),
|
|
92
|
+
("à", PeriodError),
|
|
93
|
+
("1", PeriodError),
|
|
94
|
+
("-1", PeriodError),
|
|
95
|
+
("999", PeriodError),
|
|
96
|
+
("1000-0", PeriodError),
|
|
97
|
+
("1000-1", ParserError),
|
|
98
|
+
("1000-1-1", PeriodError),
|
|
99
|
+
("1000-00", PeriodError),
|
|
100
|
+
("1000-13", PeriodError),
|
|
101
|
+
("1000-01-00", PeriodError),
|
|
102
|
+
("1000-01-99", PeriodError),
|
|
103
|
+
("1000-W0", PeriodError),
|
|
104
|
+
("1000-W1", PeriodError),
|
|
105
|
+
("1000-W99", PeriodError),
|
|
106
|
+
("1000-W1-0", PeriodError),
|
|
107
|
+
("1000-W1-1", PeriodError),
|
|
108
|
+
("1000-W1-99", PeriodError),
|
|
109
|
+
("1000-W01-0", PeriodError),
|
|
110
|
+
("1000-W01-00", PeriodError),
|
|
111
|
+
],
|
|
112
|
+
)
|
|
113
|
+
def test_parse_period_with_invalid_argument(arg, error) -> None:
|
|
114
|
+
with pytest.raises(error):
|
|
115
|
+
_parsers.parse_period(arg)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.parametrize(
|
|
119
|
+
("arg", "expected"),
|
|
120
|
+
[
|
|
121
|
+
("2022", DateUnit.YEAR),
|
|
122
|
+
("2022-01", DateUnit.MONTH),
|
|
123
|
+
("2022-01-01", DateUnit.DAY),
|
|
124
|
+
("2022-W01", DateUnit.WEEK),
|
|
125
|
+
("2022-W01-1", DateUnit.WEEKDAY),
|
|
126
|
+
],
|
|
127
|
+
)
|
|
128
|
+
def test_parse_unit(arg, expected) -> None:
|
|
129
|
+
assert _parsers.parse_unit(arg) == expected
|