From 7cfdec73513e6862838579c0f3e2b9662e6bf7b2 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 27 Sep 2018 19:40:44 -0400 Subject: [PATCH 1/6] Fix invalid string escape sequences. --- lib/matplotlib/tests/test_text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 17e33698fd36..f71b2eb16d9d 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -134,8 +134,8 @@ def test_multiline2(): ax.set_xlim([0, 1.4]) ax.set_ylim([0, 2]) ax.axhline(0.5, color='C2', linewidth=0.3) - sts = ['Line', '2 Lineg\n 2 Lg', '$\sum_i x $', 'hi $\sum_i x $\ntest', - 'test\n $\sum_i x $', '$\sum_i x $\n $\sum_i x $'] + sts = ['Line', '2 Lineg\n 2 Lg', '$\\sum_i x $', 'hi $\\sum_i x $\ntest', + 'test\n $\\sum_i x $', '$\\sum_i x $\n $\\sum_i x $'] renderer = fig.canvas.get_renderer() def draw_box(ax, tt): From fb6a04834edfd77627bf5e1efe57f971ab14d98a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 27 Sep 2018 19:45:25 -0400 Subject: [PATCH 2/6] Use _log.warning instead of deprecated _log.warn. --- lib/matplotlib/dates.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index a229e09f5e63..41f78ca98abb 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1348,10 +1348,9 @@ def get_locator(self, dmin, dmax): else: locator = MicrosecondLocator(interval, tz=self.tz) if dmin.year > 20 and interval < 1000: - _log.warn('Plotting microsecond time intervals is not' - ' well supported. Please see the' - ' MicrosecondLocator documentation' - ' for details.') + _log.warning('Plotting microsecond time intervals is not well ' + 'supported. Please see the MicrosecondLocator ' + 'documentation for details.') locator.set_axis(self.axis) From 15ca02f441913428d3bd40c81f034132d5152b8a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 27 Sep 2018 19:46:56 -0400 Subject: [PATCH 3/6] Replace deprecated np.fromstring with np.frombuffer. --- lib/matplotlib/backends/backend_agg.py | 2 +- lib/matplotlib/image.py | 4 ++-- lib/matplotlib/tests/test_mathtext.py | 2 +- lib/matplotlib/tests/test_simplification.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index c4d93d9a9a89..fd262c2bb710 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -356,7 +356,7 @@ def post_processing(image, dpi): self._update_methods() if w > 0 and h > 0: - img = np.fromstring(buffer, np.uint8) + img = np.frombuffer(buffer, np.uint8) img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255., self.dpi) gc = self.new_gc() diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index b9f5d5ae4930..1641bac9cc0e 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1460,9 +1460,9 @@ def pil_to_array(pilImage): # return MxN luminance array of uint16 raw = pilImage.tobytes('raw', pilImage.mode) if pilImage.mode.endswith('B'): - x = np.fromstring(raw, '>u2') + x = np.frombuffer(raw, '>u2') else: - x = np.fromstring(raw, ' Date: Thu, 27 Sep 2018 22:05:18 -0400 Subject: [PATCH 4/6] Handle pytest's new ParameterSet for markers. Using pytest.param(..., marks=pytest.mark.something) is a different type than if using pytest.mark.something(...), so we need to handle that case on skipping extensions. --- lib/matplotlib/testing/decorators.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index cddb910e12fa..c2fd1c50b1cc 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -158,12 +158,18 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): if isinstance(extension, str): - will_fail = extension not in comparable_formats() + name = extension + elif isinstance(extension, tuple): + # Extension might be a pytest ParameterSet instead of a plain string. + # Unfortunately, this type is not exposed, so since it's a namedtuple, + # check for a tuple instead. + name = extension.values[0] else: # Extension might be a pytest marker instead of a plain string. - will_fail = extension.args[0] not in comparable_formats() - if will_fail: - fail_msg = 'Cannot compare %s files on this system' % extension + name = extension.args[0] + + if name not in comparable_formats(): + fail_msg = 'Cannot compare %s files on this system' % (name, ) import pytest return pytest.mark.xfail(extension, reason=fail_msg, strict=False, raises=ImageComparisonFailure) From 46d3860f1d0509d7dd0afc50b044fd482543b317 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 28 Sep 2018 03:40:37 -0400 Subject: [PATCH 5/6] TST: Use new method for applying pytest markers. --- lib/matplotlib/testing/decorators.py | 8 ++++++-- lib/mpl_toolkits/tests/test_mplot3d.py | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index c2fd1c50b1cc..d606a9666999 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -159,20 +159,24 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): if isinstance(extension, str): name = extension + marks = [] elif isinstance(extension, tuple): # Extension might be a pytest ParameterSet instead of a plain string. # Unfortunately, this type is not exposed, so since it's a namedtuple, # check for a tuple instead. name = extension.values[0] + marks = list(extension.marks) else: # Extension might be a pytest marker instead of a plain string. name = extension.args[0] + marks = [extension.mark] if name not in comparable_formats(): fail_msg = 'Cannot compare %s files on this system' % (name, ) import pytest - return pytest.mark.xfail(extension, reason=fail_msg, strict=False, - raises=ImageComparisonFailure) + marks += [pytest.mark.xfail(reason=fail_msg, strict=False, + raises=ImageComparisonFailure)] + return pytest.param(name, marks=marks) else: return extension diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 908de75777a1..880553d8882c 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -133,9 +133,10 @@ def test_lines3d(): # Reason for flakiness of SVG test is still unknown. -@image_comparison(baseline_images=['mixedsubplot'], remove_text=True, - extensions=['png', 'pdf', - pytest.mark.xfail('svg', strict=False)]) +@image_comparison( + baseline_images=['mixedsubplot'], remove_text=True, + extensions=['png', 'pdf', + pytest.param('svg', marks=pytest.mark.xfail(strict=False))]) def test_mixedsubplots(): def f(t): s1 = np.cos(2*np.pi*t) From d82d0f7a2b40a36af8330909d927b3edf16f418c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 28 Sep 2018 04:41:22 -0400 Subject: [PATCH 6/6] TST: Catch warnings when looking for optional deps. --- lib/matplotlib/tests/test_backend_pdf.py | 9 ++++++--- lib/matplotlib/tests/test_backend_ps.py | 15 +++++++++------ lib/matplotlib/tests/test_backend_svg.py | 9 ++++++--- lib/matplotlib/tests/test_text.py | 8 +++++--- lib/matplotlib/tests/test_usetex.py | 12 ++++++++++-- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index a0bfe6213e73..04102640ff7b 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -2,6 +2,7 @@ import os import sys import tempfile +import warnings import numpy as np import pytest @@ -14,9 +15,11 @@ _determinism_check) -needs_usetex = pytest.mark.skipif( - not checkdep_usetex(True), - reason="This test needs a TeX installation") +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + needs_usetex = pytest.mark.skipif( + not checkdep_usetex(True), + reason="This test needs a TeX installation") @image_comparison(baseline_images=['pdf_use14corefonts'], diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index dfa4747ae518..a8237f77f094 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -3,6 +3,7 @@ from pathlib import Path import re import tempfile +import warnings import pytest @@ -14,12 +15,14 @@ _determinism_check) -needs_ghostscript = pytest.mark.skipif( - matplotlib.checkdep_ghostscript()[0] is None, - reason="This test needs a ghostscript installation") -needs_usetex = pytest.mark.skipif( - not matplotlib.checkdep_usetex(True), - reason="This test needs a TeX installation") +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + needs_ghostscript = pytest.mark.skipif( + matplotlib.checkdep_ghostscript()[0] is None, + reason="This test needs a ghostscript installation") + needs_usetex = pytest.mark.skipif( + not matplotlib.checkdep_usetex(True), + reason="This test needs a TeX installation") # This tests tends to hit a TeX cache lock on AppVeyor. diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 1c06821841cb..9fce1fa84d68 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -2,6 +2,7 @@ from io import BytesIO import os import tempfile +import warnings import xml.parsers.expat import pytest @@ -12,9 +13,11 @@ from matplotlib import dviread -needs_usetex = pytest.mark.skipif( - not matplotlib.checkdep_usetex(True), - reason="This test needs a TeX installation") +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + needs_usetex = pytest.mark.skipif( + not matplotlib.checkdep_usetex(True), + reason="This test needs a TeX installation") def test_visibility(): diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index f71b2eb16d9d..19e00be77c5b 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -11,9 +11,11 @@ from matplotlib.testing.decorators import image_comparison -needs_usetex = pytest.mark.skipif( - not matplotlib.checkdep_usetex(True), - reason="This test needs a TeX installation") +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + needs_usetex = pytest.mark.skipif( + not matplotlib.checkdep_usetex(True), + reason="This test needs a TeX installation") @image_comparison(baseline_images=['font_styles']) diff --git a/lib/matplotlib/tests/test_usetex.py b/lib/matplotlib/tests/test_usetex.py index ebdb6a726de4..644493279d30 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -1,3 +1,5 @@ +import warnings + import pytest import matplotlib @@ -5,8 +7,14 @@ import matplotlib.pyplot as plt -@pytest.mark.skipif(not matplotlib.checkdep_usetex(True), - reason='Missing TeX or Ghostscript or dvipng') +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + needs_usetex = pytest.mark.skipif( + not matplotlib.checkdep_usetex(True), + reason='Missing TeX of Ghostscript or dvipng') + + +@needs_usetex @image_comparison(baseline_images=['test_usetex'], extensions=['pdf', 'png'], tol=0.3)