Skip to content

Commit 496fdea

Browse files
Smit-createoyamad
andauthored
MAINT: Remove nose imports and use pytest (#613)
* MAINT: Remove nose imports and use pytest * STY: pep8 fixes * MAINT: Remove nose imports and use pytest * MAINT: Remove nose imports and use pytest * CI: Add pytest in environment.yml * MAINT: Remove nose imports and use pytest * MAINT: Add missing __init__ files * CI: Move to pytest * FIX: Specify dtype=np.int64 to avoid overflow on Windows Co-Authored-By: Daisuke Oyama <[email protected]> * STY: Fix pep8 issues Co-authored-by: Daisuke Oyama <[email protected]>
1 parent f322e44 commit 496fdea

33 files changed

+268
-422
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,28 @@ jobs:
3434
uses: actions/setup-python@v1
3535
with:
3636
python-version: ${{ matrix.python-version }}
37+
3738
- name: Install dependencies
3839
run: |
3940
python -m pip install --upgrade pip
40-
pip install -U nose coverage numpy scipy pandas numba sympy ipython statsmodels flake8 pytest
41+
pip install -U coverage numpy scipy pandas numba sympy ipython statsmodels flake8 pytest
4142
python setup.py install
42-
- name: Run Tests (nose)
43+
44+
- name: flake8 Tests
4345
run: |
4446
flake8 --select F401, F405,E231 quantecon
45-
nosetests --with-coverage -a "!slow" --cover-package=quantecon
47+
4648
- name: Run Tests (pytest)
4749
run: |
48-
pytest quantecon/game_theory
49-
pytest quantecon/markov
50-
pytest quantecon/optimize
51-
pytest quantecon/random
50+
pytest quantecon
51+
5252
- name: Coveralls Parallel
5353
uses: AndreMiras/coveralls-python-action@develop
5454
if: runner.os == 'Linux'
5555
with:
5656
flag-name: run-${{ matrix.test_number }}
5757
parallel: true
58+
5859
coveralls_finish:
5960
needs: tests
6061
runs-on: ubuntu-latest

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ dependencies:
1414
- statsmodels
1515
- flake8
1616
- requests
17+
- pytest

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
slow: marks tests as slow (deselect with '-m "not slow"')

quantecon/game_theory/game_generators/tests/__init__.py

Whitespace-only changes.

quantecon/game_theory/tests/__init__.py

Whitespace-only changes.

quantecon/markov/tests/__init__.py

Whitespace-only changes.

quantecon/quad.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def qnwequi(n, a, b, kind="N", equidist_pp=None, random_state=None):
155155
if b.size == 1:
156156
b = np.repeat(b, d)
157157

158-
i = np.arange(1, n + 1)
158+
# Specify `dtype=np.int64` to avoid overflow on Windows
159+
i = np.arange(1, n + 1, dtype=np.int64)
159160

160161
if kind.upper() == "N": # Neiderreiter
161162
j = 2.0 ** (np.arange(1, d+1) / (d+1))

quantecon/random/tests/__init__.py

Whitespace-only changes.

quantecon/tests/test_arma.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
covered by the numpy tests since we rely on much of their code.
44
55
"""
6-
import sys
7-
import unittest
86
import numpy as np
9-
from numpy.testing import assert_array_equal
7+
from numpy.testing import assert_array_equal, assert_
108
from quantecon.arma import ARMA
119

1210

13-
class TestARMA(unittest.TestCase):
14-
def setUp(self):
11+
class TestARMA():
12+
def setup(self):
1513
# Initial Values
1614
phi = np.array([.95, -.4, -.4])
1715
theta = np.zeros(3)
@@ -28,7 +26,7 @@ def test_simulate(self):
2826

2927
sim = lp.simulation(ts_length=250)
3028

31-
self.assertTrue(sim.size==250)
29+
assert_(sim.size == 250)
3230

3331
def test_simulate_with_seed(self):
3432
lp = self.lp
@@ -43,10 +41,4 @@ def test_impulse_response(self):
4341

4442
imp_resp = lp.impulse_response(impulse_length=75)
4543

46-
self.assertTrue(imp_resp.size==75)
47-
48-
49-
if __name__ == '__main__':
50-
suite = unittest.TestLoader().loadTestsFromTestCase(TestARMA)
51-
unittest.TextTestRunner(verbosity=2, stream=sys.stderr).run(suite)
52-
44+
assert_(imp_resp.size == 75)

quantecon/tests/test_compute_fp.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
TODO: add multivariate case
1010
1111
"""
12-
import unittest
1312
import numpy as np
14-
from nose.tools import ok_, raises
13+
from numpy.testing import assert_, assert_raises
1514
from quantecon import compute_fixed_point
1615

1716

18-
class TestFPLogisticEquation(unittest.TestCase):
17+
class TestFPLogisticEquation():
1918

2019
@classmethod
21-
def setUpClass(cls):
20+
def setup(cls):
2221
cls.mu_1 = 0.2 # 0 is unique fixed point forall x_0 \in [0, 1]
2322

2423
# (4mu - 1)/(4mu) is a fixed point forall x_0 \in [0, 1]
@@ -38,34 +37,31 @@ def test_contraction_1(self):
3837
f = lambda x: self.T(x, self.mu_1)
3938
for i in self.unit_inverval:
4039
# should have fixed point of 0.0
41-
self.assertTrue(abs(compute_fixed_point(f, i, **self.kwargs))
42-
< 1e-4)
40+
assert_(abs(compute_fixed_point(f, i, **self.kwargs)) < 1e-4)
4341

4442
def test_not_contraction_2(self):
4543
"compute_fp: no convergence outside interval of convergence"
4644
f = lambda x: self.T(x, self.mu_2)
4745
for i in self.unit_inverval:
4846
# This shouldn't converge to 0.0
49-
self.assertFalse(abs(compute_fixed_point(f, i, **self.kwargs))
50-
< 1e-4)
47+
assert_(not (abs(compute_fixed_point(f, i, **self.kwargs)) < 1e-4))
5148

5249
def test_contraction_2(self):
5350
"compute_fp: convergence inside interval of convergence"
5451
f = lambda x: self.T(x, self.mu_2)
5552
fp = (4 * self.mu_2 - 1) / (4 * self.mu_2)
5653
for i in self.unit_inverval:
5754
# This should converge to fp
58-
self.assertTrue(abs(compute_fixed_point(f, i, **self.kwargs)-fp)
59-
< 1e-4)
55+
assert_(abs(compute_fixed_point(f, i, **self.kwargs)-fp) < 1e-4)
6056

6157
def test_not_contraction_1(self):
6258
"compute_fp: no convergence outside interval of convergence"
6359
f = lambda x: self.T(x, self.mu_1)
6460
fp = (4 * self.mu_1 - 1) / (4 * self.mu_1)
6561
for i in self.unit_inverval:
6662
# This should not converge (b/c unique fp is 0.0)
67-
self.assertFalse(abs(compute_fixed_point(f, i, **self.kwargs)-fp)
68-
< 1e-4)
63+
assert_(not (abs(compute_fixed_point(f, i, **self.kwargs)-fp)
64+
< 1e-4))
6965

7066
def test_imitation_game_method(self):
7167
"compute_fp: Test imitation game method"
@@ -76,22 +72,22 @@ def test_imitation_game_method(self):
7672
for i in self.unit_inverval:
7773
fp_computed = compute_fixed_point(self.T, i, method=method,
7874
mu=mu, **self.kwargs)
79-
self.assertTrue(
75+
assert_(
8076
abs(self.T(fp_computed, mu=mu) - fp_computed) <= error_tol
8177
)
8278

8379
# numpy array input
8480
i = np.asarray(self.unit_inverval)
8581
fp_computed = compute_fixed_point(self.T, i, method=method, mu=mu,
8682
**self.kwargs)
87-
self.assertTrue(
83+
assert_(
8884
abs(self.T(fp_computed, mu=mu) - fp_computed).max() <=
8985
error_tol
9086
)
9187

9288

9389
class TestComputeFPContraction():
94-
def setUp(self):
90+
def setup(self):
9591
self.coeff = 0.5
9692
self.methods = ['iteration', 'imitation_game']
9793

@@ -106,7 +102,7 @@ def test_num_iter_one(self):
106102
fp_computed = compute_fixed_point(self.f, init,
107103
error_tol=error_tol,
108104
method=method)
109-
ok_(fp_computed <= error_tol * 2)
105+
assert_(fp_computed <= error_tol * 2)
110106

111107
def test_num_iter_large(self):
112108
init = 1.
@@ -119,7 +115,7 @@ def test_num_iter_large(self):
119115
error_tol=error_tol,
120116
max_iter=max_iter, method=method,
121117
print_skip=max_iter)
122-
ok_(fp_computed <= error_tol * 2)
118+
assert_(fp_computed <= error_tol * 2)
123119

124120
def test_2d_input(self):
125121
error_tol = self.coeff**4
@@ -129,12 +125,11 @@ def test_2d_input(self):
129125
fp_computed = compute_fixed_point(self.f, init,
130126
error_tol=error_tol,
131127
method=method)
132-
ok_((fp_computed <= error_tol * 2).all())
128+
assert_((fp_computed <= error_tol * 2).all())
133129

134130

135-
@raises(ValueError)
136131
def test_raises_value_error_nonpositive_max_iter():
137132
f = lambda x: 0.5*x
138133
init = 1.
139134
max_iter = 0
140-
compute_fixed_point(f, init, max_iter=max_iter)
135+
assert_raises(ValueError, compute_fixed_point, f, init, max_iter=max_iter)

0 commit comments

Comments
 (0)