Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db61667

Browse filesBrowse files
authored
Merge pull request #7932 from QuLogic/pytest-remaining
Convert remaining tests to pytest
2 parents dd4d2ae + dda6023 commit db61667
Copy full SHA for db61667
Expand file treeCollapse file tree

18 files changed

+83
-147
lines changed

‎conftest.py

Copy file name to clipboardExpand all lines: conftest.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def pytest_configure(config):
6969
matplotlib._init_tests()
7070

7171
if config.getoption('--no-pep8'):
72-
default_test_modules.remove('matplotlib.tests.test_coding_standards')
7372
IGNORED_TESTS['matplotlib'] += 'test_coding_standards'
7473

7574

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,17 +1474,9 @@ 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',
1487-
'matplotlib.tests.test_cycles',
14881480
]
14891481

14901482

‎lib/matplotlib/tests/test_coding_standards.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_coding_standards.py
+3-9Lines 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_colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colors.py
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010

11-
from numpy.testing import assert_raises, assert_equal
11+
from numpy.testing import assert_equal
1212
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
1313

1414
from matplotlib import cycler
@@ -336,7 +336,8 @@ def test_cmap_and_norm_from_levels_and_colors2():
336336
'Wih extend={0!r} and data '
337337
'value={1!r}'.format(extend, d_val))
338338

339-
assert_raises(ValueError, mcolors.from_levels_and_colors, levels, colors)
339+
with pytest.raises(ValueError):
340+
mcolors.from_levels_and_colors(levels, colors)
340341

341342

342343
def test_rgb_hsv_round_trip():
@@ -359,11 +360,8 @@ def test_autoscale_masked():
359360

360361
def test_colors_no_float():
361362
# Gray must be a string to distinguish 3-4 grays from RGB or RGBA.
362-
363-
def gray_from_float_rgba():
364-
return mcolors.to_rgba(0.4)
365-
366-
assert_raises(ValueError, gray_from_float_rgba)
363+
with pytest.raises(ValueError):
364+
mcolors.to_rgba(0.4)
367365

368366

369367
@image_comparison(baseline_images=['light_source_shading_topo'],

‎lib/matplotlib/tests/test_contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_contour.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from matplotlib import mlab
88
from matplotlib.testing.decorators import cleanup, image_comparison
99
from matplotlib import pyplot as plt
10-
from numpy.testing import assert_equal, assert_raises
1110
from numpy.testing import assert_array_almost_equal
11+
import pytest
1212
import warnings
1313

1414
import re
@@ -282,13 +282,14 @@ def test_contourf_decreasing_levels():
282282
# github issue 5477.
283283
z = [[0.1, 0.3], [0.5, 0.7]]
284284
plt.figure()
285-
assert_raises(ValueError, plt.contourf, z, [1.0, 0.0])
285+
with pytest.raises(ValueError):
286+
plt.contourf(z, [1.0, 0.0])
286287
# Legacy contouring algorithm gives a warning rather than raising an error,
287288
# plus a DeprecationWarning.
288289
with warnings.catch_warnings(record=True) as w:
289290
warnings.simplefilter("always")
290291
plt.contourf(z, [1.0, 0.0], corner_mask='legacy')
291-
assert_equal(len(w), 2)
292+
assert len(w) == 2
292293

293294

294295
@cleanup

‎lib/matplotlib/tests/test_cycles.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_cycles.py
+26-16Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from matplotlib.cbook import MatplotlibDeprecationWarning
55
import matplotlib.pyplot as plt
66
import numpy as np
7-
from numpy.testing import assert_raises
7+
import pytest
88

99
from cycler import cycler
1010

@@ -198,18 +198,28 @@ def test_cycle_reset():
198198
@cleanup
199199
def test_invalid_input_forms():
200200
fig, ax = plt.subplots()
201-
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 1)
202-
assert_raises((TypeError, ValueError), ax.set_prop_cycle, [1, 2])
203-
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'color', 'fish')
204-
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'linewidth', 1)
205-
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
206-
'linewidth', {'1': 1, '2': 2})
207-
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
208-
linewidth=1, color='r')
209-
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'foobar', [1, 2])
210-
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
211-
foobar=[1, 2])
212-
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
213-
cycler(foobar=[1, 2]))
214-
assert_raises(ValueError, ax.set_prop_cycle,
215-
cycler(color='rgb', c='cmy'))
201+
202+
with pytest.raises((TypeError, ValueError)):
203+
ax.set_prop_cycle(1)
204+
with pytest.raises((TypeError, ValueError)):
205+
ax.set_prop_cycle([1, 2])
206+
207+
with pytest.raises((TypeError, ValueError)):
208+
ax.set_prop_cycle('color', 'fish')
209+
210+
with pytest.raises((TypeError, ValueError)):
211+
ax.set_prop_cycle('linewidth', 1)
212+
with pytest.raises((TypeError, ValueError)):
213+
ax.set_prop_cycle('linewidth', {'1': 1, '2': 2})
214+
with pytest.raises((TypeError, ValueError)):
215+
ax.set_prop_cycle(linewidth=1, color='r')
216+
217+
with pytest.raises((TypeError, ValueError)):
218+
ax.set_prop_cycle('foobar', [1, 2])
219+
with pytest.raises((TypeError, ValueError)):
220+
ax.set_prop_cycle(foobar=[1, 2])
221+
222+
with pytest.raises((TypeError, ValueError)):
223+
ax.set_prop_cycle(cycler(foobar=[1, 2]))
224+
with pytest.raises(ValueError):
225+
ax.set_prop_cycle(cycler(color='rgb', c='cmy'))

‎lib/matplotlib/tests/test_dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_dates.py
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
except ImportError:
1818
import mock
1919

20-
from numpy.testing import assert_raises, assert_equal
20+
from numpy.testing import assert_equal
2121

2222
from matplotlib.testing.decorators import image_comparison, cleanup
2323
import matplotlib.pyplot as plt
@@ -108,7 +108,8 @@ def test_too_many_date_ticks():
108108
ax.set_xlim((t0, tf), auto=True)
109109
ax.plot([], [])
110110
ax.xaxis.set_major_locator(mdates.DayLocator())
111-
assert_raises(RuntimeError, fig.savefig, 'junk.png')
111+
with pytest.raises(RuntimeError):
112+
fig.savefig('junk.png')
112113

113114

114115
@image_comparison(baseline_images=['RRuleLocator_bounds'], extensions=['png'])
@@ -266,7 +267,8 @@ def test_empty_date_with_year_formatter():
266267
ax.xaxis.set_major_formatter(yearFmt)
267268

268269
with tempfile.TemporaryFile() as fh:
269-
assert_raises(ValueError, fig.savefig, fh)
270+
with pytest.raises(ValueError):
271+
fig.savefig(fh)
270272

271273

272274
def test_auto_date_locator():
@@ -453,10 +455,14 @@ def tz_convert(*args):
453455

454456

455457
def test_DayLocator():
456-
assert_raises(ValueError, mdates.DayLocator, interval=-1)
457-
assert_raises(ValueError, mdates.DayLocator, interval=-1.5)
458-
assert_raises(ValueError, mdates.DayLocator, interval=0)
459-
assert_raises(ValueError, mdates.DayLocator, interval=1.3)
458+
with pytest.raises(ValueError):
459+
mdates.DayLocator(interval=-1)
460+
with pytest.raises(ValueError):
461+
mdates.DayLocator(interval=-1.5)
462+
with pytest.raises(ValueError):
463+
mdates.DayLocator(interval=0)
464+
with pytest.raises(ValueError):
465+
mdates.DayLocator(interval=1.3)
460466
mdates.DayLocator(interval=1.0)
461467

462468

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import os
77
import warnings
88

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

1312
from matplotlib.testing.decorators import (image_comparison,
1413
knownfailureif, cleanup)
15-
from matplotlib.image import (BboxImage, imread, NonUniformImage,
16-
AxesImage, FigureImage, PcolorImage)
14+
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
15+
NonUniformImage, PcolorImage)
1716
from matplotlib.transforms import Bbox, Affine2D, TransformedBbox
1817
from matplotlib import rcParams, rc_context
1918
from matplotlib import patches

‎lib/matplotlib/tests/test_legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_legend.py
-5Lines 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_lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_lines.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import itertools
88
import matplotlib.lines as mlines
9-
from numpy.testing import assert_raises
9+
import pytest
1010
from timeit import repeat
1111
import numpy as np
1212
from cycler import cycler
@@ -109,7 +109,7 @@ def test_linestyle_variants():
109109
@cleanup
110110
def test_valid_linestyles():
111111
line = mlines.Line2D([], [])
112-
with assert_raises(ValueError):
112+
with pytest.raises(ValueError):
113113
line.set_linestyle('aardvark')
114114

115115

@@ -130,7 +130,7 @@ def test_drawstyle_variants():
130130
@cleanup
131131
def test_valid_drawstyles():
132132
line = mlines.Line2D([], [])
133-
with assert_raises(ValueError):
133+
with pytest.raises(ValueError):
134134
line.set_drawstyle('foobar')
135135

136136

‎lib/matplotlib/tests/test_mlab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_mlab.py
-10Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_offsetbox.py
+2-7Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_patches.py
+3-10Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_path.py
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
unicode_literals)
33
import copy
44

5-
import six
6-
75
import numpy as np
86

97
from numpy.testing import assert_array_equal
8+
import pytest
109

1110
from matplotlib.path import Path
1211
from matplotlib.patches import Polygon
13-
from nose.tools import assert_raises, assert_equal
1412
from matplotlib.testing.decorators import image_comparison
1513
import matplotlib.pyplot as plt
1614
from matplotlib import transforms
@@ -22,7 +20,8 @@ def test_readonly_path():
2220
def modify_vertices():
2321
path.vertices = path.vertices * 2.0
2422

25-
assert_raises(AttributeError, modify_vertices)
23+
with pytest.raises(AttributeError):
24+
modify_vertices()
2625

2726

2827
def test_point_in_path():
@@ -90,7 +89,7 @@ def test_make_compound_path_empty():
9089
# We should be able to make a compound path with no arguments.
9190
# This makes it easier to write generic path based code.
9291
r = Path.make_compound_path()
93-
assert_equal(r.vertices.shape, (0, 2))
92+
assert r.vertices.shape == (0, 2)
9493

9594

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.