3
$ßL]š  ã               @   s¾   d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Zdd„ ZdZdZe	jjdeƒ ƒe	jjdd�d	d
„ ƒƒZe	jjdejkdd�e	jjejdkdd�dd„ ƒƒZdS )é    Nc              C   sª   g } x ddgdfddgdfdgdfddgdfd	gd
fdgdfdgdfgD ]Z\}}d }t jjdƒsfd}ntdd„ |D ƒƒr|d}|r˜tj|tjj|d�d�}| j|ƒ qHW | S )NZcairoZgiZgtk3aggZ	gtk3cairoZPyQt5Zqt5aggZ	cairocffiZqt5cairoÚtkinterZtkaggZwxZwxaggZDISPLAYzNo $DISPLAYc             s   s   | ]}t jj|ƒd kV  qd S )N)Ú	importlibÚutilÚ	find_spec)Ú.0Údep© r   úR/tmp/pip-install-edjban26/matplotlib/matplotlib/tests/test_backends_interactive.pyú	<genexpr>!   s    z5_get_testable_interactive_backends.<locals>.<genexpr>zMissing dependency)Úreason)Zmarks)	ÚosÚenvironÚgetÚanyÚpytestÚparamÚmarkÚskipÚappend)ÚbackendsÚdepsÚbackendr   r   r   r	   Ú"_get_testable_interactive_backends   s&    


r   a_  import importlib
import importlib.util
import sys
from unittest import TestCase

import matplotlib as mpl
from matplotlib import pyplot as plt, rcParams
from matplotlib.backend_bases import FigureCanvasBase
rcParams.update({
    "webagg.open_in_browser": False,
    "webagg.port_retries": 1,
})
backend = plt.rcParams["backend"].lower()
assert_equal = TestCase().assertEqual
assert_raises = TestCase().assertRaises

if backend.endswith("agg") and not backend.startswith(("gtk3", "web")):
    # Force interactive framework setup.
    plt.figure()

    # Check that we cannot switch to a backend using another interactive
    # framework, but can switch to a backend using cairo instead of agg, or a
    # non-interactive backend.  In the first case, we use tkagg as the "other"
    # interactive backend as it is (essentially) guaranteed to be present.
    # Moreover, don't test switching away from gtk3 (as Gtk.main_level() is
    # not set up at this point yet) and webagg (which uses no interactive
    # framework).

    if backend != "tkagg":
        with assert_raises(ImportError):
            mpl.use("tkagg", force=True)

    def check_alt_backend(alt_backend):
        mpl.use(alt_backend, force=True)
        fig = plt.figure()
        assert_equal(
            type(fig.canvas).__module__,
            "matplotlib.backends.backend_{}".format(alt_backend))

    if importlib.util.find_spec("cairocffi"):
        check_alt_backend(backend[:-3] + "cairo")
    check_alt_backend("svg")

mpl.use(backend, force=True)

fig, ax = plt.subplots()
assert_equal(
    type(fig.canvas).__module__,
    "matplotlib.backends.backend_{}".format(backend))

ax.plot([0, 1], [2, 3])

timer = fig.canvas.new_timer(1)
timer.add_callback(FigureCanvasBase.key_press_event, fig.canvas, "q")
# Trigger quitting upon draw.
fig.canvas.mpl_connect("draw_event", lambda event: timer.start())

plt.show()
é
   r   é   )Zrerunsc             C   s@   t jtjdtgtjd| i–td�}|jr<t	j
d|j› d�ƒ d S )Nz-cÚ
MPLBACKEND)ÚenvÚtimeoutz2The subprocess returned with non-zero exit status Ú.)Ú
subprocessÚrunÚsysÚ
executableÚ_test_scriptr   r   Ú_test_timeoutÚ
returncoder   Úfail)r   Úprocr   r   r	   Útest_interactive_backendn   s
    r(   Z"SYSTEM_TEAMFOUNDATIONCOLLECTIONURIz,this test fails an azure for unknown reasons)r   ÚntzCannot send SIGINT on Windows.c              C   sÚ   t jdƒ tjtjdtgtjddi–d�} dj	t
jd t
jd ƒ}tjƒ t }x^y&| jƒ }|d ksft‚tjj|ƒ}P W qP tjjk
r¨   tjƒ |kr¢t jd	ƒ nwPY qPX qPW |jƒ  | jtjƒ | jtd
�dksÖt‚d S )NZtornadoz-cr   Zwebagg)r   zhttp://{}:{}zwebagg.addresszwebagg.portz'Failed to connect to the webagg server.)r   r   )r   Zimportorskipr   ÚPopenr!   r"   r#   r   r   ÚformatÚmplZrcParamsÚtimeÚperf_counterr$   ÚpollÚAssertionErrorÚurllibÚrequestÚurlopenÚerrorÚURLErrorr&   ÚcloseÚsend_signalÚsignalÚSIGINTÚwait)r'   Úurlr   ÚretcodeÚconnr   r   r	   Útest_webaggy   s&    
r>   )r   Zimportlib.utilr   r8   r   r!   r-   Úurllib.requestr1   r   Z
matplotlibr,   r   r#   r$   r   ZparametrizeZflakyr(   Zskipifr   Únamer>   r   r   r   r	   Ú<module>   s"   W
