Skip to content

Commit 9b2d237

Browse files
committed
Add some basic smoketesting for webagg (and wx).
1 parent fc73593 commit 9b2d237

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,16 @@ install:
131131
codecov \
132132
coverage \
133133
$CYCLER \
134+
$DATEUTIL \
134135
$NOSE \
135136
$NUMPY \
136137
$PANDAS \
137138
codecov \
138139
coverage \
139140
pillow \
140141
$PYPARSING \
141-
$DATEUTIL \
142-
$SPHINX
142+
$SPHINX \
143+
tornado
143144
# GUI toolkits are pip-installable only for some versions of Python so
144145
# don't fail if we can't install them. Make it easier to check whether the
145146
# install was successful by trying to import the toolkit (sometimes, the

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import importlib
22
import os
3-
from subprocess import Popen
3+
import signal
4+
import subprocess
45
import sys
6+
import time
7+
import urllib.request
58

69
import pytest
710

11+
import matplotlib as mpl
12+
813

914
# Minimal smoke-testing of the backends for which the dependencies are
1015
# PyPI-installable on Travis. They are not available for all tested Python
@@ -17,6 +22,7 @@ def _get_testable_interactive_backends():
1722
(["PyQt5"], "qt5agg"),
1823
(["cairocffi", "PyQt5"], "qt5cairo"),
1924
(["tkinter"], "tkagg"),
25+
(["wx"], "wx"),
2026
(["wx"], "wxagg")]:
2127
reason = None
2228
if not os.environ.get("DISPLAY"):
@@ -30,20 +36,48 @@ def _get_testable_interactive_backends():
3036

3137
_test_script = """\
3238
import sys
33-
from matplotlib import pyplot as plt
39+
from matplotlib import pyplot as plt, rcParams
40+
rcParams.update({
41+
"webagg.open_in_browser": False,
42+
"webagg.port_retries": 1,
43+
})
3444
3545
fig = plt.figure()
3646
ax = fig.add_subplot(111)
37-
ax.plot([1,2,3], [1,3,1])
47+
ax.plot([1, 2], [2, 3])
3848
fig.canvas.mpl_connect("draw_event", lambda event: sys.exit())
3949
plt.show()
4050
"""
51+
_test_timeout = 10 # Empirically, 1s is not enough on Travis.
4152

4253

4354
@pytest.mark.parametrize("backend", _get_testable_interactive_backends())
4455
@pytest.mark.flaky(reruns=3)
45-
def test_backend(backend):
46-
proc = Popen([sys.executable, "-c", _test_script],
47-
env={**os.environ, "MPLBACKEND": backend})
48-
# Empirically, 1s is not enough on Travis.
49-
assert proc.wait(timeout=10) == 0
56+
def test_interactive_backend(backend):
57+
subprocess.run([sys.executable, "-c", _test_script],
58+
env={**os.environ, "MPLBACKEND": backend},
59+
check=True, # Throw on failure.
60+
timeout=_test_timeout)
61+
62+
63+
@pytest.mark.skipif(
64+
os.name == "win32", reason="Cannot send SIGINT on Windows.")
65+
def test_webagg():
66+
pytest.importorskip("tornado")
67+
proc = subprocess.Popen([sys.executable, "-c", _test_script],
68+
env={**os.environ, "MPLBACKEND": "webagg"})
69+
url = "http://{}:{}".format(
70+
mpl.rcParams["webagg.address"], mpl.rcParams["webagg.port"])
71+
timeout = time.perf_counter() + _test_timeout
72+
while True:
73+
try:
74+
conn = urllib.request.urlopen(url)
75+
break
76+
except urllib.error.URLError:
77+
if time.perf_counter() > timeout:
78+
pytest.fail("Failed to connect to the webagg server.")
79+
else:
80+
continue
81+
conn.close()
82+
proc.send_signal(signal.SIGINT)
83+
assert proc.wait(timeout=_test_timeout) == 0

0 commit comments

Comments
 (0)