8000 Convert remaining tests to pytest. · adrn/matplotlib@82630de · GitHub
[go: up one dir, main page]

Skip to con 8000 tent

Commit 82630de

Browse files
committed
Convert remaining tests to pytest.
1 parent b1e0937 commit 82630de

File tree

11 files changed

+24
-93
lines changed

11 files changed

+24
-93
lines changed

lib/matplotlib/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,14 +1474,7 @@ def _jupyter_nbextension_paths():
14741474

14751475

14761476
default_test_modules = [
1477-
'matplotlib.tests.test_coding_standards',
1478-
'matplotlib.tests.test_offsetbox',
1479-
'matplotlib.tests.test_patches',
1480-
'matplotlib.tests.test_path',
1481-
'matplotlib.tests.test_patheffects',
1482-
'matplotlib.tests.test_pickle',
14831477
'matplotlib.tests.test_png',
1484-
'matplotlib.tests.test_quiver',
14851478
'matplotlib.tests.test_units',
14861479
'matplotlib.tests.test_widgets',
14871480
'matplotlib.tests.test_cycles',

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from fnmatch import fnmatch
55
import os
66

7-
from nose.tools import assert_equal
8-
from nose.plugins.skip import SkipTest
7+
import pytest
98
from ..testing import xfail
109

1110
try:
@@ -103,7 +102,7 @@ def assert_pep8_conformance(module=matplotlib, exclude_files=None,
103102
__tracebackhide__ = True
104103

105104
if not HAS_PEP8:
106-
raise SkipTest('The pep8 tool is required for this test')
105+
pytest.skip('The pep8 tool is required for this test')
107106

108107
# to get a list of bad files, rather than the specific errors, add
109108
# "reporter=pep8.FileReport" to the StyleGuide constructor.
@@ -141,7 +140,7 @@ def assert_pep8_conformance(module=matplotlib, exclude_files=None,
141140
"{0}".format('\n'.join(reporter._global_deferred_print)))
142141
else:
143142
msg = "Found code syntax errors (and warnings)."
144-
assert_equal(result.total_errors, 0, msg)
143+
assert result.total_errors == 0, msg
145144

146145
# If we've been using the exclusions reporter, check that we didn't
147146
# exclude files unnecessarily.
@@ -287,8 +286,3 @@ def test_pep8_conformance_examples():
287286
pep8_additional_ignore=PEP8_ADDITIONAL_IGNORE +
288287
['E116', 'E501', 'E402'],
289288
expected_bad_files=expected_bad_files)
290-
291-
292-
if __name__ == '__main__':
293-
import nose
294-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import warnings
88

9-
109
import numpy as np
1110
from numpy.testing import assert_array_equal
1211

lib/matplotlib/tests/test_legend.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,3 @@ def test_linecollection_scaled_dashes():
331331
for oh, lh in zip((lc1, lc2, lc3), (h1, h2, h3)):
332332
assert oh.get_linestyles()[0][1] == lh._dashSeq
333333
assert oh.get_linestyles()[0][0] == lh._dashOffset
334-
335-
336-
if __name__ == '__main__':
337-
import nose
338-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_mlab.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,13 +3102,3 @@ def test_psd_onesided_norm():
31023102
sides='onesided')
31033103
Su_1side = np.append([Su[0]], Su[1:4] + Su[4:][::-1])
31043104
assert_allclose(P, Su_1side, atol=1e-06)
3105-
3106-
3107-
if __name__ == '__main__':
3108-
import nose
3109-
import sys
3110-
3111-
args = ['-s', '--with-doctest']
3112-
argv = sys.argv
3113-
argv = argv[:1] + args + argv[1:]
3114-
nose.runmodule(argv=argv, exit=False)

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import nose
5-
from nose.tools import assert_true, assert_false
64
from matplotlib.testing.decorators import image_comparison, cleanup
75
import matplotlib.pyplot as plt
86
import matplotlib.patches as mpatches
@@ -78,9 +76,9 @@ def test_offsetbox_clip_children():
7876
ax.add_artist(anchored_box)
7977

8078
fig.canvas.draw()
81-
assert_false(fig.stale)
79+
assert not fig.stale
8280
da.clip_children = True
83-
assert_true(fig.stale)
81+
assert fig.stale
8482

8583

8684
@cleanup
@@ -103,6 +101,3 @@ def test_offsetbox_loc_codes():
103101
anchored_box = AnchoredOffsetbox(loc=code, child=da)
104102
ax.add_artist(anchored_box)
105103
fig.canvas.draw()
106-
107-
if __name__ == '__main__':
108-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_patches.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import six
88

99
import numpy as np
10-
from numpy.testing import assert_array_equal
11-
from numpy.testing import assert_equal
12-
from numpy.testing import assert_almost_equal
10+
from numpy.testing import assert_almost_equal, assert_array_equal
1311

1412
from matplotlib.patches import Polygon
1513
from matplotlib.patches import Rectangle
@@ -255,9 +253,9 @@ def test_wedge_movement():
255253

256254
w = mpatches.Wedge(**init_args)
257255
for attr, (old_v, new_v, func) in six.iteritems(param_dict):
258-
assert_equal(getattr(w, attr), old_v)
256+
assert getattr(w, attr) == old_v
259257
getattr(w, func)(new_v)
260-
assert_equal(getattr(w, attr), new_v)
258+
assert getattr(w, attr) == new_v
261259

262260

263261
# png needs tol>=0.06, pdf tol>=1.617
@@ -313,8 +311,3 @@ def test_patch_str():
313311
p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)
314312
expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)'
315313
assert str(p) == expected
316-
317-
318-
if __name__ == '__main__':
319-
import nose
320-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_path.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import numpy as np
88

99
from numpy.testing import assert_array_equal
10+
import pytest
1011

1112
from matplotlib.path import Path
1213
from matplotlib.patches import Polygon
13-
from nose.tools import assert_raises, assert_equal
1414
from matplotlib.testing.decorators import image_comparison
1515
import matplotlib.pyplot as plt
1616
from matplotlib import transforms
@@ -22,7 +22,8 @@ def test_readonly_path():
2222
def modify_vertices():
2323
path.vertices = path.vertices * 2.0
2424

25-
assert_raises(AttributeError, modify_vertices)
25+
with pytest.raises(AttributeError):
26+
modify_vertices()
2627

2728

2829
def test_point_in_path():
@@ -90,7 +91,7 @@ def test_make_compound_path_empty():
9091
# We should be able to make a compound path with no arguments.
9192
# This makes it easier to write generic path based code.
9293
r = Path.make_compound_path()
93-
assert_equal(r.vertices.shape, (0, 2))
94+
assert r.vertices.shape == (0, 2)
9495

9596

9697
@image_comparison(baseline_images=['xkcd'], remove_text=True)
@@ -181,8 +182,3 @@ def test_path_deepcopy():
181182
path2 = Path(verts, codes)
182183
copy.deepcopy(path1)
183184
copy.deepcopy(path2)
184-
185-
186-
if __name__ == '__main__':
187-
import nose
188-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_patheffects.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
import matplotlib.pyplot as plt
1111
import matplotlib.patheffects as path_effects
1212

13-
try:
14-
# mock in python 3.3+
15-
from unittest import mock
16-
except ImportError:
17-
import mock
18-
from nose.tools import assert_equal
19-
2013

2114
@image_comparison(baseline_images=['patheffect1'], remove_text=True)
2215
def test_patheffect1():
@@ -101,13 +94,12 @@ def test_PathEffect_points_to_pixels():
10194

10295
# Confirm that using a path effects renderer maintains point sizes
10396
# appropriately. Otherwise rendered font would be the wrong size.
104-
assert_equal(renderer.points_to_pixels(15),
105-
pe_renderer.points_to_pixels(15))
97+
assert renderer.points_to_pixels(15) == pe_renderer.points_to_pixels(15)
10698

10799

108100
def test_SimplePatchShadow_offset():
109101
pe = path_effects.SimplePatchShadow(offset=(4, 5))
110-
assert_equal(pe._offset, (4, 5))
102+
assert pe._offset == (4, 5)
111103

112104

113105
@image_comparison(baseline_images=['collection'], tol=0.015)
@@ -127,8 +119,3 @@ def test_collection():
127119
linewidth=3)])
128120
text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none',
129121
'edgecolor': 'blue'})
130-
131-
132-
if __name__ == '__main__':
133-
import nose
134-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_pickle.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from io import BytesIO
99

10-
from nose.tools import assert_equal, assert_not_equal
1110
import numpy as np
1211

1312
from matplotlib.testing.decorators import cleanup, image_comparison
@@ -184,16 +183,16 @@ def test_complete():
184183
plt.close('all')
185184

186185
# make doubly sure that there are no figures left
187-
assert_equal(plt._pylab_helpers.Gcf.figs, {})
186+
assert plt._pylab_helpers.Gcf.figs == {}
188187

189188
# wind back the fh and load in the figure
190189
result_fh.seek(0)
191190
fig = pickle.load(result_fh)
192191

193192
# make sure there is now a figure manager
194-
assert_not_equal(plt._pylab_helpers.Gcf.figs, {})
193+
assert plt._pylab_helpers.Gcf.figs != {}
195194

196-
assert_equal(fig.get_label(), 'Figure with a label?')
195+
assert fig.get_label() == 'Figure with a label?'
197196

198197

199198
@cleanup
@@ -262,13 +261,12 @@ def test_transform():
262261

263262
obj = pickle.loads(pf)
264263
# Check parent -> child links of TransformWrapper.
265-
assert_equal(obj.wrapper._child, obj.composite)
264+
assert obj.wrapper._child == obj.composite
266265
# Check child -> parent links of TransformWrapper.
267-
assert_equal(
268-
[v() for v in obj.wrapper._parents.values()], [obj.composite2])
266+
assert [v() for v in obj.wrapper._parents.values()] == [obj.composite2]
269267
# Check input and output dimensions are set as expected.
270-
assert_equal(obj.wrapper.input_dims, obj.composite.input_dims)
271-
assert_equal(obj.wrapper.output_dims, obj.composite.output_dims)
268+
assert obj.wrapper.input_dims == obj.composite.input_dims
269+
assert obj.wrapper.output_dims == obj.composite.output_dims
272270

273271

274272
def test_rrulewrapper():
@@ -278,8 +276,3 @@ def test_rrulewrapper():
278276
except RecursionError:
279277
print('rrulewrapper pickling test failed')
280278
raise
281-
282-
283-
if __name__ == '__main__':
284-
import nose
285-
nose.runmodule(argv=['-s'])

0 commit comments

Comments
 (0)
0