Skip to content

Commit

Permalink
Remove nose
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux committed Apr 19, 2019
1 parent 767ac5c commit 029fad0
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 152 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ make test
To run all the tests defined on a test file:

```sh
nosetests core/test_parameters.py
pytest tests/core/test_parameters.py
```

To run a single test:

```sh
nosetests core/test_parameters.py:test_parameter_for_period
pytest tests/core/test_parameters.py -k test_parameter_for_period
```

## Style
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ hang-closing = true
ignore = E128,E251,F403,F405,E501,W503,W504
in-place = true

[nosetests]
where = tests
exe = true
with-doctest = true

[tool:pytest]
addopts = --showlocals --doctest-modules --disable-pytest-warnings
testpaths = tests
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
general_requirements = [
'dpath == 1.4.0',
'enum34 >= 1.1.6',
'nose < 2.0.0', # For openfisca test
'pytest >= 4.0.0, < 5.0.0', # For openfisca test
'numpy >= 1.11, < 1.16',
'psutil == 5.4.6',
'PyYAML >= 3.10',
Expand All @@ -29,7 +29,6 @@
'flake8 >= 3.7.0, < 3.8.0',
'flake8-bugbear >= 19.3.0, < 20.0.0',
'flake8-print >= 3.1.0, < 4.0.0',
'pytest >= 4.0.0, < 5.0.0',
'pytest-cov >= 2.0.0, < 3.0.0',
'openfisca-country-template >= 3.6.0rc0, < 4.0.0',
'openfisca-extension-template >= 1.2.0rc0, < 2.0.0'
Expand Down Expand Up @@ -75,5 +74,4 @@
],
},
packages = find_packages(exclude=['tests*']),
test_suite = 'nose.collector',
)
49 changes: 18 additions & 31 deletions tests/core/parameters_fancy_indexing/test_fancy_indexing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

import os
import re

import numpy as np
from nose.tools import raises, assert_in, assert_regexp_matches
import pytest


from openfisca_core.tools import assert_near
from openfisca_core.parameters import ParameterNode, Parameter, ParameterNotFound
Expand Down Expand Up @@ -55,17 +57,13 @@ def test_triple_fancy_indexing():
assert_near(P[family_status][housing_occupancy_status][zone], [100, 200, 300, 400, 500, 600, 700, 800])


@raises(ParameterNotFound)
def test_wrong_key():
zone = np.asarray(['z1', 'z2', 'z2', 'toto'])
try:
with pytest.raises(ParameterNotFound) as e:
P.single.owner[zone]
except ParameterNotFound as e:
assert_in("'rate.single.owner.toto' was not found", get_message(e))
raise
assert "'rate.single.owner.toto' was not found" in get_message(e.value)


@raises(ValueError)
def test_inhomogenous():
parameters = ParameterNode(directory_path = LOCAL_DIR)
parameters.rate.couple.owner.add_child('toto', Parameter('toto', {
Expand All @@ -78,15 +76,12 @@ def test_inhomogenous():

P = parameters.rate('2015-01-01')
housing_occupancy_status = np.asarray(['owner', 'owner', 'tenant', 'tenant'])
try:
with pytest.raises(ValueError) as error:
P.couple[housing_occupancy_status]
except ValueError as e:
assert_in("'rate.couple.owner.toto' exists", get_message(e))
assert_in("'rate.couple.tenant.toto' doesn't", get_message(e))
raise
assert "'rate.couple.owner.toto' exists" in get_message(error.value)
assert "'rate.couple.tenant.toto' doesn't" in get_message(error.value)


@raises(ValueError)
def test_inhomogenous_2():
parameters = ParameterNode(directory_path = LOCAL_DIR)
parameters.rate.couple.tenant.add_child('toto', Parameter('toto', {
Expand All @@ -99,15 +94,12 @@ def test_inhomogenous_2():

P = parameters.rate('2015-01-01')
housing_occupancy_status = np.asarray(['owner', 'owner', 'tenant', 'tenant'])
try:
with pytest.raises(ValueError) as e:
P.couple[housing_occupancy_status]
except ValueError as e:
assert_in("'rate.couple.tenant.toto' exists", get_message(e))
assert_in("'rate.couple.owner.toto' doesn't", get_message(e))
raise
assert "'rate.couple.tenant.toto' exists" in get_message(e.value)
assert "'rate.couple.owner.toto' doesn't" in get_message(e.value)


@raises(ValueError)
def test_inhomogenous_3():
parameters = ParameterNode(directory_path = LOCAL_DIR)
parameters.rate.couple.tenant.add_child('z4', ParameterNode('toto', data = {
Expand All @@ -121,12 +113,10 @@ def test_inhomogenous_3():

P = parameters.rate('2015-01-01')
zone = np.asarray(['z1', 'z2', 'z2', 'z1'])
try:
with pytest.raises(ValueError) as e:
P.couple.tenant[zone]
except ValueError as e:
assert_in("'rate.couple.tenant.z4' is a node", get_message(e))
assert_regexp_matches(get_message(e), r"'rate.couple.tenant.z(1|2|3)' is not")
raise
assert "'rate.couple.tenant.z4' is a node" in get_message(e.value)
assert re.findall(r"'rate.couple.tenant.z(1|2|3)' is not", get_message(e.value))


P_2 = parameters.local_tax('2015-01-01')
Expand All @@ -140,15 +130,12 @@ def test_with_properties_starting_by_number():
P_3 = parameters.bareme('2015-01-01')


@raises(NotImplementedError)
def test_with_bareme():
city_code = np.asarray(['75012', '75007', '75015'])
try:
P_3[city_code], [100, 300, 200]
except NotImplementedError as e:
assert_regexp_matches(get_message(e), r"'bareme.7501\d' is a 'MarginalRateTaxScale'")
assert_in("has not been implemented", get_message(e))
raise
with pytest.raises(NotImplementedError) as e:
P_3[city_code]
assert re.findall(r"'bareme.7501\d' is a 'MarginalRateTaxScale'", get_message(e.value))
assert "has not been implemented" in get_message(e.value)


def test_with_enum():
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_extensions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nose.tools import raises
import pytest

from openfisca_country_template import CountryTaxBenefitSystem

Expand All @@ -24,6 +24,6 @@ def test_access_to_parameters():
assert tbs.parameters.local_town.child_allowance.amount('2016-01') == 100.0


@raises(ValueError)
def test_failure_to_load_extension_when_directory_doesnt_exist():
original_tbs.load_extension('/this/is/not/a/real/path')
with pytest.raises(ValueError):
original_tbs.load_extension('/this/is/not/a/real/path')
10 changes: 5 additions & 5 deletions tests/core/test_formula_helpers.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# -*- coding: utf-8 -*-

import numpy
from nose.tools import raises
import pytest

from openfisca_core.formula_helpers import apply_thresholds as apply_thresholds
from openfisca_core.tools import assert_near


@raises(AssertionError)
def test_apply_thresholds_with_too_many_thresholds():
input = numpy.array([10])
thresholds = [5, 4]
choice_list = [10]
return apply_thresholds(input, thresholds, choice_list)
with pytest.raises(AssertionError):
return apply_thresholds(input, thresholds, choice_list)


@raises(AssertionError)
def test_apply_thresholds_with_too_few_thresholds():
input = numpy.array([10])
thresholds = [5]
choice_list = [10, 15, 20]
return apply_thresholds(input, thresholds, choice_list)
with pytest.raises(AssertionError):
return apply_thresholds(input, thresholds, choice_list)


def test_apply_thresholds():
Expand Down
33 changes: 12 additions & 21 deletions tests/core/test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-

from nose.tools import assert_equal, raises
import tempfile

import pytest

from openfisca_core.parameters import ParameterNotFound, ParameterNode, ParameterNodeAtInstant, load_parameter_file
from .test_countries import tax_benefit_system

Expand All @@ -25,46 +26,37 @@ def test_param_values():
}

for date, value in dated_values.items():
assert_equal(
tax_benefit_system.get_parameters_at_instant(date).taxes.income_tax_rate,
value
)
assert tax_benefit_system.get_parameters_at_instant(date).taxes.income_tax_rate == value


@raises(ParameterNotFound)
def test_param_before_it_is_defined():
tax_benefit_system.get_parameters_at_instant('1997-12-31').taxes.income_tax_rate
with pytest.raises(ParameterNotFound):
tax_benefit_system.get_parameters_at_instant('1997-12-31').taxes.income_tax_rate


# The placeholder should have no effect on the parameter computation
def test_param_with_placeholder():
assert_equal(
tax_benefit_system.get_parameters_at_instant('2018-01-01').taxes.income_tax_rate,
0.15
)
assert tax_benefit_system.get_parameters_at_instant('2018-01-01').taxes.income_tax_rate == 0.15


def test_stopped_parameter_before_end_value():
assert_equal(
tax_benefit_system.get_parameters_at_instant('2011-12-31').benefits.housing_allowance,
0.25
)
assert tax_benefit_system.get_parameters_at_instant('2011-12-31').benefits.housing_allowance == 0.25


@raises(ParameterNotFound)
def test_stopped_parameter_after_end_value():
tax_benefit_system.get_parameters_at_instant('2016-12-01').benefits.housing_allowance
with pytest.raises(ParameterNotFound):
tax_benefit_system.get_parameters_at_instant('2016-12-01').benefits.housing_allowance


def test_parameter_for_period():
income_tax_rate = tax_benefit_system.parameters.taxes.income_tax_rate
assert income_tax_rate("2015") == income_tax_rate("2015-01-01")


@raises(ValueError)
def test_wrong_value():
income_tax_rate = tax_benefit_system.parameters.taxes.income_tax_rate
income_tax_rate("test")
with pytest.raises(ValueError):
income_tax_rate("test")


def test_parameter_repr():
Expand Down Expand Up @@ -97,8 +89,7 @@ def test_parameter_node_metadata():

def test_parameter_documentation():
parameter = tax_benefit_system.parameters.benefits.housing_allowance
assert_equal(parameter.documentation,
'A fraction of the rent.\nFrom the 1st of Dec 2016, the housing allowance no longer exists.\n')
assert parameter.documentation == 'A fraction of the rent.\nFrom the 1st of Dec 2016, the housing allowance no longer exists.\n'


def test_get_descendants():
Expand Down
11 changes: 3 additions & 8 deletions tests/core/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import subprocess

from nose.tools import nottest, raises
import pytest
import openfisca_extension_template

from openfisca_core.tools.test_runner import run_tests
Expand All @@ -18,11 +18,6 @@
EXIT_TESTSFAILED = 1


# Declare that these two functions are not tests to run with nose
nottest(run_tests)


@nottest
def run_yaml_test(path, options = None):
yaml_path = os.path.join(yaml_tests_dir, path)

Expand Down Expand Up @@ -92,12 +87,12 @@ def test_shell_script():
subprocess.check_call(command, stdout = devnull, stderr = devnull)


@raises(subprocess.CalledProcessError)
def test_failing_shell_script():
yaml_path = os.path.join(yaml_tests_dir, 'test_failure.yaml')
command = ['openfisca', 'test', yaml_path, '-c', 'openfisca_dummy_country']
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(command, stdout = devnull, stderr = devnull)
with pytest.raises(subprocess.CalledProcessError):
subprocess.check_call(command, stdout = devnull, stderr = devnull)


def test_shell_script_with_reform():
Expand Down
32 changes: 14 additions & 18 deletions tests/web_api/test_entities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from http.client import OK
from nose.tools import assert_equal
import json
import openfisca_country_template
from . import subject
Expand All @@ -19,22 +18,19 @@ def test_response_data():
entities = json.loads(entities_response.data.decode('utf-8'))
test_documentation = openfisca_country_template.entities.Household.doc.strip()

assert_equal(
entities['household'],
{
'description': 'All the people in a family or group who live together in the same place.',
'documentation': test_documentation,
'plural': 'households',
'roles': {
'child': {
'description': 'Other individuals living in the household.',
'plural': 'children',
},
'parent': {
'description': 'The one or two adults in charge of the household.',
'plural': 'parents',
'max': 2,
}
assert entities['household'] == {
'description': 'All the people in a family or group who live together in the same place.',
'documentation': test_documentation,
'plural': 'households',
'roles': {
'child': {
'description': 'Other individuals living in the household.',
'plural': 'children',
},
'parent': {
'description': 'The one or two adults in charge of the household.',
'plural': 'parents',
'max': 2,
}
}
)
}

0 comments on commit 029fad0

Please sign in to comment.