Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pytest #150

Merged
merged 9 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.7.9 [150](https://github.com/openfisca/openfisca-france-data/pull/150)

- Replace `nosetests` (unmaintained) with `pytest`.

## 0.7.8 [151](https://github.com/openfisca/openfisca-france-data/pull/151)

- Bump openfisca-france version to 34
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ format-style:
autopep8 `git ls-files | grep "\.py$$"`

test: clean check-syntax-errors
nosetests openfisca_france_data/tests --ignore-files='(test_calibration.py|test_inflation.py|test_eipp.py|test_surveys.py|test_simulation.py|test_pivot_table.py|test_aggregates.py|test_af.py|test_al.py|test_impot_revenu.py)' --exclude-dir=openfisca_france_data/tests/erfs_fpr --exe --with-doctest
pytest --ignore=openfisca_france_data/tests/erfs_fpr

test-local: clean check-syntax-errors
nosetests openfisca_france_data/tests --ignore-files='(test_calibration.py|test_inflation.py|test_eipp.py|test_surveys.py|test_simulation.py|test_pivot_table.py|test_aggregates.py|test_af.py|test_al.py|test_impot_revenu.py)' --exe --with-doctest
pytest

archive: clean
git archive HEAD --format=zip > archive.zip
Expand Down
27 changes: 4 additions & 23 deletions openfisca_france_data/tests/test_aggregates.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# -*- coding: utf-8 -*-

import logging
import numpy as np

import pytest

from openfisca_france_data.aggregates import Aggregates
from openfisca_france_data.erfs.scenario import ErfsSurveyScenario
from openfisca_france_data.erfs_fpr.scenario import ErfsFprSurveyScenario
from openfisca_france_data.aggregates import Aggregates
from openfisca_france_data.tests import base as base_survey


log = logging.getLogger(__name__)


@pytest.mark.skip(reason = 'assert False != (None is not None)')
def test_erfs_survey_simulation(year = 2009):
survey_scenario = ErfsSurveyScenario.create(year = year)
aggregates = Aggregates(survey_scenario = survey_scenario)
aggregates.compute_aggregates()
return aggregates.base_data_frame


@pytest.mark.skip(reason = "TypeError: create() got an unexpected keyword argument 'data_year'")
def test_erfs_aggregates_reform():
'''
test aggregates value with data
Expand All @@ -31,19 +28,3 @@ def test_erfs_aggregates_reform():
base_data_frame = aggregates.compute_aggregates()

return aggregates, base_data_frame


if __name__ == '__main__':
import logging
log = logging.getLogger(__name__)
import sys
logging.basicConfig(level = logging.INFO, stream = sys.stdout)
# aggregates_data_frame, difference_data_frame,
survey_scenario = test_erfs_fpr_survey_simulation_aggregates()

aggregates = Aggregates(survey_scenario = survey_scenario)
# df = aggregates.compute_aggregates()
difference_data_frame = aggregates.compute_difference()
# return aggregates.base_data_frame, difference_data_frame, survey_scenario

# df = test_erfs_aggregates_reform()
19 changes: 7 additions & 12 deletions openfisca_france_data/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,34 @@
import pkg_resources
import os

import pytest

from openfisca_survey_manager.calibration import Calibration
from openfisca_france_data.erfs.scenario import ErfsSurveyScenario


openfisca_france_data_location = pkg_resources.get_distribution('openfisca-france-data').location
@pytest.fixture
def location():
return pkg_resources.get_distribution('openfisca-france-data').location


@pytest.mark.skip(reason = 'assert None is not None')
def test_calibration():
year = 2009
survey_scenario = ErfsSurveyScenario().create(year = year)
calibration = Calibration(survey_scenario)
calibration.parameters['method'] = 'linear'
log.info('initial_total_population: {} '.format(calibration.initial_total_population))
calibration.total_population = calibration.initial_total_population * 1.123
log.info('calibration.total_population: {} '.format(calibration.total_population))

filename = os.path.join(
openfisca_france_data_location,
location,
"openfisca_france_data",
"calibrations",
"calib_2006.csv"
)

calibration.set_inputs_margins_from_file(filename, 2006)
calibration.set_parameters('invlo', 3)
calibration.set_parameters('up', 3)
calibration.set_parameters('method', 'logit')
calibration.calibrate()


if __name__ == '__main__':
import logging
log = logging.getLogger(__name__)
import sys
logging.basicConfig(level = logging.INFO, stream = sys.stdout)
test_calibration()
23 changes: 9 additions & 14 deletions openfisca_france_data/tests/test_eipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

import os

import pytest

from openfisca_core.formulas import NaNCreationError
from openfisca_core.simulations import NaNCreationError
import openfisca_france
from openfisca_france.surveys import SurveyScenario
from openfisca_survey_manager.surveys import SurveyCollection
from openfisca_france_data.build_openfisca_survey_data.utils import id_formatter
# from openfisca_france.surveys import SurveyScenario
from openfisca_survey_manager.survey_collections import SurveyCollection
# from openfisca_france_data.build_openfisca_survey_data.utils import id_formatter


current_dir = os.path.dirname(os.path.realpath(__file__))
@pytest.fixture
def current_dir():
os.path.dirname(os.path.realpath(__file__))


def get_input_data_frame(year):
Expand Down Expand Up @@ -48,6 +51,7 @@ def filter_input_data_frame(data_frame, filter_entity = None, filter_index = Non
return data_frame


@pytest.mark.skip(reason = "configparser.NoOptionError: No option 'eipp' in section: 'collections'")
def test_survey_simulation():
year = 2011
input_data_frame = get_input_data_frame(year)
Expand Down Expand Up @@ -80,12 +84,3 @@ def test_survey_simulation():
simulation_debug.calculate(column_name)

print(revenu_disponible.info())
print('finished')


if __name__ == '__main__':
import logging
log = logging.getLogger(__name__)
import sys
logging.basicConfig(level = logging.INFO, stream = sys.stdout)
test_survey_simulation()
12 changes: 2 additions & 10 deletions openfisca_france_data/tests/test_inflation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-


import logging
import sys
import pytest

from openfisca_france_data.erfs_fpr.get_survey_scenario import get_survey_scenario
from openfisca_france_data.tests import base as base_survey


log = logging.getLogger(__name__)


@pytest.mark.skip(reason = "configparser.NoOptionError: No option 'openfisca_erfs_fpr' in section: 'collections'")
def test_inflation():
period = year = 2012
survey_scenario = get_survey_scenario(year = year, tax_benefit_system = base_survey.france_data_tax_benefit_system)
Expand All @@ -20,8 +17,3 @@ def test_inflation():
survey_scenario.inflate(target_by_variable = target_by_variable, period = period)
assert abs(survey_scenario.compute_aggregate('salaire_imposable', period = period) - 1.2e08) / 1.2e08 < 1e-6, \
"{} != {}".format(survey_scenario.compute_aggregate('salaire_imposable', period = period), 1.2e08)


if __name__ == '__main__':
logging.basicConfig(level = logging.INFO, stream = sys.stdout)
test_inflation()
19 changes: 6 additions & 13 deletions openfisca_france_data/tests/test_pivot_table.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-


import pytest

from openfisca_france_data.erfs_fpr.get_survey_scenario import get_survey_scenario as erfs_fpr_get_survey_scenario
from openfisca_france_data.erfs.scenario import ErfsSurveyScenario
from openfisca_france_data.tests import base as base_survey


@pytest.mark.skip(reason = "configparser.NoOptionError: No option 'openfisca_erfs_fpr' in section: 'collections'")
def test_pivot_table_1d_mean():
year = 2012
survey_scenario = get_survey_scenario(kind = 'erfs_fpr', year = year)
Expand All @@ -17,6 +20,7 @@ def test_pivot_table_1d_mean():
return pivot_table


@pytest.mark.skip(reason = "configparser.NoOptionError: No option 'openfisca_erfs_fpr' in section: 'collections'")
def test_pivot_table_1d_sum():
year = 2012
survey_scenario = get_survey_scenario(kind = 'erfs_fpr', year = year)
Expand All @@ -29,6 +33,7 @@ def test_pivot_table_1d_sum():
return pivot_table


@pytest.mark.skip(reason = "configparser.NoOptionError: No option 'openfisca_erfs_fpr' in section: 'collections'")
def test_pivot_table_1d_count():
year = 2012
survey_scenario = get_survey_scenario(kind = 'erfs_fpr', year = year)
Expand All @@ -41,6 +46,7 @@ def test_pivot_table_1d_count():
return pivot_table


@pytest.mark.skip(reason = "configparser.NoOptionError: No option 'openfisca_erfs_fpr' in section: 'collections'")
def test_pivot_table_2d_2values():
year = 2012
survey_scenario = get_survey_scenario(kind = 'erfs_fpr', year = year)
Expand All @@ -62,16 +68,3 @@ def get_survey_scenario(kind = 'erfs_fpr', year = None):
SurveyScenario = ErfsSurveyScenario

return SurveyScenario.create(year = year)


if __name__ == '__main__':
import logging
import time
log = logging.getLogger(__name__)
import sys
logging.basicConfig(level = logging.INFO, stream = sys.stdout)
start = time.time()
print(test_pivot_table_1d_sum())
print(test_pivot_table_1d_mean())
print(test_pivot_table_2d_2values())
print(time.time() - start)
66 changes: 32 additions & 34 deletions openfisca_france_data/tests/test_simulation.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
# -*- coding: utf-8 -*-


from openfisca_france_data.erfs.scenario import ErfsSurveyScenario
import time

import pytest

from openfisca_france_data.erfs_fpr.scenario import ErfsFprSurveyScenario
from openfisca_france_data.erfs_fpr.get_survey_scenario import get_survey_scenario

from openfisca_france_data.tests import base as base_survey


import logging


log = logging.getLogger(__name__)


variables = [
'activite',
'af_nbenf',
'af',
'age',
'aide_logement_montant_brut',
'aspa',
'autonomie_financiere',
'menage_ordinaire_individus',
'minimum_vieillesse',
'nbptr',
'pensions_alimentaires_percues',
'revenu_disponible',
'rsa_base_ressources',
'rsa',
'salaire_imposable',
'salaire_net',
'weight_familles',
]
@pytest.fixture
def variables():
[
'activite',
'af_nbenf',
'af',
'age',
'aide_logement_montant_brut',
'aspa',
'autonomie_financiere',
'menage_ordinaire_individus',
'minimum_vieillesse',
'nbptr',
'pensions_alimentaires_percues',
'revenu_disponible',
'rsa_base_ressources',
'rsa',
'salaire_imposable',
'salaire_net',
'weight_familles',
]


def loose_check(data_frame_by_entity):
Expand Down Expand Up @@ -79,6 +77,7 @@ def loose_check(data_frame_by_entity):
variable, entity)


@pytest.mark.skip(reason = "NameError: name 'reduce' is not defined")
def test_erfs_fpr_survey_simulation(year = 2012, rebuild_input_data = False):
tax_benefit_system = base_survey.get_cached_reform(
reform_key = 'inversion_directe_salaires',
Expand All @@ -98,6 +97,7 @@ def test_erfs_fpr_survey_simulation(year = 2012, rebuild_input_data = False):
return survey_scenario, data_frame_by_entity


@pytest.mark.skip(reason = "NameError: name 'reduce' is not defined")
def test_erfs_survey_simulation(year = 2009):
tax_benefit_system = base_survey.get_cached_reform(
reform_key = 'inversion_directe_salaires',
Expand All @@ -121,18 +121,16 @@ def test_erfs_survey_simulation(year = 2009):
return survey_scenario, data_frame_by_entity


@pytest.mark.skip(reason = 'assert False != (None is not None)')
def test_weights_building():
year = 2012
survey_scenario = ErfsFprSurveyScenario.create(year = year)
survey_scenario.new_simulation()
return survey_scenario.simulation


if __name__ == '__main__':
import time
log = logging.getLogger(__name__)
import sys
logging.basicConfig(level = logging.INFO, stream = sys.stdout)
@pytest.mark.skip(reason = "NameError: name 'reduce' is not defined")
def test_something():
start = time.time()
year = 2012
survey_scenario, data_frame_by_entity = test_erfs_fpr_survey_simulation(year = year)
Expand All @@ -152,8 +150,8 @@ def test_weights_building():
],
)

# data_frame_familles = data_frame_by_entity['famille']
# data_frame_foyers_fiscaux = data_frame_by_entity['foyer_fiscal']
# data_frame_familles = data_frame_by_entity['famille']
# data_frame_foyers_fiscaux = data_frame_by_entity['foyer_fiscal']
data_frame_individus = data_frame_by_entity['individu']
data_frame_individus.query('salaire_imposable_pour_inversion > 0').categorie_salarie.isin(range(7)).all()
data_frame_individus.query('salaire_imposable_pour_inversion > 0').contrat_de_travail.isin(range(2)).all()
Expand All @@ -163,7 +161,7 @@ def test_weights_building():
'(heures_remunerees_volume == 0) & (salaire_imposable_pour_inversion > 0)'
).contrat_de_travail == 0).all()

# data_frame_menages = data_frame_by_entity['menage']
# data_frame_menages = data_frame_by_entity['menage']
print(time.time() - start)

mask = data_frame_individus.query(
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ hang-closing = true
ignore = E128,E251,F403,F405,E501,W503
in-place = true

[nosetests]
exe = true
with-doctest = true
with-coverage = true
cover-package = openfisca_france_data
[tool:pytest]
addopts = --showlocals --doctest-modules --disable-pytest-warnings --cov=openfisca_france_data
testpaths = openfisca_france_data/tests
python_files = **/*.py
Loading