From f3f57b1b987441f874f85b278a4040c63e953e49 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 19 Sep 2018 04:38:11 -0400 Subject: [PATCH 01/16] Backport PR #12154: Avoid triggering deprecation warnings with pytest 3.8. --- .appveyor.yml | 2 +- .travis.yml | 4 +--- doc/devel/contributing.rst | 6 +++--- doc/devel/testing.rst | 4 ++-- lib/matplotlib/testing/conftest.py | 10 +++++----- setupext.py | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a163f42f115e..0d34fa4572f7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -66,7 +66,7 @@ install: - activate test-environment - echo %PYTHON_VERSION% %TARGET_ARCH% # pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124 - - pip install -q "pytest!=3.3.0,>=3.2.0,<3.8" "pytest-cov>=2.3.1" + - pip install -q "pytest>=3.6.0,<3.8" "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout pytest-xdist # Apply patch to `subprocess` on Python versions > 2 and < 3.6.3 diff --git a/.travis.yml b/.travis.yml index cbf1c9624684..cf3f09409c23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,8 +53,6 @@ env: - PANDAS= - PILLOW=pillow - PYPARSING=pyparsing - # pytest-timeout master depends on pytest>=3.6. Testing with pytest 3.1 is - # still supported; this is tested by the first matrix entry. - PYTEST='pytest>=3.6,<3.8' - PYTEST_COV=pytest-cov - PYTEST_RERUNFAILURES=pytest-rerunfailures @@ -80,7 +78,7 @@ matrix: - NUMPY=numpy==1.7.1 - PANDAS='pandas<0.21.0' - PYPARSING=pyparsing==2.0.1 - - PYTEST=pytest==3.1.0 + - PYTEST=pytest==3.6.0 - PYTEST_COV=pytest-cov==2.3.1 - PYTEST_TIMEOUT=pytest-timeout==1.2.1 # Newer pytest-timeouts don't support pytest <3.4. - PYTEST_RERUNFAILURES='pytest-rerunfailures<5' # 5 needs pytest>=3.6 diff --git a/doc/devel/contributing.rst b/doc/devel/contributing.rst index 35f376beea66..b8656535bc08 100644 --- a/doc/devel/contributing.rst +++ b/doc/devel/contributing.rst @@ -109,7 +109,7 @@ value. Installing Matplotlib in developer mode --------------------------------------- -To install Matplotlib (and compile the c-extensions) run the following +To install Matplotlib (and compile the C-extensions) run the following command from the top-level directory :: python -mpip install -ve . @@ -148,11 +148,11 @@ environment is set up properly:: .. _pep8: https://pep8.readthedocs.io/en/latest/ .. _mock: https://docs.python.org/dev/library/unittest.mock.html .. _Ghostscript: https://www.ghostscript.com/ -.. _Inkscape: https://inkscape.org> +.. _Inkscape: https://inkscape.org/ .. note:: - **Additional dependencies for testing**: pytest_ (version 3.1 or later), + **Additional dependencies for testing**: pytest_ (version 3.6 or later), mock_ (if Python 2), Ghostscript_, Inkscape_ .. seealso:: diff --git a/doc/devel/testing.rst b/doc/devel/testing.rst index 8334a132a74a..03ca5c9bdec6 100644 --- a/doc/devel/testing.rst +++ b/doc/devel/testing.rst @@ -22,11 +22,11 @@ Requirements Install the latest version of Matplotlib as documented in :ref:`installing_for_devs` In particular, follow the instructions to use a -local FreeType build +local FreeType build. The following software is required to run the tests: - - pytest_ (>=3.1) + - pytest_ (>=3.6) - mock_, when running Python 2 - Ghostscript_ (to render PDF files) - Inkscape_ (to render SVG files) diff --git a/lib/matplotlib/testing/conftest.py b/lib/matplotlib/testing/conftest.py index 9dc180c96000..fb3065947805 100644 --- a/lib/matplotlib/testing/conftest.py +++ b/lib/matplotlib/testing/conftest.py @@ -24,19 +24,19 @@ def mpl_test_settings(request): original_settings = matplotlib.rcParams.copy() backend = None - backend_marker = request.keywords.get('backend') + backend_marker = request.node.get_closest_marker('backend') if backend_marker is not None: assert len(backend_marker.args) == 1, \ "Marker 'backend' must specify 1 backend." - backend = backend_marker.args[0] + backend, = backend_marker.args prev_backend = matplotlib.get_backend() style = '_classic_test' # Default of cleanup and image_comparison too. - style_marker = request.keywords.get('style') + style_marker = request.node.get_closest_marker('style') if style_marker is not None: assert len(style_marker.args) == 1, \ "Marker 'style' must specify 1 style." - style = style_marker.args[0] + style, = style_marker.args matplotlib.testing.setup() if backend is not None: @@ -64,7 +64,7 @@ def mpl_image_comparison_parameters(request, extension): # pytest won't get confused. # We annotate the decorated function with any parameters captured by this # fixture so that they can be used by the wrapper in image_comparison. - baseline_images = request.keywords['baseline_images'].args[0] + baseline_images, = request.node.get_closest_marker('baseline_images').args if baseline_images is None: # Allow baseline image list to be produced on the fly based on current # parametrization. diff --git a/setupext.py b/setupext.py index a5b88064c238..fe14870f5b2f 100644 --- a/setupext.py +++ b/setupext.py @@ -785,7 +785,7 @@ def get_namespace_packages(self): class Tests(OptionalPackage): name = "tests" - pytest_min_version = '3.1' + pytest_min_version = '3.6' default_config = False def check(self): From a818a05f71fbf73c6e796ef4e88088dc217dec73 Mon Sep 17 00:00:00 2001 From: Bruno Pagani Date: Mon, 14 Jan 2019 16:33:56 +0100 Subject: [PATCH 02/16] Revert "Pin pytest to <3.8" --- .appveyor.yml | 3 +-- .travis.yml | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0d34fa4572f7..928d1ff39abd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -66,8 +66,7 @@ install: - activate test-environment - echo %PYTHON_VERSION% %TARGET_ARCH% # pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124 - - pip install -q "pytest>=3.6.0,<3.8" "pytest-cov>=2.3.1" - pytest-rerunfailures pytest-timeout pytest-xdist + - pip install -q "pytest>=3.6.0" "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout pytest-xdist # Apply patch to `subprocess` on Python versions > 2 and < 3.6.3 # https://github.com/matplotlib/matplotlib/issues/9176 diff --git a/.travis.yml b/.travis.yml index cf3f09409c23..47d4a320adef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,9 +53,8 @@ env: - PANDAS= - PILLOW=pillow - PYPARSING=pyparsing - - PYTEST='pytest>=3.6,<3.8' + - PYTEST='pytest>=3.6' - PYTEST_COV=pytest-cov - - PYTEST_RERUNFAILURES=pytest-rerunfailures - PYTEST_PEP8= - PYTEST_TIMEOUT=pytest-timeout - SPHINX=sphinx @@ -81,7 +80,6 @@ matrix: - PYTEST=pytest==3.6.0 - PYTEST_COV=pytest-cov==2.3.1 - PYTEST_TIMEOUT=pytest-timeout==1.2.1 # Newer pytest-timeouts don't support pytest <3.4. - - PYTEST_RERUNFAILURES='pytest-rerunfailures<5' # 5 needs pytest>=3.6 - SPHINX=sphinx==1.3 - python: 3.4 env: PYTHON_ARGS=-OO @@ -177,7 +175,7 @@ install: $PYTEST_COV \ pytest-faulthandler \ $PYTEST_PEP8 \ - $PYTEST_RERUNFAILURES \ + pytest-rerunfailures \ $PYTEST_TIMEOUT \ pytest-xdist From 360d83d3cf37416f90dfacb1d2a46202fb35206f Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 26 Sep 2018 08:58:41 -0700 Subject: [PATCH 03/16] Backport PR #12297: Remove some pytest parameterising warnings --- lib/matplotlib/tests/test_backend_ps.py | 13 ++++++++----- lib/matplotlib/tests/test_backend_svg.py | 2 +- lib/matplotlib/tests/test_backends_interactive.py | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 8bf6e7dde38e..10d8033d4ca9 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -31,13 +31,16 @@ @pytest.mark.flaky(reruns=3) @pytest.mark.parametrize('format, use_log, rcParams', [ ('ps', False, {}), - needs_ghostscript(('ps', False, {'ps.usedistiller': 'ghostscript'})), - needs_usetex(needs_ghostscript(('ps', False, {'text.latex.unicode': True, - 'text.usetex': True}))), + pytest.param('ps', False, {'ps.usedistiller': 'ghostscript'}, + marks=needs_ghostscript), + pytest.param('ps', False, {'text.latex.unicode': True, + 'text.usetex': True}, + marks=[needs_ghostscript, needs_usetex]), ('eps', False, {}), ('eps', True, {'ps.useafm': True}), - needs_usetex(needs_ghostscript(('eps', False, {'text.latex.unicode': True, - 'text.usetex': True}))), + pytest.param('eps', False, {'text.latex.unicode': True, + 'text.usetex': True}, + marks=[needs_ghostscript, needs_usetex]), ], ids=[ 'ps', 'ps with distiller', diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index e0cbdfa8bce1..1f6bf7cc3a62 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -130,7 +130,7 @@ def _test_determinism_save(filename, usetex): "filename, usetex", # unique filenames to allow for parallel testing [("determinism_notex.svg", False), - needs_usetex(("determinism_tex.svg", True))]) + pytest.param("determinism_tex.svg", True, marks=needs_usetex)]) def test_determinism(filename, usetex): import sys from subprocess import check_output, STDOUT, CalledProcessError diff --git a/lib/matplotlib/tests/test_backends_interactive.py b/lib/matplotlib/tests/test_backends_interactive.py index df7a5d08a10b..8cd4585bffc2 100644 --- a/lib/matplotlib/tests/test_backends_interactive.py +++ b/lib/matplotlib/tests/test_backends_interactive.py @@ -31,8 +31,10 @@ def _get_testable_interactive_backends(): reason = "No $DISPLAY" elif any(importlib.util.find_spec(dep) is None for dep in deps): reason = "Missing dependency" - backends.append(pytest.mark.skip(reason=reason)(backend) if reason - else backend) + if reason: + backend = pytest.param( + backend, marks=pytest.mark.skip(reason=reason)) + backends.append(backend) return backends From 6e0c6137ed16f73489f9fd6bb5019001bad92168 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 16 Jan 2019 14:20:42 -0500 Subject: [PATCH 04/16] CI: Explicitly install xvfb --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 47d4a320adef..1376bb7e95f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ addons: - texlive-latex-extra - texlive-latex-recommended - texlive-xetex + - xvfb env: global: From 794895c704a3ce0ccf0b9956bd54eeee9fa2ccf8 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 16 Jan 2019 14:32:35 -0500 Subject: [PATCH 05/16] CI: try using systemd to start xvfb following part of https://gist.github.com/ypandit/f4fe751bcbf3ee6a32ca --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1376bb7e95f1..45d3dd1684b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -190,7 +190,7 @@ before_script: - | if [[ $TRAVIS_OS_NAME != 'osx' ]]; then export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start + systemctl start Xvfb.service fi script: ci/travis/test_script.sh From bffc34b7e5f343d402ba6e738c7272b309902ca7 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 16 Jan 2019 14:56:02 -0500 Subject: [PATCH 06/16] CI: try xvfb as a service following https://docs.travis-ci.com/user/gui-and-headless-browsers/#using-xvfb-to-run-tests-that-require-a-gui --- .travis.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45d3dd1684b4..cad98c9d59b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: python dist: xenial sudo: false +services: + - xvfb + branches: except: - /^auto-backport-of-pr-\d*/ @@ -186,12 +189,6 @@ install: # Install matplotlib pip install -ve . -before_script: - - | - if [[ $TRAVIS_OS_NAME != 'osx' ]]; then - export DISPLAY=:99.0 - systemctl start Xvfb.service - fi script: ci/travis/test_script.sh From 655ad9e193b174a1ed6a1a79361fbdd8cd514ff8 Mon Sep 17 00:00:00 2001 From: Bruno Pagani Date: Wed, 16 Jan 2019 22:26:22 +0100 Subject: [PATCH 07/16] Bump pytest to 3.6.1 Else pytest fails to start, fixed upstream in: https://github.com/pytest-dev/pytest/commit/b5a94d8e6c49201c8c79a7c52b8466e020e6d6b8 --- .appveyor.yml | 2 +- .travis.yml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 928d1ff39abd..7f47d15f2300 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -66,7 +66,7 @@ install: - activate test-environment - echo %PYTHON_VERSION% %TARGET_ARCH% # pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124 - - pip install -q "pytest>=3.6.0" "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout pytest-xdist + - pip install -q "pytest>=3.6.1" "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout pytest-xdist # Apply patch to `subprocess` on Python versions > 2 and < 3.6.3 # https://github.com/matplotlib/matplotlib/issues/9176 diff --git a/.travis.yml b/.travis.yml index cad98c9d59b9..cd9804aac687 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ env: - PANDAS= - PILLOW=pillow - PYPARSING=pyparsing - - PYTEST='pytest>=3.6' + - PYTEST='pytest>=3.6.1' - PYTEST_COV=pytest-cov - PYTEST_PEP8= - PYTEST_TIMEOUT=pytest-timeout @@ -73,6 +73,7 @@ matrix: include: - python: 2.7 # pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124. + # pytest>=3.6.1 due to https://github.com/pytest-dev/pytest/commit/b5a94d8e6c49201c8c79a7c52b8466e020e6d6b8 env: - CYCLER=cycler==0.10 - DATEUTIL=python-dateutil==2.1 @@ -81,7 +82,7 @@ matrix: - NUMPY=numpy==1.7.1 - PANDAS='pandas<0.21.0' - PYPARSING=pyparsing==2.0.1 - - PYTEST=pytest==3.6.0 + - PYTEST=pytest==3.6.1 - PYTEST_COV=pytest-cov==2.3.1 - PYTEST_TIMEOUT=pytest-timeout==1.2.1 # Newer pytest-timeouts don't support pytest <3.4. - SPHINX=sphinx==1.3 From 32cdb6b82048ac2418c13aef9a3741285f9aec3e Mon Sep 17 00:00:00 2001 From: Bruno Pagani Date: Wed, 16 Jan 2019 23:10:07 +0100 Subject: [PATCH 08/16] CI: Limit pytest-rerunfailures in minimal version test --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cd9804aac687..e07f29fd8670 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,6 +59,7 @@ env: - PYPARSING=pyparsing - PYTEST='pytest>=3.6.1' - PYTEST_COV=pytest-cov + - PYTEST_RERUNFAILURES=pytest-rerunfailures - PYTEST_PEP8= - PYTEST_TIMEOUT=pytest-timeout - SPHINX=sphinx @@ -84,6 +85,7 @@ matrix: - PYPARSING=pyparsing==2.0.1 - PYTEST=pytest==3.6.1 - PYTEST_COV=pytest-cov==2.3.1 + - PYTEST_RERUNFAILURES='pytest-rerunfailures<6' # 6 needs pytest >=3.8 - PYTEST_TIMEOUT=pytest-timeout==1.2.1 # Newer pytest-timeouts don't support pytest <3.4. - SPHINX=sphinx==1.3 - python: 3.4 @@ -180,7 +182,7 @@ install: $PYTEST_COV \ pytest-faulthandler \ $PYTEST_PEP8 \ - pytest-rerunfailures \ + $PYTEST_RERUNFAILURES \ $PYTEST_TIMEOUT \ pytest-xdist From 3f4d8e9bdf0c9d33c56689f2e1dc44e6e9fe5611 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 27 Sep 2018 19:45:25 -0400 Subject: [PATCH 09/16] 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 2712d64291a7..290341146d85 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1369,10 +1369,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 7c4f28c3c15c31bdaf48233b4ab5e7ca8c51bf87 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 27 Sep 2018 19:46:56 -0400 Subject: [PATCH 10/16] 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 aff6cddf492d..491a9b2c5d6b 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -391,7 +391,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 58a28c8f689a..3bdcccf48821 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1447,9 +1447,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 11/16] 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 0ce6e6252493..8f1600f48c89 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -223,12 +223,18 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): if isinstance(extension, six.string_types): - 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 9f4a44299af43ebb473635ec07e993e3b7c4cf61 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 28 Sep 2018 03:40:37 -0400 Subject: [PATCH 12/16] 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 8f1600f48c89..d008446dcbf4 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -224,20 +224,24 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): if isinstance(extension, six.string_types): 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 0a506db92adf..d6e57b9b4e6e 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -125,9 +125,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 209d1dc62d5aae31b5138c8e5b2a19a5cc163c27 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 18 Jul 2018 22:40:41 +0200 Subject: [PATCH 13/16] Use skipif instead of xfail when test dependencies are missing. In such cases, there's no need to even try running the test and get an exception out of it. --- lib/matplotlib/tests/test_backend_pdf.py | 2 +- lib/matplotlib/tests/test_backend_ps.py | 6 ++---- lib/matplotlib/tests/test_backend_qt4.py | 2 +- lib/matplotlib/tests/test_backend_svg.py | 2 +- lib/matplotlib/tests/test_image.py | 17 +++++------------ lib/matplotlib/tests/test_text.py | 2 +- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 13fa0374ec76..6cf37f3b5a1f 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -20,7 +20,7 @@ _determinism_check) -needs_usetex = pytest.mark.xfail( +needs_usetex = pytest.mark.skipif( not checkdep_usetex(True), reason="This test needs a TeX installation") diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 10d8033d4ca9..f5eb1daba90d 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -17,12 +17,10 @@ _determinism_check) -needs_ghostscript = pytest.mark.xfail( +needs_ghostscript = pytest.mark.skipif( matplotlib.checkdep_ghostscript()[0] is None, reason="This test needs a ghostscript installation") - - -needs_usetex = pytest.mark.xfail( +needs_usetex = pytest.mark.skipif( not matplotlib.checkdep_usetex(True), reason="This test needs a TeX installation") diff --git a/lib/matplotlib/tests/test_backend_qt4.py b/lib/matplotlib/tests/test_backend_qt4.py index a621329772ed..ede4bca90780 100644 --- a/lib/matplotlib/tests/test_backend_qt4.py +++ b/lib/matplotlib/tests/test_backend_qt4.py @@ -29,7 +29,7 @@ py_qt_ver = QtCore.__version_info__[0] if py_qt_ver != 4: - pytestmark = pytest.mark.xfail(reason='Qt4 is not available') + pytestmark = pytest.mark.skipif(reason='Qt4 is not available') @pytest.mark.backend('Qt4Agg') diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 1f6bf7cc3a62..7be7aaee5017 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -16,7 +16,7 @@ from matplotlib import dviread -needs_usetex = pytest.mark.xfail( +needs_usetex = pytest.mark.skipif( not matplotlib.checkdep_usetex(True), reason="This test needs a TeX installation") diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index e6da25789f0b..c8a23347f65e 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -23,14 +23,6 @@ import pytest -try: - from PIL import Image - HAS_PIL = True -except ImportError: - HAS_PIL = False -needs_pillow = pytest.mark.xfail(not HAS_PIL, reason='Test requires Pillow') - - @image_comparison(baseline_images=['image_interps'], style='mpl20') def test_image_interps(): 'make the basic nearest, bilinear and bicubic interps' @@ -113,8 +105,8 @@ def test_image_python_io(): plt.imread(buffer) -@needs_pillow def test_imread_pil_uint16(): + pytest.importorskip("PIL") img = plt.imread(os.path.join(os.path.dirname(__file__), 'baseline_images', 'test_image', 'uint16.tif')) assert (img.dtype == np.uint16) @@ -122,8 +114,8 @@ def test_imread_pil_uint16(): @pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python 3.6+") -@needs_pillow def test_imread_fspath(): + pytest.importorskip("PIL") from pathlib import Path img = plt.imread( Path(__file__).parent / 'baseline_images/test_image/uint16.tif') @@ -497,8 +489,8 @@ def test_nonuniformimage_setnorm(): im.set_norm(plt.Normalize()) -@needs_pillow def test_jpeg_2d(): + Image = pytest.importorskip('PIL.Image') # smoke test that mode-L pillow images work. imd = np.ones((10, 10), dtype='uint8') for i in range(10): @@ -509,8 +501,9 @@ def test_jpeg_2d(): ax.imshow(im) -@needs_pillow def test_jpeg_alpha(): + Image = pytest.importorskip('PIL.Image') + plt.figure(figsize=(1, 1), dpi=300) # Create an image that is all black, with a gradient from 0-1 in # the alpha channel from left to right. diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 7bc878accc95..987dee6d776e 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -14,7 +14,7 @@ from matplotlib.testing.decorators import image_comparison -needs_usetex = pytest.mark.xfail( +needs_usetex = pytest.mark.skipif( not matplotlib.checkdep_usetex(True), reason="This test needs a TeX installation") From 364f01886c698e68ef90208cf07c543288490eed Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 28 Sep 2018 04:41:22 -0400 Subject: [PATCH 14/16] 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 | 11 +++++++++-- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 6cf37f3b5a1f..c028eed8f2eb 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -8,6 +8,7 @@ import os import sys import tempfile +import warnings import numpy as np import pytest @@ -20,9 +21,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 f5eb1daba90d..46cb355c9860 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -4,6 +4,7 @@ import io import re +import warnings import numpy as np import pytest @@ -17,12 +18,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 7be7aaee5017..da93e2d38806 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -6,6 +6,7 @@ from io import BytesIO import os import tempfile +import warnings import xml.parsers.expat import pytest @@ -16,9 +17,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 987dee6d776e..e438766b7032 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -14,9 +14,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 5d6a939e8a1a..e3b1c1f6ce39 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -1,4 +1,5 @@ from __future__ import absolute_import, division, print_function +import warnings import pytest @@ -7,8 +8,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) From cc1c6a84760b84604d064bc8d6d2e1ca5f8483e8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 26 Sep 2018 15:21:47 -0400 Subject: [PATCH 15/16] Merge pull request #12294 from dstansby/tri-warnings Fix expand_dims warnings in triinterpolate --- lib/matplotlib/tri/triinterpolate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/tri/triinterpolate.py b/lib/matplotlib/tri/triinterpolate.py index e0c2047489a5..f3c6deb0c977 100644 --- a/lib/matplotlib/tri/triinterpolate.py +++ b/lib/matplotlib/tri/triinterpolate.py @@ -581,9 +581,9 @@ def _compute_tri_eccentricities(tris_pts): The so-called eccentricity parameters [1] needed for HCT triangular element. """ - a = np.expand_dims(tris_pts[:, 2, :]-tris_pts[:, 1, :], axis=2) - b = np.expand_dims(tris_pts[:, 0, :]-tris_pts[:, 2, :], axis=2) - c = np.expand_dims(tris_pts[:, 1, :]-tris_pts[:, 0, :], axis=2) + a = np.expand_dims(tris_pts[:, 2, :] - tris_pts[:, 1, :], axis=2) + b = np.expand_dims(tris_pts[:, 0, :] - tris_pts[:, 2, :], axis=2) + c = np.expand_dims(tris_pts[:, 1, :] - tris_pts[:, 0, :], axis=2) # Do not use np.squeeze, this is dangerous if only one triangle # in the triangulation... dot_a = _prod_vectorized(_transpose_vectorized(a), a)[:, 0, 0] @@ -1071,9 +1071,9 @@ def get_dof_vec(tri_z, tri_dz, J): J1 = _prod_vectorized(_ReducedHCT_Element.J0_to_J1, J) J2 = _prod_vectorized(_ReducedHCT_Element.J0_to_J2, J) - col0 = _prod_vectorized(J, np.expand_dims(tri_dz[:, 0, :], axis=3)) - col1 = _prod_vectorized(J1, np.expand_dims(tri_dz[:, 1, :], axis=3)) - col2 = _prod_vectorized(J2, np.expand_dims(tri_dz[:, 2, :], axis=3)) + col0 = _prod_vectorized(J, np.expand_dims(tri_dz[:, 0, :], axis=2)) + col1 = _prod_vectorized(J1, np.expand_dims(tri_dz[:, 1, :], axis=2)) + col2 = _prod_vectorized(J2, np.expand_dims(tri_dz[:, 2, :], axis=2)) dfdksi = _to_matrix_vectorized([ [col0[:, 0, 0], col1[:, 0, 0], col2[:, 0, 0]], From 62cc0844d85e4cb2853a95a8e86fe0138c7fae87 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 19 Jan 2019 11:12:50 -0500 Subject: [PATCH 16/16] CI: don't install ffmpeg on OSX on travis It seems to be timing out the build (because it is falling back to building ffmpeg from scratch?!). --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e07f29fd8670..70e130caf038 100644 --- a/.travis.yml +++ b/.travis.yml @@ -125,7 +125,7 @@ before_install: else brew update brew tap homebrew/gui - brew install python libpng ffmpeg imagemagick mplayer ccache + # brew install python libpng ffmpeg imagemagick mplayer ccache # We could install ghostscript and inkscape here to test svg and pdf # but this makes the test time really long. # brew install ghostscript inkscape