From d6fdeba944dfa65b7d243043101ff437f58f032a Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 21 Dec 2015 17:29:12 -0500 Subject: [PATCH] FIX: suppress warning in Artist.properties Calling `get_axes` currently raises a deprecating warning, eat this. The Artist.properties function will be completely re-written in 2.1 with traitlets so this is a reasonable stop-gap for now. closes #5089 --- lib/matplotlib/artist.py | 4 +++- lib/matplotlib/tests/test_artist.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index a4614f214299..244c0b666fb8 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -1276,7 +1276,9 @@ def properties(self): continue try: - val = func() + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + val = func() except: continue else: diff --git a/lib/matplotlib/tests/test_artist.py b/lib/matplotlib/tests/test_artist.py index 4f8fe30c9253..d2d5da078a42 100644 --- a/lib/matplotlib/tests/test_artist.py +++ b/lib/matplotlib/tests/test_artist.py @@ -1,6 +1,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) - +import warnings from matplotlib.externals import six import io @@ -9,6 +9,7 @@ import matplotlib.pyplot as plt import matplotlib.patches as mpatches +import matplotlib.lines as mlines import matplotlib.path as mpath import matplotlib.transforms as mtrans import matplotlib.collections as mcollections @@ -176,6 +177,16 @@ def test_remove(): assert_true(ax.stale) +@cleanup +def test_properties(): + ln = mlines.Line2D([], []) + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always") + ln.properties() + assert len(w) == 0 + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)