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

Skip to content

Commit be08391

Browse files
committed
Add basic testing of interactive backends.
1 parent 740ce99 commit be08391

File tree

5 files changed

+95
-22
lines changed

5 files changed

+95
-22
lines changed

.travis.yml

Lines changed: 42 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,48 @@ 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+
# See https://wxpython.org/Phoenix/snapshot-builds/README.txt
129+
pip install --pre \
130+
-f https://wxpython.org/Phoenix/release-extras/linux/gtk3/centos-7/ \
131+
wxpython \
132+
|| true
119133
if [[ $BUILD_DOCS == true ]]; then
120134
pip install $PRE -r doc-requirements.txt
121135
fi
122136
123137
# 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
138+
pip install $PRE \
139+
pytest \
140+
pytest-cov>=2.3.1 \
141+
pytest-faulthandler \
142+
pytest-rerunfailures \
143+
pytest-timeout \
144+
pytest-xdist \
145+
$INSTALL_PEP8
125146
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
147+
# We manually install humor sans using the package from Ubuntu 14.10.
148+
# Unfortunatly humor sans is not availible in the Ubuntu version used by
149+
# Travis but we can manually install the deb from a later version since is
150+
# it basically just a .ttf file. The current Travis Ubuntu image is to old
151+
# to search .local/share/fonts so we store fonts in .fonts
130152
if [[ $BUILD_DOCS == true ]]; then
131153
wget https://github.com/google/fonts/blob/master/ofl/felipa/Felipa-Regular.ttf?raw=true -O Felipa-Regular.ttf
132154
wget http://mirrors.kernel.org/ubuntu/pool/universe/f/fonts-humor-sans/fonts-humor-sans_1.0-1_all.deb
@@ -144,6 +166,13 @@ install:
144166
# Install matplotlib
145167
pip install -ve .
146168
169+
before_script:
170+
- |
171+
if [[ $TRAVIS_OS_NAME != 'osx' ]]; then
172+
export DISPLAY=:99.0
173+
sh -e /etc/init.d/xvfb start
174+
fi
175+
147176
script: ci/travis/test_script.sh
148177

149178
before_cache:

ci/travis/test_script.sh

Lines 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

Lines 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

Lines 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(
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import sys
3+
4+
from matplotlib.compat.subprocess import Popen
5+
import pytest
6+
7+
8+
# Minimal smoke-testing of the backends for which the dependencies are
9+
# PyPI-installable. They are not available for all tested Python versions so
10+
# we don't fail on missing backends.
11+
12+
13+
def _get_available_backends():
14+
backends = []
15+
for module_name, backend in [
16+
("PyQt5", "qt5agg"),
17+
("Tkinter", "tkagg"),
18+
("tkinter", "tkagg"),
19+
("wx", "wxagg")]:
20+
try:
21+
__import__(module_name)
22+
except ImportError:
23+
pass
24+
else:
25+
backends.append(backend)
26+
return backends
27+
28+
29+
_test_script = """\
30+
import sys
31+
from matplotlib import pyplot as plt
32+
33+
fig = plt.figure()
34+
fig.canvas.mpl_connect("draw_event", lambda event: sys.exit())
35+
plt.show()
36+
"""
37+
38+
39+
@pytest.mark.skipif("DISPLAY" not in os.environ,
40+
reason="The DISPLAY environment variable is not set.")
41+
@pytest.mark.parametrize("backend", _get_available_backends())
42+
def test_backend(backend):
43+
environ = os.environ.copy()
44+
environ["MPLBACKEND"] = backend
45+
proc = Popen([sys.executable, "-c", _test_script], env=environ)
46+
# Empirically, 1s is not enough on Travis.
47+
assert proc.wait(timeout=5) == 0

0 commit comments

Comments
 (0)