From c9a8edb31bfabb4a98e2bacb4ee828395201b0d7 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 19 Jul 2018 11:23:40 +0200 Subject: [PATCH] Suppress/fix some test warnings. The only remaining test that throws a warning is test_image.py::test_full_invalid ("converting a masked element to nan"), which I didn't suppress in the test because I think that should indeed not throw (we don't throw warnings when passing partially-nan data either). --- lib/matplotlib/colors.py | 3 ++- lib/matplotlib/tests/test_axes.py | 2 +- lib/matplotlib/tests/test_font_manager.py | 10 +++++----- lib/matplotlib/tests/test_image.py | 7 +++++-- lib/matplotlib/tests/test_patches.py | 6 ++++-- lib/matplotlib/tests/test_rcparams.py | 4 ++-- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index f7cfb0786539..2b42a988f735 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1112,7 +1112,8 @@ def _transform(self, a): """ Inplace transformation. """ - masked = np.abs(a) > self.linthresh + with np.errstate(invalid="ignore"): + masked = np.abs(a) > self.linthresh sign = np.sign(a[masked]) log = (self._linscale_adj + np.log(np.abs(a[masked]) / self.linthresh)) log *= sign * self.linthresh diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b952914c86f2..b6dd9298cf22 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1714,7 +1714,7 @@ def test_scatter_marker(self): c=[(1, 0, 0), 'y', 'b', 'lime'], s=[60, 50, 40, 30], edgecolors=['k', 'r', 'g', 'b'], - verts=verts) + marker=verts) @image_comparison(baseline_images=['scatter_2D'], remove_text=True, extensions=['png']) diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 703a4e6e3359..4e75aa5199c3 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -67,11 +67,11 @@ def test_otf(): if os.path.exists(fname): assert is_opentype_cff_font(fname) - otf_files = [f for f in fontManager.ttffiles if 'otf' in f] - for f in otf_files: - with open(f, 'rb') as fd: - res = fd.read(4) == b'OTTO' - assert res == is_opentype_cff_font(f) + for f in fontManager.ttflist: + if 'otf' in f.fname: + with open(f.fname, 'rb') as fd: + res = fd.read(4) == b'OTTO' + assert res == is_opentype_cff_font(f.fname) @pytest.mark.skipif(not has_fclist, reason='no fontconfig installed') diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 098705bea2b0..893108258b65 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -1,3 +1,4 @@ +from contextlib import ExitStack from copy import copy import io import os @@ -875,8 +876,10 @@ def test_empty_imshow(make_norm): def test_imshow_float128(): fig, ax = plt.subplots() ax.imshow(np.zeros((3, 3), dtype=np.longdouble)) - # Ensure that drawing doesn't cause crash - fig.canvas.draw() + with (ExitStack() if np.can_cast(np.longdouble, np.float64, "equiv") + else pytest.warns(UserWarning)): + # Ensure that drawing doesn't cause crash. + fig.canvas.draw() def test_imshow_bool(): diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 1d0319b138ba..89a77e258010 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -5,6 +5,7 @@ from numpy.testing import assert_almost_equal, assert_array_equal import pytest +from matplotlib.cbook import MatplotlibDeprecationWarning from matplotlib.patches import Polygon, Rectangle from matplotlib.testing.decorators import image_comparison, check_figures_equal import matplotlib.pyplot as plt @@ -344,8 +345,9 @@ def test_patch_str(): s = mpatches.Shadow(p, 1, 1) assert str(s) == "Shadow(ConnectionPatch((1, 2), (3, 4)))" - p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1) - assert str(p) == "YAArrow()" + with pytest.warns(MatplotlibDeprecationWarning): + p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1) + assert str(p) == "YAArrow()" # Not testing Arrow, FancyArrow here # because they seem to exist only for historical reasons. diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 020a8b1a6f84..7eec4d421105 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -10,6 +10,7 @@ import pytest import matplotlib as mpl +from matplotlib.cbook import MatplotlibDeprecationWarning import matplotlib.pyplot as plt import matplotlib.colors as mcolors import numpy as np @@ -120,8 +121,7 @@ def test_Bug_2543(): # printed in the test suite. with warnings.catch_warnings(): warnings.filterwarnings('ignore', - message='.*(deprecated|obsolete)', - category=UserWarning) + category=MatplotlibDeprecationWarning) with mpl.rc_context(): _copy = mpl.rcParams.copy() for key in _copy: