-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appveyor on python 2.7 doesn't like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.