Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 718ac86

Browse filesBrowse files
authored
Merge pull request #8660 from anntzer/xvfb-tests
TST: Add basic testing of interactive backends.
2 parents d50843e + 0c68715 commit 718ac86
Copy full SHA for 718ac86

File tree

Expand file treeCollapse file tree

5 files changed

+97
-22
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+97
-22
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+38-13Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ addons:
2727
- graphviz
2828
- libgeos-dev
2929
- otf-freefont
30-
# - fonts-humor-sans
31-
# sources:
32-
# - debian-sid
3330

3431
env:
3532
global:
@@ -95,7 +92,7 @@ before_install:
9592
else
9693
brew update
9794
brew tap homebrew/gui
98-
brew install python libpng ffmpeg imagemagick mplayer ccache
95+
brew install python libpng ffmpeg imagemagick mplayer ccache
9996
# We could install ghostscript and inkscape here to test svg and pdf
10097
# but this makes the test time really long.
10198
# brew install ghostscript inkscape
@@ -110,23 +107,44 @@ install:
110107
ccache -s
111108
git describe
112109
# Upgrade pip and setuptools and wheel to get as clean an install as possible
113-
pip install --upgrade pip
114-
pip install --upgrade wheel
115-
pip install --upgrade setuptools
110+
pip install --upgrade pip setuptools wheel
116111
- |
117112
# Install dependencies from pypi
118-
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS cycler codecov coverage $MOCK $NOSE sphinx pillow
113+
pip install $PRE \
114+
$MOCK \
115+
$NOSE \
116+
$NUMPY \
117+
$PANDAS \
118+
codecov \
119+
coverage \
120+
cycler \
121+
pillow \
122+
pyparsing!=2.1.6 \
123+
python-dateutil \
124+
sphinx
125+
# GUI toolkits are pip-installable only for some versions of Python so don't
126+
# fail if we can't install them.
127+
pip install pyqt5 || true
128+
python -c 'import PyQt5.QtCore' || true
119129
if [[ $BUILD_DOCS == true ]]; then
120130
pip install $PRE -r doc-requirements.txt
121131
fi
122132
123133
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
124-
pip install $PRE pytest 'pytest-cov>=2.3.1' pytest-faulthandler pytest-rerunfailures pytest-timeout pytest-xdist $INSTALL_PEP8
134+
pip install $PRE \
135+
pytest \
136+
pytest-cov>=2.3.1 \
137+
pytest-faulthandler \
138+
pytest-rerunfailures \
139+
pytest-timeout \
140+
pytest-xdist \
141+
$INSTALL_PEP8
125142
126-
# We manually install humor sans using the package from Ubuntu 14.10. Unfortunatly humor sans is not
127-
# availible in the Ubuntu version used by Travis but we can manually install the deb from a later
128-
# version since is it basically just a .ttf file
129-
# The current Travis Ubuntu image is to old to search .local/share/fonts so we store fonts in .fonts
143+
# We manually install humor sans using the package from Ubuntu 14.10.
144+
# Unfortunatly humor sans is not availible in the Ubuntu version used by
145+
# Travis but we can manually install the deb from a later version since is
146+
# it basically just a .ttf file. The current Travis Ubuntu image is to old
147+
# to search .local/share/fonts so we store fonts in .fonts
130148
if [[ $BUILD_DOCS == true ]]; then
131149
wget https://github.com/google/fonts/blob/master/ofl/felipa/Felipa-Regular.ttf?raw=true -O Felipa-Regular.ttf
132150
wget http://mirrors.kernel.org/ubuntu/pool/universe/f/fonts-humor-sans/fonts-humor-sans_1.0-1_all.deb
@@ -144,6 +162,13 @@ install:
144162
# Install matplotlib
145163
pip install -ve .
146164
165+
before_script:
166+
- |
167+
if [[ $TRAVIS_OS_NAME != 'osx' ]]; then
168+
export DISPLAY=:99.0
169+
sh -e /etc/init.d/xvfb start
170+
fi
171+
147172
script: ci/travis/test_script.sh
148173

149174
before_cache:

‎ci/travis/test_script.sh

Copy file name to clipboardExpand all lines: ci/travis/test_script.sh
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ set -ev
1111
# Travis VM to run out of memory (since so many copies of inkscape and
1212
# ghostscript are running at the same time).
1313

14-
echo Testing import of tkagg backend
15-
MPLBACKEND="tkagg" python -c 'import matplotlib.pyplot as plt; print(plt.get_backend())'
16-
1714
if [[ $BUILD_DOCS == false ]]; then
1815
if [[ $DELETE_FONT_CACHE == 1 ]]; then
1916
rm -rf ~/.cache/matplotlib

‎lib/matplotlib/tests/test_backend_qt4.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt4.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

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

2121
QtCore = qt_compat.QtCore
2222
_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
@@ -47,7 +47,7 @@ def test_fig_close():
4747

4848
# assert that we have removed the reference to the FigureManager
4949
# that got added by plt.figure()
50-
assert(init_figs == Gcf.figs)
50+
assert init_figs == Gcf.figs
5151

5252

5353
@pytest.mark.parametrize(

‎lib/matplotlib/tests/test_backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt5.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
with matplotlib.rc_context(rc={'backend': 'Qt5Agg'}):
1717
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat',
1818
minversion='5')
19-
from matplotlib.backends.backend_qt5 import (MODIFIER_KEYS,
20-
SUPER, ALT, CTRL, SHIFT) # noqa
19+
from matplotlib.backends.backend_qt5 import (
20+
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa
2121

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

4141
# assert that we have removed the reference to the FigureManager
4242
# that got added by plt.figure()
43-
assert(init_figs == Gcf.figs)
43+
assert init_figs == Gcf.figs
4444

4545

4646
@pytest.mark.parametrize(
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import importlib
2+
import os
3+
import sys
4+
5+
from matplotlib.compat.subprocess import Popen
6+
import pytest
7+
8+
9+
# Minimal smoke-testing of the backends for which the dependencies are
10+
# PyPI-installable on Travis. They are not available for all tested Python
11+
# versions so we don't fail on missing backends.
12+
#
13+
# Once the Travis build environment switches to Ubuntu 14.04, we should be able
14+
# to add wxagg (which has wheels for 14.04 but not for 12.04).
15+
#
16+
# We also don't test on Py2 because its subprocess module doesn't support
17+
# timeouts, and it would require a separate code path to check for module
18+
# existence without actually trying to import the module (which may install
19+
# an undesirable input hook).
20+
21+
22+
def _get_available_backends():
23+
if sys.version_info < (3,):
24+
return []
25+
else:
26+
return [
27+
pytest.mark.skipif(
28+
importlib.util.find_spec(module_name) is None,
29+
reason="Could not import {!r}".format(module_name))(backend)
30+
for module_name, backend in [
31+
("PyQt5", "qt5agg"),
32+
("tkinter", "tkagg")]]
33+
34+
35+
_test_script = """\
36+
import sys
37+
from matplotlib import pyplot as plt
38+
39+
fig = plt.figure()
40+
fig.canvas.mpl_connect("draw_event", lambda event: sys.exit())
41+
plt.show()
42+
"""
43+
44+
45+
@pytest.mark.skipif("DISPLAY" not in os.environ,
46+
reason="The DISPLAY environment variable is not set.")
47+
@pytest.mark.parametrize("backend", _get_available_backends())
48+
def test_backend(backend):
49+
environ = os.environ.copy()
50+
environ["MPLBACKEND"] = backend
51+
proc = Popen([sys.executable, "-c", _test_script], env=environ)
52+
# Empirically, 1s is not enough on Travis.
53+
assert proc.wait(timeout=5) == 0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.