Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add basic testing of interactive backends. #8660

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 1 commit into from
May 26, 2017
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
51 changes: 38 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ addons:
- graphviz
- libgeos-dev
- otf-freefont
# - fonts-humor-sans
# sources:
# - debian-sid

env:
global:
Expand Down Expand Up @@ -95,7 +92,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 All @@ -110,23 +107,44 @@ install:
ccache -s
git describe
# Upgrade pip and setuptools and wheel to get as clean an install as possible
pip install --upgrade pip
pip install --upgrade wheel
pip install --upgrade setuptools
pip install --upgrade pip setuptools wheel
- |
# Install dependencies from pypi
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS cycler codecov coverage $MOCK $NOSE sphinx pillow
pip install $PRE \
$MOCK \
$NOSE \
$NUMPY \
$PANDAS \
codecov \
coverage \
cycler \
pillow \
pyparsing!=2.1.6 \
python-dateutil \
sphinx
# GUI toolkits are pip-installable only for some versions of Python so don't
# fail if we can't install them.
pip install pyqt5 || true
python -c 'import PyQt5.QtCore' || true
if [[ $BUILD_DOCS == true ]]; then
pip install $PRE -r doc-requirements.txt
fi

# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
pip install $PRE pytest 'pytest-cov>=2.3.1' pytest-faulthandler pytest-rerunfailures pytest-timeout pytest-xdist $INSTALL_PEP8
pip install $PRE \
pytest \
pytest-cov>=2.3.1 \
pytest-faulthandler \
pytest-rerunfailures \
pytest-timeout \
pytest-xdist \
$INSTALL_PEP8

# We manually install humor sans using the package from Ubuntu 14.10. Unfortunatly humor sans is not
# availible in the Ubuntu version used by Travis but we can manually install the deb from a later
# version since is it basically just a .ttf file
# The current Travis Ubuntu image is to old to search .local/share/fonts so we store fonts in .fonts
# We manually install humor sans using the package from Ubuntu 14.10.
# Unfortunatly humor sans is not availible in the Ubuntu version used by
# Travis but we can manually install the deb from a later version since is
# it basically just a .ttf file. The current Travis Ubuntu image is to old
# to search .local/share/fonts so we store fonts in .fonts
if [[ $BUILD_DOCS == true ]]; then
wget https://github.com/google/fonts/blob/master/ofl/felipa/Felipa-Regular.ttf?raw=true -O Felipa-Regular.ttf
wget http://mirrors.kernel.org/ubuntu/pool/universe/f/fonts-humor-sans/fonts-humor-sans_1.0-1_all.deb
Expand All @@ -144,6 +162,13 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis docs suggest a sleep here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except that we're going to build matplotlib before running any tests, so xvfb should have more than enough time to start :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't building already happen in install?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even then, just test collection should give us enough time.


script: ci/travis/test_script.sh

before_cache:
Expand Down
3 changes: 0 additions & 3 deletions ci/travis/test_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ set -ev
# Travis VM to run out of memory (since so many copies of inkscape and
# ghostscript are running at the same time).

echo Testing import of tkagg backend
MPLBACKEND="tkagg" python -c 'import matplotlib.pyplot as plt; print(plt.get_backend())'

if [[ $BUILD_DOCS == false ]]; then
if [[ $DELETE_FONT_CACHE == 1 ]]; then
rm -rf ~/.cache/matplotlib
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_backend_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

with matplotlib.rc_context(rc={'backend': 'Qt4Agg'}):
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat')
from matplotlib.backends.backend_qt4 import (MODIFIER_KEYS,
SUPER, ALT, CTRL, SHIFT) # noqa
from matplotlib.backends.backend_qt4 import (
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa

QtCore = qt_compat.QtCore
_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_fig_close():

# assert that we have removed the reference to the FigureManager
# that got added by plt.figure()
assert(init_figs == Gcf.figs)
assert init_figs == Gcf.figs


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
with matplotlib.rc_context(rc={'backend': 'Qt5Agg'}):
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat',
minversion='5')
from matplotlib.backends.backend_qt5 import (MODIFIER_KEYS,
SUPER, ALT, CTRL, SHIFT) # noqa
from matplotlib.backends.backend_qt5 import (
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa

QtCore = qt_compat.QtCore
_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
Expand All @@ -40,7 +40,7 @@ def test_fig_close():

# assert that we have removed the reference to the FigureManager
# that got added by plt.figure()
assert(init_figs == Gcf.figs)
assert init_figs == Gcf.figs


@pytest.mark.parametrize(
Expand Down
53 changes: 53 additions & 0 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import importlib
import os
import sys

from matplotlib.compat.subprocess import Popen
import pytest


# Minimal smoke-testing of the backends for which the dependencies are
# PyPI-installable on Travis. They are not available for all tested Python
# versions so we don't fail on missing backends.
#
# Once the Travis build environment switches to Ubuntu 14.04, we should be able
# to add wxagg (which has wheels for 14.04 but not for 12.04).
#
# We also don't test on Py2 because its subprocess module doesn't support
# timeouts, and it would require a separate code path to check for module
# existence without actually trying to import the module (which may install
# an undesirable input hook).


def _get_available_backends():
if sys.version_info < (3,):
return []
else:
return [
pytest.mark.skipif(
importlib.util.find_spec(module_name) is None,
reason="Could not import {!r}".format(module_name))(backend)
for module_name, backend in [
("PyQt5", "qt5agg"),
("tkinter", "tkagg")]]


_test_script = """\
import sys
from matplotlib import pyplot as plt

fig = plt.figure()
fig.canvas.mpl_connect("draw_event", lambda event: sys.exit())
plt.show()
"""


@pytest.mark.skipif("DISPLAY" not in os.environ,
reason="The DISPLAY environment variable is not set.")
@pytest.mark.parametrize("backend", _get_available_backends())
def test_backend(backend):
environ = os.environ.copy()
environ["MPLBACKEND"] = backend
proc = Popen([sys.executable, "-c", _test_script], env=environ)
# Empirically, 1s is not enough on Travis.
assert proc.wait(timeout=5) == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appveyor on python 2.7 doesn't like timeout=5 for some reason - https://ci.appveyor.com/project/matplotlib/matplotlib/build/1.0.1635/job/d70betvulec3rx10#L1592

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because windows + py2 doesn't use subprocess32. I'm a bit surprised that the DISPLAY env variable is set on windows though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah, let's ignore py2. that'll also let me handle @tacaswell's concern re: importing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a py2 issue was the source of the instigating bug 😈

I am 👍 on this being a py3 only test though.