o
    g[*                     @   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lZd dlZd dlmZ dd ZdZdd Zejde ejd	d
dgejjdddd Zdd Ze ZeD ]:Zejd  Zdev r}ejejjejd qeedkrejejjejd qeedkrejejjejdd qeejdeejjdddd Z ejj!dej"v ddejj!ej#dkdddd  Z$ejj!ej%d!kd"dejjd#dd$d%d& Z&dS )'    N)_c_internal_utilsc                  C   sn  z
ddl m}  d}W n ty   d}Y nw g }ddgdfddgdf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dgdff
D ]n\}}d }dd |D }tjdkr_t s_d}n |rjdd|}n|dkrwt	j
drwd}nd|v r|sd}g }|r|tjjd| d| d  n|drtjd!kr|tjjd"d  tj||d#}|| qF|S )$Nr   )QtGuiTFcairogigtk3agg	gtk3cairoPyQt5qt5agg	cairocffiqt5cairoPySide2tkintertkaggwxwxaggzmatplotlib.backends._macosxmacosxc                 S   s   g | ]
}t j|s|qS  )	importlibutil	find_spec).0depr   r   h/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/matplotlib/tests/test_backends_interactive.py
<listcomp>+   s    z6_get_testable_interactive_backends.<locals>.<listcomp>linuxz'$DISPLAY and $WAYLAND_DISPLAY are unsetz{} cannot be importedz, TF_BUILDzmacosx backend fails on Azureqt5zno usable Qt5 bindingsz	Skipping z	 because reasondarwinzgithub #16849)marks)matplotlib.backends.qt_compatr   ImportErrorsysplatformr   display_is_validformatjoinosenvirongetappendpytestmarkskip
startswithxfailparam)r   have_qt5backendsdepsbackendr   missingr    r   r   r   "_get_testable_interactive_backends   sP   






r7   
   c                     s0  dd l } dd l}dd l}dd l}ddlm} dd lddlmm} ddl	m
} |ddd t|jdkrB|||jd  jd	  }| j | j}|d
r|ds  |dkr~|t jddd W d    n1 syw   Y   fdd}	| jdr|	|d d d  |	d j|dd  \}
} t|
jjd| |ddgddg |
jd |j!|
jd |
j"dfdd |
j"dt# |$ }|
j%|dd &  'd |$ }|
j%|dd |d s|j(d!kr |) |)  d S d S d S )"Nr   )TestCasepyplotrcParams)FigureCanvasBaseF   zwebagg.open_in_browserzwebagg.port_retries   r5   agg)gtk3webr   Tforcec                    s2   j | dd  } t|jjd|  d S )NTrD   matplotlib.backends.backend_{})usefiguretypecanvas
__module__r&   )alt_backendfig)assert_equalmplpltr   r   check_alt_backendp   s   
z1_test_interactive_impl.<locals>.check_alt_backendr
   r   svgrF      g      ?q
draw_eventc                    s      S )N)start)event)timerr   r   <lambda>   s    z(_test_interactive_impl.<locals>.<lambda>close_eventpng)r&         ?r   r   )*importlib.utiliojsonr#   unittestr9   
matplotlibr;   r<   matplotlib.backend_basesr=   updatelenargvloadslowerassertEqualassertRaisesendswithr/   rH   r"   rG   r   r   subplotsrI   rJ   rK   r&   plot	new_timeradd_callbackkey_press_eventmpl_connectprintBytesIOsavefigshowpauser$   getvalue)r   r_   r`   r#   r9   r<   r=   r5   assert_raisesrQ   rM   axresultresult_afterr   )rN   rO   rP   rY   r   _test_interactive_implK   s^   



r|   r5   toolbartoolbar2toolmanagerrT   )rerunsc                 C   s   | dkr|dkrt d tjtjdttd t	
d|igi tj| ddttjd	d
}|jr<t d|j d |jddksFJ d S )Nr   r   z*toolmanager is not implemented for macosx.-c
_test_interactive_impl()r}   0
MPLBACKENDSOURCE_DATE_EPOCHT)envtimeoutstdoutuniversal_newlines2The subprocess returned with non-zero exit status .
CloseEventr>   )r,   r.   
subprocessrunr#   
executableinspect	getsourcer|   r`   dumpsr(   r)   _test_timeoutPIPE
returncodefailr   count)r5   r}   procr   r   r   test_interactive_backend   s&   

r   c                  C   s   ddl m}  dd l}dd l}ddlm}m} |ddd t|j	dkr0||
|j	d  | \}}|d |  |jg d	}|  |jd
t |  |jj}|d |  |  |j  d S )Nr   )ThreadPoolExecutorr:   Fr>   r?   r@   r]   )r>   rT      r[   )concurrent.futuresr   r`   r#   rb   r;   r<   rd   re   rf   rg   rl   rv   submitrm   rz   rJ   rq   rr   drawcloseflush_events)r   r`   r#   rP   r<   rM   ry   futurer   r   r   _test_thread_impl   s(   

r   r   )raisesr   r   T)r   strictc                 C   sR   t jtjdttd gi tj| ddt	dt j
dd}|jddks'J d S )	Nr   z
_test_thread_impl()r   r   T)r   r   checkr   r   r   r>   )r   r   r#   r   r   r   r   r(   r)   r   r   r   r   )r5   r   r   r   r   test_interactive_thread_safety   s   r   r   z,this test fails an azure for unknown reasonsr   ntzCannot send SIGINT on Windows.c                  C   s   t d tjtjdttd gi t	j
dddd} dtjd	 tjd
 }t t }	 z|  }|d u s;J tj|}W n tjjy[   t |krWt d nY q/Y nw q0|  | tj | jtddksqJ d S )Ntornador   r   webaggr   r   )r   zhttp://{}:{}zwebagg.addresszwebagg.portTz'Failed to connect to the webagg server.)r   r   )r,   importorskipr   Popenr#   r   r   r   r|   r(   r)   r&   rO   r<   timeperf_counterr   pollurllibrequesturlopenerrorURLErrorr   r   send_signalsignalSIGINTwait)r   urlr   retcodeconnr   r   r   test_webagg   s:   
r   r   zthis a linux-only testQt5Agg)skip_on_importerrorc                  C   s8   d} t tjd| g}|jrtd|j d d S d S )Na  
import os
import sys

# make it look headless
os.environ.pop('DISPLAY', None)
os.environ.pop('WAYLAND_DISPLAY', None)

# we should fast-track to Agg
import matplotlib.pyplot as plt
plt.get_backend() == 'agg'
assert 'PyQt5' not in sys.modules

# make sure we really have pyqt installed
import PyQt5
assert 'PyQt5' in sys.modules

# try to switch and make sure we fail with ImportError
try:
    plt.switch_backend('qt5agg')
except ImportError:
    ...
else:
    sys.exit(1)

r   r   r   )r   r   r#   r   r   r,   r   )test_scriptr   r   r   r   test_lazy_linux_headless  s   r   )'r   r^   r   r`   r(   r   r   r#   r   urllib.requestr   r,   rb   rO   r   r7   r   r|   r-   parametrizeflakyr   r   _thread_safe_backendsr1   valuesr5   r    r+   r0   CalledProcessErrorTimeoutExpiredr   skipifr)   namer   r$   r   r   r   r   r   <module>   s`    +
R

