8000 Suppress warnings in tests. · matplotlib/matplotlib@24cb5a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 24cb5a0

Browse files
committed
Suppress warnings in tests.
Handles - stem(..., use_line_collection=True). - deprecation of cbook.dedent, cbook.is_hashable, mlab.demean, transforms.Log10Transform. Explicitly check for numpy's warning when imshow()ing an image with only nans. Catch an "expected" warning in test_ttconv (the warning is only emitted when the figure is being saved, so we can't actually assert it).
1 parent a7a3f2a commit 24cb5a0

File tree

9 files changed

+32
-30
lines changed

9 files changed

+32
-30
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,10 +3091,10 @@ def test_stem_args():
30913091
y = list(range(10))
30923092

30933093
# Test the call signatures
3094-
ax.stem(y)
3095-
ax.stem(x, y)
3096-
ax.stem(x, y, 'r--')
3097-
ax.stem(x, y, 'r--', basefmt='b--')
3094+
ax.stem(y, use_line_collection=True)
3095+
ax.stem(x, y, use_line_collection=True)
3096+
ax.stem(x, y, 'r--', use_line_collection=True)
3097+
ax.stem(x, y, 'r--', basefmt='b--', use_line_collection=True)
30983098

30993099

31003100
def test_stem_dates():
@@ -3106,7 +3106,7 @@ def test_stem_dates():
31063106
x1 = parser.parse("2013-9-28 12:00:00")
31073107
y1 = 200
31083108

3109-
ax.stem([x, x1], [y, y1], "*-")
3109+
ax.stem([x, x1], [y, y1], "*-", use_line_collection=True)
31103110

31113111

31123112
@image_comparison(baseline_images=['hist_stacked_stepfilled_alpha'])

lib/matplotlib/tests/test_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import builtins
22
import subprocess
33
import sys
4+
import textwrap
45

56
import matplotlib
6-
from matplotlib.cbook import dedent
77

88

99
def test_simple():
@@ -36,7 +36,7 @@ def test_override_builtins():
3636

3737

3838
def test_lazy_imports():
39-
source = dedent("""
39+
source = textwrap.dedent("""
4040
import sys
4141
4242
import matplotlib.figure

lib/matplotlib/tests/test_cbook.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919

2020
def test_is_hashable():
21-
s = 'string'
22-
assert cbook.is_hashable(s)
23-
24-
lst = ['list', 'of', 'stings']
25-
assert not cbook.is_hashable(lst)
21+
with pytest.warns(MatplotlibDeprecationWarning):
22+
s = 'string'
23+
assert cbook.is_hashable(s)
24+
lst = ['list', 'of', 'stings']
25+
assert not cbook.is_hashable(lst)
2626

2727

2828
class Test_delete_masked_points(object):

lib/matplotlib/tests/test_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def test_stem_remove():
55
ax = plt.gca()
6-
st = ax.stem([1, 2], [1, 2])
6+
st = ax.stem([1, 2], [1, 2], use_line_collection=True)
77
st.remove()
88

99

lib/matplotlib/tests/test_image.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,10 @@ def test_imshow_bool():
943943

944944

945945
def test_full_invalid():
946-
x = np.ones((10, 10))
947-
x[:] = np.nan
948-
949-
f, ax = plt.subplots()
950-
ax.imshow(x)
951-
952-
f.canvas.draw()
946+
fig, ax = plt.subplots()
947+
ax.imshow(np.full((10, 10), np.nan))
948+
with pytest.warns(UserWarning):
949+
fig.canvas.draw()
953950

954951

955952
@pytest.mark.parametrize("fmt,counted",

lib/matplotlib/tests/test_mlab.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,8 @@ def test_detrend_1D_d1_ValueError(self):
908908

909909
def test_demean_1D_d1_ValueError(self):
910910
input = self.sig_slope
911-
with pytest.raises(ValueError):
911+
with pytest.raises(ValueError), \
912+
pytest.warns(MatplotlibDeprecationWarning):
912913
mlab.demean(input, axis=1)
913914

914915
def test_detrend_mean_2D_d2_ValueError(self):
@@ -923,7 +924,8 @@ def test_detrend_2D_d2_ValueError(self):
923924

924925
def test_demean_2D_d2_ValueError(self):
925926
input = self.sig_slope[np.newaxis]
926-
with pytest.raises(ValueError):
927+
with pytest.raises(ValueError), \
928+
pytest.warns(MatplotlibDeprecationWarning):
927929
mlab.demean(input, axis=2)
928930

929931
def test_detrend_linear_0D_zeros(self):

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,5 @@ def test_collapsed():
324324
p2 = ax.get_position()
325325
assert p1.width == p2.width
326326
# test that passing a rect doesn't crash...
327-
plt.tight_layout(rect=[0, 0, 0.8, 0.8])
327+
with pytest.warns(UserWarning):
328+
plt.tight_layout(rect=[0, 0, 0.8, 0.8])

lib/matplotlib/tests/test_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ def test_clipping_of_log():
186186
path = Path(points, codes)
187187

188188
# something like this happens in plotting logarithmic histograms
189-
trans = mtransforms.BlendedGenericTransform(mtransforms.Affine2D(),
190-
LogScale.Log10Transform('clip'))
189+
trans = mtransforms.BlendedGenericTransform(
190+
mtransforms.Affine2D(), LogScale.LogTransform(10, 'clip'))
191191
tpath = trans.transform_path_non_affine(path)
192192
result = tpath.iter_segments(trans.get_affine(),
193193
clip=(0, 0, 100, 100),

lib/matplotlib/tests/test_ttconv.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
from pathlib import Path
2+
13
import matplotlib
24
from matplotlib.font_manager import FontProperties
35
from matplotlib.testing.decorators import image_comparison
46
import matplotlib.pyplot as plt
5-
import os.path
67

78

89
@image_comparison(baseline_images=["truetype-conversion"],
910
extensions=["pdf"])
10-
def test_truetype_conversion():
11-
fontname = os.path.join(os.path.dirname(__file__), 'mpltest.ttf')
12-
fontname = os.path.abspath(fontname)
13-
fontprop = FontProperties(fname=fontname, size=80)
11+
# mpltest.ttf does not have "l"/"p" glyphs so we get a warning when trying to
12+
# get the font extents.
13+
def test_truetype_conversion(recwarn):
14+
fontprop = FontProperties(
15+
fname=str(Path(__file__).with_name('mpltest.ttf').resolve()), size=80)
1416
matplotlib.rcParams['pdf.fonttype'] = 3
1517
fig, ax = plt.subplots()
1618
ax.text(0, 0, "ABCDE", fontproperties=fontprop)

0 commit comments

Comments
 (0)
0