Skip to content

Commit 5491777

Browse files
committed
Fixed warnings catching and counting with warnings.catch_warnings
1 parent c718e61 commit 5491777

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

lib/matplotlib/tests/test_axes.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,7 @@ def test_eventplot_problem_kwargs():
26662666
axobj = fig.add_subplot(111)
26672667

26682668
with warnings.catch_warnings(record=True) as w:
2669+
warnings.simplefilter("always")
26692670
colls = axobj.eventplot(data,
26702671
colors=['r', 'b'],
26712672
color=['c', 'm'],
@@ -4017,6 +4018,7 @@ def test_pathological_hexbin():
40174018
out = io.BytesIO()
40184019

40194020
with warnings.catch_warnings(record=True) as w:
4021+
warnings.simplefilter("always")
40204022
mylist = [10] * 100
40214023
fig, ax = plt.subplots(1, 1)
40224024
ax.hexbin(mylist, mylist)
@@ -4236,10 +4238,11 @@ def test_errorbar_inputs_shotgun():
42364238
def test_axisbg_warning():
42374239
fig = plt.figure()
42384240
with warnings.catch_warnings(record=True) as w:
4241+
warnings.simplefilter("always")
42394242
ax = matplotlib.axes.Axes(fig, [0, 0, 1, 1], axisbg='r')
4240-
assert len(w) == 1
4241-
assert (str(w[0].message).startswith(
4242-
("The axisbg attribute was deprecated in version 2.0.")))
4243+
assert len(w) == 1
4244+
msg = "The axisbg attribute was deprecated in version 2.0."
4245+
assert str(w[0].message).startswith(msg)
42434246

42444247

42454248
@image_comparison(baseline_images=["dash_offset"], remove_text=True)

lib/matplotlib/tests/test_contour.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ def test_contourf_decreasing_levels():
288288
# Legacy contouring algorithm gives a warning rather than raising an error,
289289
# plus a DeprecationWarning.
290290
with warnings.catch_warnings(record=True) as w:
291+
warnings.simplefilter("always")
291292
plt.contourf(z, [1.0, 0.0], corner_mask='legacy')
292-
assert_equal(len(w), 2)
293+
assert_equal(len(w), 2)
293294

294295

295296
@cleanup
@@ -299,16 +300,18 @@ def test_vminvmax_warning():
299300
cs = plt.contourf(z, [0.0, 1.0])
300301

301302
with warnings.catch_warnings(record=True) as w:
303+
warnings.simplefilter("always")
302304
cs.vmin
303-
assert len(w) == 1
304-
assert (str(w[0].message).startswith(
305-
("vmin is deprecated and will be removed in 2.2 ")))
305+
assert len(w) == 1
306+
msg = "vmin is deprecated and will be removed in 2.2 "
307+
assert str(w[0].message).startswith(msg)
306308

307309
with warnings.catch_warnings(record=True) as w:
310+
warnings.simplefilter("always")
308311
cs.vmax
309-
assert len(w) == 1
310-
assert (str(w[0].message).startswith(
311-
("vmax is deprecated and will be removed in 2.2 ")))
312+
assert len(w) == 1
313+
msg = "vmax is deprecated and will be removed in 2.2 "
314+
assert str(w[0].message).startswith(msg)
312315

313316

314317
if __name__ == '__main__':

lib/matplotlib/tests/test_figure.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from six.moves import xrange
66

77
from nose.tools import assert_equal, assert_true
8+
from matplotlib import rcParams
89
from matplotlib.testing.decorators import image_comparison, cleanup
910
from matplotlib.axes import Axes
1011
import matplotlib.pyplot as plt
@@ -124,9 +125,10 @@ def test_too_many_figures():
124125
import warnings
125126

126127
with warnings.catch_warnings(record=True) as w:
127-
for i in range(22):
128+
warnings.simplefilter("always")
129+
for i in range(rcParams['figure.max_open_warning'] + 1):
128130
fig = plt.figure()
129-
assert len(w) == 1
131+
assert len(w) == 1
130132

131133

132134
def test_iterability_axes_argument():

lib/matplotlib/tests/test_ticker.py

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_NullLocator_set_params():
9797
"""
9898
loc = mticker.NullLocator()
9999
with warnings.catch_warnings(record=True) as w:
100+
warnings.simplefilter("always")
100101
loc.set_params()
101102
nose.tools.assert_equal(len(w), 1)
102103

0 commit comments

Comments
 (0)