o
    :a                     @   s0  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ZdddZ	ej
jddde	dd	d
d Zej
jddde	dd	dd Zej
je dkddej
jdddej
jdde	dd	dd Zej
jdddej
jdde	d d	dd Zej
jddde	dd	dd ZdS )    N<   c                    sJ    du r
t tS tdt dt   fdd}|S )a  
    A decorator to run *func* in a subprocess and assert that it prints
    "success" *success_count* times and nothing on stderr.

    TkAgg tests seem to have interactions between tests, so isolate each test
    in a subprocess. See GH#18261

    The decorated function must be fully self-contained, and thus perform
    all the imports it needs.  Because its source is extracted and run by
    itself, coverage will consider it as not being run, so it should be marked
    with ``# pragma: no cover``
    Nz(?ms)^def .*r   c               	      s   z"t jtjd d j dgi tjdditt jt jddd} W n t j	y2   t
d Y d S  t jyA   t
d	 Y d S w d
d | j D rNJ | jdksXJ d S )Nz-c
z()Z
MPLBACKENDTkAggT)envZtimeoutstdoutstderrcheckZuniversal_newlineszSubprocess timed outz+Subprocess failed to test intended behaviorc                 S   s   g | ]}d |vr|qS )ZOpenGL ).0liner	   r	   B/usr/lib/python3/dist-packages/matplotlib/tests/test_backend_tk.py
<listcomp>7   s    
z8_isolated_tk_test.<locals>.test_func.<locals>.<listcomp>success)
subprocessrunsys
executable__name__osenviron_test_timeoutPIPEZTimeoutExpiredpytestZfailZCalledProcessErrorr   
splitlinesr   count)procfuncsourcesuccess_countr	   r   	test_func"   s"   
	z$_isolated_tk_test.<locals>.test_func)		functoolspartial_isolated_tk_testresearchinspectZ	getsourcegroupwraps)r   r   r    r	   r   r   r#      s   r#   r   T)Zskip_on_importerror   )r   c               	   C   s   dd l m}  dd l}ddlm} |  \}}|jj}|d}|j	d d \}}|||j
jf}	d}
|
D ] }z||j t||	dd| W q3 tyS   td Y q3w d S )Nr   )_tkagg)   r+   r+      ))r,   r   r,   )r,   r   r   r,   )   r)   r   r,   )r   r,   r-   r,   )r   r,   r,   r   )r   r,   r.   r)   )r   r.   r,      r   )matplotlib.pyplotpyplotZnumpyZmatplotlib.backendsr*   ZsubplotscanvasZ_tkphotoZonesshapeZctypesdataZblittkZ
interpaddrstr
ValueErrorprint)pltZnpr*   figZaxZ
photoimager4   ZheightwidthZdataptrZ	bad_boxesZbad_boxr	   r	   r   	test_blit>   s&   
r<   r.   c                     sf   dd l } dd lm g  fdd}fdd |  d|   r1td d S d S )Nr   c                      s4      ddgddg   d  d S )Nr.   r,   r/      r   )figureplotcloseafterr	   )legitimate_quitr9   rootr	   r   do_plota   s   z;test_figuremanager_preserves_host_mainloop.<locals>.do_plotc                      s       d d S )NT)quitappendr	   )rC   r   r	   r   rB   g   s   zCtest_figuremanager_preserves_host_mainloop.<locals>.legitimate_quitr   )tkinterr0   r1   TkrA   Zmainloopr8   )rG   rD   r	   )rB   r9   rC   r   r   *test_figuremanager_preserves_host_mainloopZ   s   rI   ZCPythonzZPyPy does not support Tkinter threading: https://foss.heptapod.net/pypy/pypy/-/issues/1929)reasonr/   )Zrerunsc                     s   dd l } dd ldd lm dd l}ddlm  |  }g dg d  fdd}|	 |j
|dd}|  jdd	   |  d S )
Nr   )"_get_running_interactive_framework)r.   r,   r/   )r.   r,   r=   c                      s>   d  ks d d  kr   rtd d S d S )Nr5   g{Gz?r   )sleepr@   waitr8   r	   rK   r9   Zshow_finished_eventtimer	   r   target   s   


z6test_figuremanager_cleans_own_mainloop.<locals>.targetT)rP   Zdaemonblock)rG   rO   r0   r1   	threadingZmatplotlib.cbookrK   rH   r?   ZEventZThreadstartshowsetjoin)rG   rS   rC   rP   threadr	   rN   r   &test_figuremanager_cleans_own_mainloops   s   rY   c                  C   s`   dd l } | j`| j`dd lm} | }|jdd |  |j	j
  |d || d S )Nr   FrQ   g?)rG   ZMiscupdateZupdate_idletasksr0   r1   r>   rU   Zdrawr2   ZtoolbarZconfigure_subplotspauser@   )rG   r9   r:   r	   r	   r   test_never_update   s   
r\   r,   c                     sZ   dd l m}  ddlm  G  fddd }|  }td ||j|jjj td d S )Nr   NavigationToolbar2Tkc                       s   e Zd Zdd  jD ZdS )z)test_missing_back_button.<locals>.Toolbarc                 S   s   g | ]
}|d  dv r|qS )r   )ZHomeZPanZZoomr	   )r
   tr	   r	   r   r      s    

z4test_missing_back_button.<locals>.Toolbar.<listcomp>N)r   
__module____qualname__Z	toolitemsr	   r]   r	   r   Toolbar   s    rb   r   )	r0   r1   Z!matplotlib.backends.backend_tkaggr^   r>   r8   r2   ZmanagerZwindow)r9   rb   r:   r	   r]   r   test_missing_back_button   s   rc   )N)r!   r&   r   platformr$   r   r   r   r   r#   ZmarkZbackendr<   rI   ZskipifZpython_implementationZflakyrY   r\   rc   r	   r	   r	   r   <module>   s<    
0