Skip to content

Backport PRs #12154, #12294, #12297, #12316, #13159 & #13205 to fix multiple tests issues #13181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.0,>=3.2.0,<3.8" "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
Expand Down
21 changes: 9 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ language: python
dist: xenial
sudo: false

services:
- xvfb

branches:
except:
- /^auto-backport-of-pr-\d*/
Expand Down Expand Up @@ -37,6 +40,7 @@ addons:
- texlive-latex-extra
- texlive-latex-recommended
- texlive-xetex
- xvfb

env:
global:
Expand All @@ -53,9 +57,7 @@ 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='pytest>=3.6.1'
- PYTEST_COV=pytest-cov
- PYTEST_RERUNFAILURES=pytest-rerunfailures
- PYTEST_PEP8=
Expand All @@ -72,6 +74,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
Expand All @@ -80,10 +83,10 @@ 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.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.
- PYTEST_RERUNFAILURES='pytest-rerunfailures<5' # 5 needs pytest>=3.6
- SPHINX=sphinx==1.3
- python: 3.4
env: PYTHON_ARGS=-OO
Expand Down Expand Up @@ -122,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
Expand Down Expand Up @@ -189,12 +192,6 @@ install:
# Install matplotlib
pip install -ve .

before_script:
- |
if [[ $TRAVIS_OS_NAME != 'osx' ]]; then
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start
fi

script: ci/travis/test_script.sh

Expand Down
6 changes: 3 additions & 3 deletions doc/devel/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down Expand Up @@ -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::
Expand Down
4 changes: 2 additions & 2 deletions doc/devel/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<u2')
x = np.frombuffer(raw, '<u2')
return x.reshape(pilImage.size[::-1]).astype('=u2')
else: # try to convert to an rgba image
try:
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 16 additions & 6 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,25 @@ 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
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.
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]
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

Expand Down
9 changes: 6 additions & 3 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import sys
import tempfile
import warnings

import numpy as np
import pytest
Expand All @@ -20,9 +21,11 @@
_determinism_check)


needs_usetex = pytest.mark.xfail(
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'],
Expand Down
30 changes: 17 additions & 13 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io
import re
import warnings

import numpy as np
import pytest
Expand All @@ -17,27 +18,30 @@
_determinism_check)


needs_ghostscript = pytest.mark.xfail(
matplotlib.checkdep_ghostscript()[0] is None,
reason="This test needs a ghostscript installation")


needs_usetex = pytest.mark.xfail(
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.
@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',
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_backend_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 7 additions & 4 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from io import BytesIO
import os
import tempfile
import warnings
import xml.parsers.expat

import pytest
Expand All @@ -16,9 +17,11 @@
from matplotlib import dviread


needs_usetex = pytest.mark.xfail(
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():
Expand Down Expand Up @@ -130,7 +133,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
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading