Skip to content

Fixed warnings catching and counting with warnings.catch_warnings #6761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,7 @@ def test_eventplot_problem_kwargs():
axobj = fig.add_subplot(111)

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

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
mylist = [10] * 100
fig, ax = plt.subplots(1, 1)
ax.hexbin(mylist, mylist)
Expand Down Expand Up @@ -4236,10 +4238,11 @@ def test_errorbar_inputs_shotgun():
def test_axisbg_warning():
fig = plt.figure()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
ax = matplotlib.axes.Axes(fig, [0, 0, 1, 1], axisbg='r')
assert len(w) == 1
assert (str(w[0].message).startswith(
("The axisbg attribute was deprecated in version 2.0.")))
assert len(w) == 1
msg = "The axisbg attribute was deprecated in version 2.0."
assert str(w[0].message).startswith(msg)


@image_comparison(baseline_images=["dash_offset"], remove_text=True)
Expand Down
17 changes: 10 additions & 7 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ def test_contourf_decreasing_levels():
# Legacy contouring algorithm gives a warning rather than raising an error,
# plus a DeprecationWarning.
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
plt.contourf(z, [1.0, 0.0], corner_mask='legacy')
assert_equal(len(w), 2)
assert_equal(len(w), 2)


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

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
cs.vmin
assert len(w) == 1
assert (str(w[0].message).startswith(
("vmin is deprecated and will be removed in 2.2 ")))
assert len(w) == 1
msg = "vmin is deprecated and will be removed in 2.2 "
assert str(w[0].message).startswith(msg)

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
cs.vmax
assert len(w) == 1
assert (str(w[0].message).startswith(
("vmax is deprecated and will be removed in 2.2 ")))
assert len(w) == 1
msg = "vmax is deprecated and will be removed in 2.2 "
assert str(w[0].message).startswith(msg)


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from six.moves import xrange

from nose.tools import assert_equal, assert_true
from matplotlib import rcParams
from matplotlib.testing.decorators import image_comparison, cleanup
from matplotlib.axes import Axes
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -124,9 +125,10 @@ def test_too_many_figures():
import warnings

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


def test_iterability_axes_argument():
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_NullLocator_set_params():
"""
loc = mticker.NullLocator()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
loc.set_params()
nose.tools.assert_equal(len(w), 1)

Expand Down