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 82ac087

Browse filesBrowse files
committed
Merge pull request #3244 from jenshnielsen/rcwarnings
Filter warnings in rcparams test (and others)
2 parents 98d19db + 827393e commit 82ac087
Copy full SHA for 82ac087

File tree

Expand file treeCollapse file tree

7 files changed

+93
-61
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+93
-61
lines changed

‎lib/matplotlib/tests/test_delaunay.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_delaunay.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
import six
55
from six.moves import xrange
6+
import warnings
67

78
import numpy as np
89
from matplotlib.testing.decorators import image_comparison, knownfailureif
9-
from matplotlib.delaunay.triangulate import Triangulation
10+
from matplotlib.cbook import MatplotlibDeprecationWarning
11+
12+
with warnings.catch_warnings():
13+
# the module is deprecated. The tests should be removed when the module is.
14+
warnings.simplefilter('ignore', MatplotlibDeprecationWarning)
15+
from matplotlib.delaunay.triangulate import Triangulation
1016
from matplotlib import pyplot as plt
1117
import matplotlib as mpl
1218

‎lib/matplotlib/tests/test_mlab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_mlab.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tempfile
77

88
from numpy.testing import assert_allclose, assert_array_equal
9+
import numpy.ma.testutils as matest
910
import numpy as np
1011
from nose.tools import (assert_equal, assert_almost_equal, assert_not_equal,
1112
assert_true, assert_raises)
@@ -2714,7 +2715,7 @@ def get_z(x, y):
27142715
z_masked = np.ma.array(z, mask=[False, False, False, True, False])
27152716
correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, get_z(xi, yi))
27162717
zi = mlab.griddata(x, y, z_masked, xi, yi, interp='linear')
2717-
np.testing.assert_array_almost_equal(zi, correct_zi_masked)
2718+
matest.assert_array_almost_equal(zi, correct_zi_masked)
27182719
np.testing.assert_array_equal(np.ma.getmask(zi),
27192720
np.ma.getmask(correct_zi_masked))
27202721

‎lib/matplotlib/tests/test_rcparams.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_rcparams.py
+29-21Lines changed: 29 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,36 @@ 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+
# We filter warnings at this stage since a number of them are raised
105+
# for deprecated rcparams as they should. We dont want these in the
106+
# printed in the test suite.
107+
with warnings.catch_warnings():
108+
warnings.filterwarnings('ignore',
109+
message='.*(deprecated|obsolete)',
110+
category=UserWarning)
111+
with mpl.rc_context():
112+
_copy = mpl.rcParams.copy()
113+
for key in six.iterkeys(_copy):
114+
mpl.rcParams[key] = _copy[key]
115+
mpl.rcParams['text.dvipnghack'] = None
116+
with mpl.rc_context():
117+
from copy import deepcopy
118+
_deep_copy = deepcopy(mpl.rcParams)
119+
from matplotlib.rcsetup import validate_bool_maybe_none, validate_bool
120+
# real test is that this does not raise
121+
assert_true(validate_bool_maybe_none(None) is None)
122+
assert_true(validate_bool_maybe_none("none") is None)
123+
_fonttype = mpl.rcParams['svg.fonttype']
124+
assert_true(_fonttype == mpl.rcParams['svg.embed_char_paths'])
125+
with mpl.rc_context():
126+
mpl.rcParams['svg.embed_char_paths'] = False
127+
assert_true(mpl.rcParams['svg.fonttype'] == "none")
120128

121129
def test_Bug_2543_newer_python():
122-
# only split from above because of the usage of assert_raises
130+
# only split from above because of the usage of assert_raises
123131
# as a context manager, which only works in 2.7 and above
124132
if sys.version_info[:2] < (2, 7):
125133
raise nose.SkipTest("assert_raises as context manager not supported with Python < 2.7")
@@ -130,8 +138,8 @@ def test_Bug_2543_newer_python():
130138
validate_bool(None)
131139
with assert_raises(ValueError):
132140
with mpl.rc_context():
133-
mpl.rcParams['svg.fonttype'] = True
134-
141+
mpl.rcParams['svg.fonttype'] = True
142+
135143
if __name__ == '__main__':
136144
import nose
137145
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

‎lib/matplotlib/tests/test_streamplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_streamplot.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def test_masks_and_nans():
4242
mask[40:60, 40:60] = 1
4343
U = np.ma.array(U, mask=mask)
4444
U[:20, :20] = np.nan
45-
plt.streamplot(X, Y, U, V, color=U, cmap=plt.cm.Blues)
45+
with np.errstate(invalid='ignore'):
46+
plt.streamplot(X, Y, U, V, color=U, cmap=plt.cm.Blues)
4647

4748

4849
@cleanup

‎lib/matplotlib/tests/test_subplots.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_subplots.py
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4+
import warnings
45
import six
56
from six.moves import xrange
67

@@ -105,10 +106,16 @@ def test_exceptions():
105106
# TODO should this test more options?
106107
assert_raises(ValueError, plt.subplots, 2, 2, sharex='blah')
107108
assert_raises(ValueError, plt.subplots, 2, 2, sharey='blah')
108-
assert_raises(ValueError, plt.subplots, 2, 2, -1)
109-
# uncomment this for 1.5
110-
# assert_raises(ValueError, plt.subplots, 2, 2, 0)
111-
assert_raises(ValueError, plt.subplots, 2, 2, 5)
109+
# We filter warnings in this test which are genuine since
110+
# the pount of this test is to ensure that this raises.
111+
with warnings.catch_warnings():
112+
warnings.filterwarnings('ignore',
113+
message='.*sharex\ argument\ to\ subplots',
114+
category=UserWarning)
115+
assert_raises(ValueError, plt.subplots, 2, 2, -1)
116+
# uncomment this for 1.5
117+
# assert_raises(ValueError, plt.subplots, 2, 2, 0)
118+
assert_raises(ValueError, plt.subplots, 2, 2, 5)
112119

113120

114121
@image_comparison(baseline_images=['subplots_offset_text'], remove_text=False)

‎lib/matplotlib/tests/test_tightlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_tightlayout.py
+37-30Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unicode_literals)
33

44
import six
5+
import warnings
56

67
import numpy as np
78

@@ -10,12 +11,14 @@
1011
from nose.tools import assert_raises
1112
from numpy.testing import assert_array_equal
1213

14+
1315
def example_plot(ax, fontsize=12):
14-
ax.plot([1, 2])
15-
ax.locator_params(nbins=3)
16-
ax.set_xlabel('x-label', fontsize=fontsize)
17-
ax.set_ylabel('y-label', fontsize=fontsize)
18-
ax.set_title('Title', fontsize=fontsize)
16+
ax.plot([1, 2])
17+
ax.locator_params(nbins=3)
18+
ax.set_xlabel('x-label', fontsize=fontsize)
19+
ax.set_ylabel('y-label', fontsize=fontsize)
20+
ax.set_title('Title', fontsize=fontsize)
21+
1922

2023
@image_comparison(baseline_images=['tight_layout1'])
2124
def test_tight_layout1():
@@ -81,50 +84,54 @@ def test_tight_layout5():
8184
fig = plt.figure()
8285

8386
ax = plt.subplot(111)
84-
arr = np.arange(100).reshape((10,10))
87+
arr = np.arange(100).reshape((10, 10))
8588
ax.imshow(arr, interpolation="none")
8689

8790
plt.tight_layout()
8891

8992

90-
9193
@image_comparison(baseline_images=['tight_layout6'])
9294
def test_tight_layout6():
9395
'Test tight_layout for gridspec'
9496

95-
fig = plt.figure()
97+
# This raises warnings since tight layout cannot
98+
# do this fully automatically. But the test is
99+
# correct since the layout is manually edited
100+
with warnings.catch_warnings():
101+
warnings.simplefilter("ignore", UserWarning)
102+
fig = plt.figure()
96103

97-
import matplotlib.gridspec as gridspec
104+
import matplotlib.gridspec as gridspec
98105

99-
gs1 = gridspec.GridSpec(2, 1)
100-
ax1 = fig.add_subplot(gs1[0])
101-
ax2 = fig.add_subplot(gs1[1])
106+
gs1 = gridspec.GridSpec(2, 1)
107+
ax1 = fig.add_subplot(gs1[0])
108+
ax2 = fig.add_subplot(gs1[1])
102109

103-
example_plot(ax1)
104-
example_plot(ax2)
110+
example_plot(ax1)
111+
example_plot(ax2)
105112

106-
gs1.tight_layout(fig, rect=[0, 0, 0.5, 1])
113+
gs1.tight_layout(fig, rect=[0, 0, 0.5, 1])
107114

108-
gs2 = gridspec.GridSpec(3, 1)
115+
gs2 = gridspec.GridSpec(3, 1)
109116

110-
for ss in gs2:
111-
ax = fig.add_subplot(ss)
112-
example_plot(ax)
113-
ax.set_title("")
114-
ax.set_xlabel("")
117+
for ss in gs2:
118+
ax = fig.add_subplot(ss)
119+
example_plot(ax)
120+
ax.set_title("")
121+
ax.set_xlabel("")
115122

116-
ax.set_xlabel("x-label", fontsize=12)
123+
ax.set_xlabel("x-label", fontsize=12)
117124

118-
gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45)
125+
gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45)
119126

120-
top = min(gs1.top, gs2.top)
121-
bottom = max(gs1.bottom, gs2.bottom)
127+
top = min(gs1.top, gs2.top)
128+
bottom = max(gs1.bottom, gs2.bottom)
122129

123-
gs1.tight_layout(fig, rect=[None, 0 + (bottom-gs1.bottom),
124-
0.5, 1 - (gs1.top-top)])
125-
gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom),
126-
None, 1 - (gs2.top-top)],
127-
h_pad=0.45)
130+
gs1.tight_layout(fig, rect=[None, 0 + (bottom-gs1.bottom),
131+
0.5, 1 - (gs1.top-top)])
132+
gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom),
133+
None, 1 - (gs2.top-top)],
134+
h_pad=0.45)
128135

129136

130137
@image_comparison(baseline_images=['tight_layout7'])

‎lib/matplotlib/tests/test_triangulation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_triangulation.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from nose.tools import assert_equal, assert_raises
1010
from numpy.testing import assert_array_equal, assert_array_almost_equal,\
1111
assert_array_less
12+
import numpy.ma.testutils as matest
1213
from matplotlib.testing.decorators import image_comparison
1314
import matplotlib.cm as cm
1415
from matplotlib.path import Path
@@ -323,7 +324,7 @@ def test_triinterp():
323324
xs, ys = np.meshgrid(xs, ys)
324325
for interp in (linear_interp, cubic_min_E, cubic_geom):
325326
zs = interp(xs, ys)
326-
assert_array_almost_equal(zs, (1.23*xs - 4.79*ys))
327+
matest.assert_array_almost_equal(zs, (1.23*xs - 4.79*ys))
327328
mask = (xs >= 1) * (xs <= 2) * (ys >= 1) * (ys <= 2)
328329
assert_array_equal(zs.mask, mask)
329330

@@ -697,7 +698,8 @@ def z(x, y):
697698
interp_z0[interp_key] = interp(xs0, ys0) # storage
698699
else:
699700
interpz = interp(xs, ys)
700-
assert_array_almost_equal(interpz, interp_z0[interp_key])
701+
matest.assert_array_almost_equal(interpz,
702+
interp_z0[interp_key])
701703

702704
scale_factor = 987654.3210
703705
for scaled_axis in ('x', 'y'):
@@ -723,7 +725,7 @@ def z(x, y):
723725
# 1 axis...
724726
for interp_key in ['lin', 'min_E', 'geom']:
725727
interpz = dic_interp[interp_key](xs, ys)
726-
assert_array_almost_equal(interpz, interp_z0[interp_key])
728+
matest.assert_array_almost_equal(interpz, interp_z0[interp_key])
727729

728730

729731
@image_comparison(baseline_images=['tri_smooth_contouring'],

0 commit comments

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