Skip to content
Snippets Groups Projects
Commit faa1d534 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Add tests for PLF 2022.

parent b3856b95
No related branches found
No related tags found
No related merge requests found
# OpenFisca France Reforms Extractor
## _Some reforms for French OpenFisca tax-benefit system_
## Install
```sh
poetry install
```
## Tests
#### Test PLF 2022 Reform
```sh
poetry run python -m openfisca_france_reforms.plf_2022.scripts.run_test
```
\ No newline at end of file
......@@ -6,6 +6,7 @@ import os
from openfisca_core.parameters import load_parameter_file
from openfisca_core.reforms import Reform
from .aah import aah_base_ressources
......
#! /usr/bin/env python
import os
import sys
from openfisca_core.tools.test_runner import run_tests
from openfisca_france import FranceTaxBenefitSystem
from .. import Plf2022
def main():
options = {}
tax_benefit_system = FranceTaxBenefitSystem()
reform = Plf2022(tax_benefit_system)
reform_path = os.path.abspath(os.path.join("openfisca_france_reforms", "plf_2022"))
print(os.path.abspath("tests_avant_reforme"))
before_reform_paths = [
os.path.join(reform_path, relative_path)
for relative_path in ["tests_avant_reforme"]
]
tax_benefit_system_code = run_tests(
tax_benefit_system,
before_reform_paths,
options,
)
print(os.path.abspath("tests_apres_reforme"))
after_reform_paths = [
os.path.join(reform_path, relative_path)
for relative_path in ["tests_apres_reforme"]
]
reform_code = run_tests(reform, after_reform_paths, options)
sys.exit(tax_benefit_system_code if tax_benefit_system_code != 0 else reform_code)
if __name__ == "__main__":
sys.exit(main())
- name: test 1
# keywords:
# description:
period: month:2022-01
absolute_error_margin: 1
input:
individus:
Alex:
taux_incapacite:
2019: 0.8
2020: 0.8
2021: 0.8
2022: 0.8
age:
2019: 30
2020: 31
2021: 32
2022: 33
autonomie_financiere:
2019: true
2020: true
2021: true
2022: true
Sam:
salaire_de_base:
2019: 18654.96
2020: 18654.96
2021: 18654.96
2022: 18654.96
Janet: {}
famille:
enfants:
- Janet
parents:
- Alex
- Sam
foyer_fiscal:
declarants:
- Alex
- Sam
personnes_a_charge:
- Janet
menage:
conjoint: Sam
enfants:
- Janet
personne_de_reference: Alex
output:
aah:
- 863
- 0
- 0
- name: test 1
# keywords:
# description:
period: month:2022-01
absolute_error_margin: 1
input:
individus:
Alex:
taux_incapacite:
2019: 0.8
2020: 0.8
2021: 0.8
2022: 0.8
age:
2019: 30
2020: 31
2021: 32
2022: 33
autonomie_financiere:
2019: true
2020: true
2021: true
2022: true
Sam:
salaire_de_base:
2019: 18654.96
2020: 18654.96
2021: 18654.96
2022: 18654.96
Janet: {}
famille:
enfants:
- Janet
parents:
- Alex
- Sam
foyer_fiscal:
declarants:
- Alex
- Sam
personnes_a_charge:
- Janet
menage:
conjoint: Sam
enfants:
- Janet
personne_de_reference: Alex
output:
aah:
- 718
- 0
- 0
from openfisca_core.simulation_builder import SimulationBuilder
from openfisca_france import FranceTaxBenefitSystem
from plf_2022 import Plf2022
# Décrivez les entités
situation = {
"familles": {
"famille_1": {
"enfants": [
"Janet"
],
"parents": [
"Alex",
"Sam"
]
}
},
"foyers_fiscaux": {
"foyer_fiscal_1": {
"declarants": [
"Alex",
"Sam"
],
"personnes_a_charge": [
"Janet"
]
}
},
"individus": {
"Alex": {
# ajouter handicap à true ?
"taux_incapacite": {
"2019": 0.8,
"2020": 0.8,
"2021": 0.8,
"2022": 0.8,
},
"age": {
"2019": 30,
"2020": 31,
"2021": 32,
"2022": 33,
},
"autonomie_financiere": {
"2019": True,
"2020": True,
"2021": True,
"2022": True,
},
},
"Sam": {
"salaire_de_base": {
"2019": 18654.96,
"2020": 18654.96,
"2021": 18654.96,
"2022": 18654.96,
}
},
"Janet": {}
},
"menages": {
"menage_1": {
"conjoint": [
"Sam"
],
"enfants": [
"Janet"
],
"personne_de_reference": [
"Alex"
]
}
}
}
# Calculez la situation actuelle de la legislation française
legislation_france = FranceTaxBenefitSystem()
loi_actuelle = SimulationBuilder().build_from_entities(legislation_france, situation)
reforme = SimulationBuilder().build_from_entities(Plf2022(legislation_france), situation)
resultat_actuel = loi_actuelle.calculate('aah', '2022-01')
print("resultat_actuel", resultat_actuel)
resultat_reforme = reforme.calculate('aah', '2022-01')
print("resultat_reforme", resultat_reforme)
......@@ -393,7 +393,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes
[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "a01b967ddcd31882c724609f1d09836e15eac5fe1f4c4776da5d7013cd5ea744"
content-hash = "b7a00e68fbce24f35a630a788c1fd825e211e225a2effdba9063b977f5cd432d"
[metadata.files]
atomicwrites = [
......
......@@ -10,6 +10,7 @@ repository = "https://git.leximpact.dev/openfisca/openfisca-france-reforms"
[tool.poetry.dependencies]
python = "^3.7"
OpenFisca-France = "^75.1.0"
OpenFisca-Core = "^35.5.0"
[tool.poetry.dev-dependencies]
black = { version = "*", allow-prereleases = true }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment