Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd75c01

Browse files
committed
Filter warnings in rcparams test.
1 parent 0287479 commit cd75c01

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

lib/matplotlib/tests/test_rcparams.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77
import sys
8+
import warnings
89

910
import matplotlib as mpl
1011
from matplotlib.tests import assert_str_equal
@@ -97,29 +98,31 @@ def test_RcParams_class():
9798

9899
def test_Bug_2543():
99100
# Test that it possible to add all values to itself / deepcopy
100-
# This was not possible because validate_bool_maybe_none did not
101+
# This was not possible because validate_bool_maybe_none did not
101102
# accept None as an argument.
102103
# https://github.com/matplotlib/matplotlib/issues/2543
103-
with mpl.rc_context():
104-
_copy = mpl.rcParams.copy()
105-
for key in six.iterkeys(_copy):
106-
mpl.rcParams[key] = _copy[key]
107-
mpl.rcParams['text.dvipnghack'] = None
108-
with mpl.rc_context():
109-
from copy import deepcopy
110-
_deep_copy = deepcopy(mpl.rcParams)
111-
from matplotlib.rcsetup import validate_bool_maybe_none, validate_bool
112-
# real test is that this does not raise
113-
assert_true(validate_bool_maybe_none(None) is None)
114-
assert_true(validate_bool_maybe_none("none") is None)
115-
_fonttype = mpl.rcParams['svg.fonttype']
116-
assert_true(_fonttype == mpl.rcParams['svg.embed_char_paths'])
117-
with mpl.rc_context():
118-
mpl.rcParams['svg.embed_char_paths'] = False
119-
assert_true(mpl.rcParams['svg.fonttype'] == "none")
104+
with warnings.catch_warnings():
105+
warnings.filterwarnings('ignore', message='.*(deprecated|obsolete)', category=UserWarning)
106+
with mpl.rc_context():
107+
_copy = mpl.rcParams.copy()
108+
for key in six.iterkeys(_copy):
109+
mpl.rcParams[key] = _copy[key]
110+
mpl.rcParams['text.dvipnghack'] = None
111+
with mpl.rc_context():
112+
from copy import deepcopy
113+
_deep_copy = deepcopy(mpl.rcParams)
114+
from matplotlib.rcsetup import validate_bool_maybe_none, validate_bool
115+
# real test is that this does not raise
116+
assert_true(validate_bool_maybe_none(None) is None)
117+
assert_true(validate_bool_maybe_none("none") is None)
118+
_fonttype = mpl.rcParams['svg.fonttype']
119+
assert_true(_fonttype == mpl.rcParams['svg.embed_char_paths'])
120+
with mpl.rc_context():
121+
mpl.rcParams['svg.embed_char_paths'] = False
122+
assert_true(mpl.rcParams['svg.fonttype'] == "none")
120123

121124
def test_Bug_2543_newer_python():
122-
# only split from above because of the usage of assert_raises
125+
# only split from above because of the usage of assert_raises
123126
# as a context manager, which only works in 2.7 and above
124127
if sys.version_info[:2] < (2, 7):
125128
raise nose.SkipTest("assert_raises as context manager not supported with Python < 2.7")
@@ -130,8 +133,8 @@ def test_Bug_2543_newer_python():
130133
validate_bool(None)
131134
with assert_raises(ValueError):
132135
with mpl.rc_context():
133-
mpl.rcParams['svg.fonttype'] = True
134-
136+
mpl.rcParams['svg.fonttype'] = True
137+
135138
if __name__ == '__main__':
136139
import nose
137140
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)