Skip to content

Commit c5a81d5

Browse files
authored
MAINT, TST: Remove nose imports and use pytest testing (#604)
* TST: remove nose imports * TST: remove nose imports * TST: remove nose imports * TST: remove nose imports * CI: Add pytest testing for game_theory * STY: pep8 fixes * CI: Add docs * Trigger CI
1 parent 84e0738 commit c5a81d5

File tree

9 files changed

+122
-225
lines changed

9 files changed

+122
-225
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ jobs:
3737
- name: Install dependencies
3838
run: |
3939
python -m pip install --upgrade pip
40-
pip install -U nose coverage numpy scipy pandas numba sympy ipython statsmodels flake8
40+
pip install -U nose coverage numpy scipy pandas numba sympy ipython statsmodels flake8 pytest
4141
python setup.py install
42-
- name: Run Tests
42+
- name: Run Tests (nose)
4343
run: |
4444
flake8 --select F401, F405,E231 quantecon
4545
nosetests --with-coverage -a "!slow" --cover-package=quantecon
46+
- name: Run Tests (pytest)
47+
run: |
48+
pytest quantecon/game_theory
4649
- name: Coveralls Parallel
4750
uses: AndreMiras/coveralls-python-action@develop
4851
if: runner.os == 'Linux'

quantecon/game_theory/tests/test_lemke_howson.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""
22
Tests for lemke_howson.py
3-
43
"""
54
import numpy as np
6-
from numpy.testing import assert_allclose
7-
from nose.tools import eq_, raises
5+
from numpy.testing import assert_allclose, assert_, assert_raises
86
from quantecon.game_theory import Player, NormalFormGame, lemke_howson
97

108

119
class TestLemkeHowson():
12-
def setUp(self):
10+
def setup(self):
1311
self.game_dicts = []
1412

1513
# From von Stengel 2007 in Algorithmic Game Theory
@@ -32,7 +30,7 @@ def test_lemke_howson(self):
3230

3331

3432
class TestLemkeHowsonDegenerate():
35-
def setUp(self):
33+
def setup(self):
3634
self.game_dicts = []
3735

3836
# From von Stengel 2007 in Algorithmic Game Theory
@@ -80,7 +78,7 @@ def test_lemke_howson_degenerate(self):
8078
for action_computed, action in zip(NE_computed,
8179
d['NEs_dict'][k]):
8280
assert_allclose(action_computed, action)
83-
eq_(res.converged, d['converged'])
81+
assert_(res.converged == d['converged'])
8482

8583

8684
def test_lemke_howson_capping():
@@ -98,47 +96,34 @@ def test_lemke_howson_capping():
9896
capping=max_iter, full_output=True)
9997
for action0, action1 in zip(NE0, NE1):
10098
assert_allclose(action0, action1)
101-
eq_(res0.init, res1.init)
99+
assert_(res0.init == res1.init)
102100

103101
init_pivot = 1
104102
max_iter = m+n
105103
NE, res = lemke_howson(g, init_pivot=init_pivot, max_iter=max_iter,
106104
capping=1, full_output=True)
107-
eq_(res.num_iter, max_iter)
108-
eq_(res.init, init_pivot-1)
105+
assert_(res.num_iter == max_iter)
106+
assert_(res.init == init_pivot-1)
109107

110108

111-
@raises(TypeError)
112109
def test_lemke_howson_invalid_g():
113110
bimatrix = [[(3, 3), (3, 2)],
114111
[(2, 2), (5, 6)],
115112
[(0, 3), (6, 1)]]
116-
lemke_howson(bimatrix)
113+
assert_raises(TypeError, lemke_howson, bimatrix)
117114

118115

119-
@raises(ValueError)
120116
def test_lemke_howson_invalid_init_pivot_integer():
121117
bimatrix = [[(3, 3), (3, 2)],
122118
[(2, 2), (5, 6)],
123119
[(0, 3), (6, 1)]]
124120
g = NormalFormGame(bimatrix)
125-
lemke_howson(g, -1)
121+
assert_raises(ValueError, lemke_howson, g, -1)
126122

127123

128-
@raises(TypeError)
129124
def test_lemke_howson_invalid_init_pivot_float():
130125
bimatrix = [[(3, 3), (3, 2)],
131126
[(2, 2), (5, 6)],
132127
[(0, 3), (6, 1)]]
133128
g = NormalFormGame(bimatrix)
134-
lemke_howson(g, 1.0)
135-
136-
137-
if __name__ == '__main__':
138-
import sys
139-
import nose
140-
141-
argv = sys.argv[:]
142-
argv.append('--verbose')
143-
argv.append('--nocapture')
144-
nose.main(argv=argv, defaultTest=__file__)
129+
assert_raises(TypeError, lemke_howson, g, 1.0)

quantecon/game_theory/tests/test_mclennan_tourky.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
"""
22
Tests for mclennan_tourky.py
3-
43
"""
54
import numpy as np
6-
from numpy.testing import assert_array_equal
7-
from nose.tools import ok_, raises
5+
from numpy.testing import assert_array_equal, assert_raises, assert_
86
from quantecon.game_theory import Player, NormalFormGame, mclennan_tourky
97
from quantecon.game_theory.mclennan_tourky import (
10-
_best_response_selection, _flatten_action_profile, _is_epsilon_nash
8+
_best_response_selection, _flatten_action_profile, _is_epsilon_nash
119
)
1210

1311

1412
class TestMclennanTourky():
15-
def setUp(self):
13+
def setup(self):
1614
def anti_coordination(N, v):
1715
payoff_array = np.empty((2,)*N)
1816
payoff_array[0, :] = 1
@@ -48,37 +46,34 @@ def epsilon_nash_interval(N, v, epsilon):
4846
def test_convergence_default(self):
4947
for d in self.game_dicts:
5048
NE, res = mclennan_tourky(d['g'], full_output=True)
51-
ok_(res.converged)
49+
assert_(res.converged)
5250

5351
def test_pure_nash(self):
5452
for d in self.game_dicts:
5553
init = (1,) + (0,)*(d['g'].N-1)
5654
NE, res = mclennan_tourky(d['g'], init=init, full_output=True)
57-
ok_(res.num_iter==1)
55+
assert_(res.num_iter == 1)
5856

5957

6058
class TestMclennanTourkyInvalidInputs():
61-
def setUp(self):
59+
def setup(self):
6260
self.bimatrix = [[(3, 3), (3, 2)],
6361
[(2, 2), (5, 6)],
6462
[(0, 3), (6, 1)]]
6563
self.g = NormalFormGame(self.bimatrix)
6664

67-
@raises(TypeError)
6865
def test_mclennan_tourky_invalid_g(self):
69-
mclennan_tourky(self.bimatrix)
66+
assert_raises(TypeError, mclennan_tourky, self.bimatrix)
7067

71-
@raises(TypeError)
7268
def test_mclennan_tourky_invalid_init_type(self):
73-
mclennan_tourky(self.g, 1)
69+
assert_raises(TypeError, mclennan_tourky, self.g, 1)
7470

75-
@raises(ValueError)
7671
def test_mclennan_tourky_invalid_init_length(self):
77-
mclennan_tourky(self.g, [1])
72+
assert_raises(ValueError, mclennan_tourky, self.g, [1])
7873

7974

8075
class TestEpsilonNash():
81-
def setUp(self):
76+
def setup(self):
8277
def anti_coordination(N, v):
8378
payoff_array = np.empty((2,)*N)
8479
payoff_array[0, :] = 1
@@ -121,17 +116,17 @@ def test_epsilon_nash_with_full_output(self):
121116
NE, res = \
122117
mclennan_tourky(d['g'], epsilon=d['epsilon'], full_output=True)
123118
for i in range(d['g'].N):
124-
ok_(d['lb'] < NE[i][0] < d['ub'])
119+
assert_(d['lb'] < NE[i][0] < d['ub'])
125120

126121
def test_epsilon_nash_without_full_output(self):
127122
for d in self.game_dicts:
128123
NE = mclennan_tourky(d['g'], epsilon=d['epsilon'],
129124
full_output=False)
130125
for i in range(d['g'].N):
131-
ok_(d['lb'] < NE[i][0] < d['ub'])
126+
assert_(d['lb'] < NE[i][0] < d['ub'])
132127

133128
def test_is_epsilon_nash_no_indptr(self):
134-
ok_(_is_epsilon_nash([1., 0., 0., 1., 0.], self.g, 1e-5))
129+
assert_(_is_epsilon_nash([1., 0., 0., 1., 0.], self.g, 1e-5))
135130

136131

137132
def test_flatten_action_profile():
@@ -151,13 +146,3 @@ def test_best_response_selection_no_indptr():
151146
expected_output = np.array([0., 1., 0., 0., 1.])
152147

153148
assert_array_equal(test_obj, expected_output)
154-
155-
156-
if __name__ == '__main__':
157-
import sys
158-
import nose
159-
160-
argv = sys.argv[:]
161-
argv.append('--verbose')
162-
argv.append('--nocapture')
163-
nose.main(argv=argv, defaultTest=__file__)

0 commit comments

Comments
 (0)