Skip to content

Commit b095d8f

Browse files
authored
MAINT, TST: Remove nose imports and use pytest (#611)
* MAINT, TST: Remove nose imports and use pytest * CI: Use pytest
1 parent c476a98 commit b095d8f

File tree

6 files changed

+33
-90
lines changed

6 files changed

+33
-90
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
run: |
4848
pytest quantecon/game_theory
4949
pytest quantecon/markov
50+
pytest quantecon/optimize
51+
pytest quantecon/random
5052
- name: Coveralls Parallel
5153
uses: AndreMiras/coveralls-python-action@develop
5254
if: runner.os == 'Linux'

quantecon/optimize/tests/test_linprog_simplex.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,3 @@ def test_bug_8662(self):
239239
desired_fun = -36.0000000000
240240
res = linprog_simplex(c, A_ub=A_ub, b_ub=b_ub)
241241
_assert_success(res, c, b_ub=b_ub, desired_fun=desired_fun)
242-
243-
244-
if __name__ == '__main__':
245-
import sys
246-
import nose
247-
248-
argv = sys.argv[:]
249-
argv.append('--verbose')
250-
argv.append('--nocapture')
251-
nose.main(argv=argv, defaultTest=__file__)

quantecon/optimize/tests/test_nelder_mead.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import numpy as np
77
from numba import njit
8-
from numpy.testing import assert_allclose
9-
from nose.tools import raises
8+
from numpy.testing import assert_allclose, assert_raises
109

1110
from quantecon.optimize import nelder_mead
1211
from ..nelder_mead import _nelder_mead_algorithm
@@ -330,71 +329,59 @@ def test_discontinuous(self):
330329
assert_allclose(results.fun, fun)
331330

332331

333-
@raises(ValueError)
334332
def test_invalid_bounds_1():
335333
x0 = np.array([-2., 1.])
336334
bounds = np.array([[10., -10.], [10., -10.]])
337-
nelder_mead(rosenbrock, x0, bounds=bounds)
335+
assert_raises(ValueError, nelder_mead, rosenbrock, x0, bounds=bounds)
338336

339337

340-
@raises(ValueError)
341338
def test_invalid_bounds_2():
342339
x0 = np.array([-2., 1.])
343340
bounds = np.array([[10., -10., 10., -10.]])
344-
nelder_mead(rosenbrock, x0, bounds=bounds)
341+
assert_raises(ValueError, nelder_mead, rosenbrock, x0, bounds=bounds)
345342

346343

347-
@raises(ValueError)
348344
def test_invalid_ρ():
349345
vertices = np.array([[-2., 1.],
350346
[1.05 * -2., 1.],
351347
[-2., 1.05 * 1.]])
352348
invalid_ρ = -1.
353-
_nelder_mead_algorithm(rosenbrock, vertices, ρ=invalid_ρ)
349+
assert_raises(ValueError, _nelder_mead_algorithm, rosenbrock,
350+
vertices, ρ=invalid_ρ)
354351

355352

356-
@raises(ValueError)
357353
def test_invalid_χ():
358354
vertices = np.array([[-2., 1.],
359355
[1.05 * -2., 1.],
360356
[-2., 1.05 * 1.]])
361357
invalid_χ = 0.5
362-
_nelder_mead_algorithm(rosenbrock, vertices, χ=invalid_χ)
358+
assert_raises(ValueError, _nelder_mead_algorithm, rosenbrock,
359+
vertices, χ=invalid_χ)
363360

364361

365-
@raises(ValueError)
366362
def test_invalid_ρχ():
367363
vertices = np.array([[-2., 1.],
368364
[1.05 * -2., 1.],
369365
[-2., 1.05 * 1.]])
370366
ρ = 2
371367
χ = 1.5
372-
_nelder_mead_algorithm(rosenbrock, vertices, ρ=ρ, χ=χ)
368+
assert_raises(ValueError, _nelder_mead_algorithm, rosenbrock,
369+
vertices, ρ=ρ, χ=χ)
373370

374371

375-
@raises(ValueError)
376372
def test_invalid_γ():
377373
vertices = np.array([[-2., 1.],
378374
[1.05 * -2., 1.],
379375
[-2., 1.05 * 1.]])
380376
invalid_γ = -1e-7
381-
_nelder_mead_algorithm(rosenbrock, vertices, γ=invalid_γ)
377+
assert_raises(ValueError, _nelder_mead_algorithm, rosenbrock,
378+
vertices, γ=invalid_γ)
382379

383380

384-
@raises(ValueError)
385381
def test_invalid_σ():
386382
vertices = np.array([[-2., 1.],
387383
[1.05 * -2., 1.],
388384
[-2., 1.05 * 1.]])
389385
invalid_σ = 1. + 1e-7
390-
_nelder_mead_algorithm(rosenbrock, vertices, σ=invalid_σ)
391-
392-
393-
if __name__ == '__main__':
394-
import sys
395-
import nose
396-
397-
argv = sys.argv[:]
398-
argv.append('--verbose')
399-
argv.append('--nocapture')
400-
nose.main(argv=argv, defaultTest=__file__)
386+
assert_raises(ValueError, _nelder_mead_algorithm, rosenbrock,
387+
vertices, σ=invalid_σ)

quantecon/optimize/tests/test_root_finding.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ def func_two_prime2(x):
5757

5858
def test_newton_basic():
5959
"""
60-
Uses the function f defined above to test the scalar maximization
60+
Uses the function f defined above to test the scalar maximization
6161
routine.
6262
"""
6363
true_fval = 1.0
6464
fval = newton(func, 5, func_prime)
6565
assert_almost_equal(true_fval, fval.root, decimal=4)
66-
66+
6767

6868
def test_newton_basic_two():
6969
"""
70-
Uses the function f defined above to test the scalar maximization
70+
Uses the function f defined above to test the scalar maximization
7171
routine.
7272
"""
7373
true_fval = 1.0
@@ -83,7 +83,7 @@ def test_newton_hard():
8383
fval = newton(func_two, 0.4, func_two_prime)
8484
assert_allclose(true_fval, fval.root, rtol=1e-5, atol=0.01)
8585

86-
86+
8787
def test_halley_basic():
8888
"""
8989
Basic test for halley method
@@ -135,15 +135,3 @@ def test_bisect_basic():
135135

136136
def test_brentq_basic():
137137
run_check(brentq, 'brentq')
138-
139-
# executing testcases.
140-
141-
142-
if __name__ == '__main__':
143-
import sys
144-
import nose
145-
146-
argv = sys.argv[:]
147-
argv.append('--verbose')
148-
argv.append('--nocapture')
149-
nose.main(argv=argv, defaultTest=__file__)

quantecon/optimize/tests/test_scalar_max.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
44
"""
55
import numpy as np
6-
from numpy.testing import assert_almost_equal
7-
from nose.tools import raises
6+
from numpy.testing import assert_almost_equal, assert_raises
87
from numba import njit
98

109
from quantecon.optimize import brent_max
@@ -51,26 +50,13 @@ def test_g():
5150
assert_almost_equal(true_xf, xf, decimal=4)
5251

5352

54-
@raises(ValueError)
5553
def test_invalid_a_brent_max():
56-
brent_max(f, -np.inf, 2)
54+
assert_raises(ValueError, brent_max, f, -np.inf, 2)
5755

5856

59-
@raises(ValueError)
6057
def test_invalid_b_brent_max():
61-
brent_max(f, -2, np.inf)
58+
assert_raises(ValueError, brent_max, f, -2, -np.inf)
6259

6360

64-
@raises(ValueError)
6561
def test_invalid_a_b_brent_max():
66-
brent_max(f, 1, 0)
67-
68-
69-
if __name__ == '__main__':
70-
import sys
71-
import nose
72-
73-
argv = sys.argv[:]
74-
argv.append('--verbose')
75-
argv.append('--nocapture')
76-
nose.main(argv=argv, defaultTest=__file__)
62+
assert_raises(ValueError, brent_max, f, 1, 0)

quantecon/random/tests/test_utilities.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
"""
1010
import numbers
1111
import numpy as np
12-
from numpy.testing import assert_array_equal, assert_allclose, assert_raises
13-
from nose.tools import eq_, ok_
12+
from numpy.testing import (assert_array_equal, assert_allclose, assert_raises,
13+
assert_)
1414
from quantecon.random import probvec, sample_without_replacement, draw
1515

1616

1717
# probvec #
1818

1919
class TestProbvec:
20-
def setUp(self):
20+
def setup(self):
2121
self.m, self.k = 2, 3 # m vectors of dimension k
2222
seed = 1234
2323

@@ -27,7 +27,7 @@ def setUp(self):
2727

2828
def test_shape(self):
2929
for out in [self.out_parallel, self.out_cpu]:
30-
eq_(out.shape, (self.m, self.k))
30+
assert_(out.shape == (self.m, self.k))
3131

3232
def test_parallel_cpu(self):
3333
assert_array_equal(self.out_parallel, self.out_cpu)
@@ -53,7 +53,7 @@ def test_sample_without_replacement_uniqueness():
5353
n = 10
5454
a = sample_without_replacement(n, n)
5555
b = np.unique(a)
56-
eq_(len(b), n)
56+
assert_(len(b) == n)
5757

5858

5959
def test_sample_without_replacement_value_error():
@@ -68,26 +68,26 @@ def test_sample_without_replacement_value_error():
6868
# draw #
6969

7070
class TestDraw:
71-
def setUp(self):
71+
def setup(self):
7272
self.pmf = np.array([0.4, 0.1, 0.5])
7373
self.cdf = np.cumsum(self.pmf)
7474
self.n = len(self.pmf)
7575

7676
def test_return_types(self):
7777
out = draw(self.cdf)
78-
ok_(isinstance(out, numbers.Integral))
78+
assert_(isinstance(out, numbers.Integral))
7979

8080
size = 10
8181
out = draw(self.cdf, size)
82-
eq_(out.shape, (size,))
82+
assert_(out.shape == (size,))
8383

8484
def test_return_values(self):
8585
out = draw(self.cdf)
86-
ok_(out in range(self.n))
86+
assert_(out in range(self.n))
8787

8888
size = 10
8989
out = draw(self.cdf, size)
90-
ok_(np.isin(out, range(self.n)).all())
90+
assert_(np.isin(out, range(self.n)).all())
9191

9292
def test_lln(self):
9393
size = 1000000
@@ -96,13 +96,3 @@ def test_lln(self):
9696
pmf_computed = hist * np.diff(bin_edges)
9797
atol = 1e-2
9898
assert_allclose(pmf_computed, self.pmf, atol=atol)
99-
100-
101-
if __name__ == '__main__':
102-
import sys
103-
import nose
104-
105-
argv = sys.argv[:]
106-
argv.append('--verbose')
107-
argv.append('--nocapture')
108-
nose.main(argv=argv, defaultTest=__file__)

0 commit comments

Comments
 (0)