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 dda6023

Browse filesBrowse files
committed
Replace np.testing.assert_raises with pytest.raises.
The former requires nose.
1 parent 0044829 commit dda6023
Copy full SHA for dda6023

File tree

Expand file treeCollapse file tree

6 files changed

+51
-37
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+51
-37
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,6 @@ def _jupyter_nbextension_paths():
14771477
'matplotlib.tests.test_png',
14781478
'matplotlib.tests.test_units',
14791479
'matplotlib.tests.test_widgets',
1480-
'matplotlib.tests.test_cycles',
14811480
]
14821481

14831482

‎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_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

0 commit comments

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