Skip to content

Commit e36fe9a

Browse files
authored
Merge pull request #11705 from anntzer/warningslesstests
MNT: Suppress/fix some test warnings.
2 parents 42f07d9 + c9a8edb commit e36fe9a

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,8 @@ def _transform(self, a):
11111111
"""
11121112
Inplace transformation.
11131113
"""
1114-
masked = np.abs(a) > self.linthresh
1114+
with np.errstate(invalid="ignore"):
1115+
masked = np.abs(a) > self.linthresh
11151116
sign = np.sign(a[masked])
11161117
log = (self._linscale_adj + np.log(np.abs(a[masked]) / self.linthresh))
11171118
log *= sign * self.linthresh

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ def test_scatter_marker(self):
17141714
c=[(1, 0, 0), 'y', 'b', 'lime'],
17151715
s=[60, 50, 40, 30],
17161716
edgecolors=['k', 'r', 'g', 'b'],
1717-
verts=verts)
1717+
marker=verts)
17181718

17191719
@image_comparison(baseline_images=['scatter_2D'], remove_text=True,
17201720
extensions=['png'])

lib/matplotlib/tests/test_font_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def test_otf():
6767
if os.path.exists(fname):
6868
assert is_opentype_cff_font(fname)
6969

70-
otf_files = [f for f in fontManager.ttffiles if 'otf' in f]
71-
for f in otf_files:
72-
with open(f, 'rb') as fd:
73-
res = fd.read(4) == b'OTTO'
74-
assert res == is_opentype_cff_font(f)
70+
for f in fontManager.ttflist:
71+
if 'otf' in f.fname:
72+
with open(f.fname, 'rb') as fd:
73+
res = fd.read(4) == b'OTTO'
74+
assert res == is_opentype_cff_font(f.fname)
7575

7676

7777
@pytest.mark.skipif(not has_fclist, reason='no fontconfig installed')

lib/matplotlib/tests/test_image.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import ExitStack
12
from copy import copy
23
import io
34
import os
@@ -875,8 +876,10 @@ def test_empty_imshow(make_norm):
875876
def test_imshow_float128():
876877
fig, ax = plt.subplots()
877878
ax.imshow(np.zeros((3, 3), dtype=np.longdouble))
878-
# Ensure that drawing doesn't cause crash
879-
fig.canvas.draw()
879+
with (ExitStack() if np.can_cast(np.longdouble, np.float64, "equiv")
880+
else pytest.warns(UserWarning)):
881+
# Ensure that drawing doesn't cause crash.
882+
fig.canvas.draw()
880883

881884

882885
def test_imshow_bool():

lib/matplotlib/tests/test_patches.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from numpy.testing import assert_almost_equal, assert_array_equal
66
import pytest
77

8+
from matplotlib.cbook import MatplotlibDeprecationWarning
89
from matplotlib.patches import Polygon, Rectangle
910
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1011
import matplotlib.pyplot as plt
@@ -344,8 +345,9 @@ def test_patch_str():
344345
s = mpatches.Shadow(p, 1, 1)
345346
assert str(s) == "Shadow(ConnectionPatch((1, 2), (3, 4)))"
346347

347-
p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1)
348-
assert str(p) == "YAArrow()"
348+
with pytest.warns(MatplotlibDeprecationWarning):
349+
p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1)
350+
assert str(p) == "YAArrow()"
349351

350352
# Not testing Arrow, FancyArrow here
351353
# because they seem to exist only for historical reasons.

lib/matplotlib/tests/test_rcparams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
import matplotlib as mpl
13+
from matplotlib.cbook import MatplotlibDeprecationWarning
1314
import matplotlib.pyplot as plt
1415
import matplotlib.colors as mcolors
1516
import numpy as np
@@ -120,8 +121,7 @@ def test_Bug_2543():
120121
# printed in the test suite.
121122
with warnings.catch_warnings():
122123
warnings.filterwarnings('ignore',
123-
message='.*(deprecated|obsolete)',
124-
category=UserWarning)
124+
category=MatplotlibDeprecationWarning)
125125
with mpl.rc_context():
126126
_copy = mpl.rcParams.copy()
127127
for key in _copy:

0 commit comments

Comments
 (0)