o
    tBh                     @   sR  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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yO } zt
d	t|j  W Y d }~d S d }~ww d
d | j D r\J | jdksfJ d S )Nz-c
z()
MPLBACKENDTkAggT)envtimeoutstdoutstderrcheckuniversal_newlineszSubprocess timed outz,Subprocess failed to test intended behavior
c                 S   s   g | ]}d |vr|qS )OpenGL ).0liner   r   w/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/matplotlib/tests/test_backend_tk.py
<listcomp>8   s    z8_isolated_tk_test.<locals>.test_func.<locals>.<listcomp>success)
subprocessrunsys
executable__name__osenviron_test_timeoutPIPETimeoutExpiredpytestfailCalledProcessErrorstrr	   
splitlinesr   count)procefuncsourcesuccess_countr   r   	test_func"   s(   
	z$_isolated_tk_test.<locals>.test_func)		functoolspartial_isolated_tk_testresearchinspect	getsourcegroupwraps)r(   r&   r)   r   r%   r   r,      s   r,   r   T)skip_on_importerror   )r(   c               	   C   s   dd l m}  dd l}dd l}ddlm} |  \}}|jj}|	d}|j
d d \}}	||	|jjf}
d}|D ] }z||j t||
dd| W q7 tyW   td Y q7w d S )Nr   )_tkagg)   r6   r6      ))r7   r   r7   )r7   r   r   r7   )   r4   r   r7   )r   r7   r8   r7   )r   r7   r7   r   )r   r7   r9   r4   )r   r9   r7      r   )matplotlib.pyplotpyplotnumpy!matplotlib.backends.backend_tkaggmatplotlib.backendsr5   subplotscanvas_tkphotoonesshapectypesdatablittk
interpaddrr    
ValueErrorprint)pltnp
matplotlibr5   figax
photoimagerF   heightwidthdataptr	bad_boxesbad_boxr   r   r   	test_blit?   s(   
rW   r9   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 )Nr9   r7   r:      r   )figureplotcloseafterr   )legitimate_quitrL   rootr   r   do_plotc   s   z;test_figuremanager_preserves_host_mainloop.<locals>.do_plotc                      s       d d S NT)quitappendr   )r^   r   r   r   r]   i   s   zCtest_figuremanager_preserves_host_mainloop.<locals>.legitimate_quitr   )tkinterr;   r<   Tkr\   mainlooprK   )rc   r_   r   )r]   rL   r^   r   r   *test_figuremanager_preserves_host_mainloop\   s   rf   CPythonzZPyPy does not support Tkinter threading: https://foss.heptapod.net/pypy/pypy/-/issues/1929)reasonr:   )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r9   r7   r:   )r9   r7   rX   c                      s>   d  ks d d  kr   rtd d S d S )NrH   g{Gz?r   )sleepr[   waitrK   r   rj   rL   show_finished_eventtimer   r   target   s   


z6test_figuremanager_cleans_own_mainloop.<locals>.targetT)rq   daemonblock)rc   rp   r;   r<   	threadingmatplotlib.cbookrj   rd   rZ   EventThreadstartshowsetjoin)rc   ru   r^   rq   threadr   rn   r   &test_figuremanager_cleans_own_mainloopu   s   r~   c                  C   sn   dd l } | j`| j`dd lm} | }|jdd |  |j	j
  |j	 d|j| |jdd d S )Nr   Frs   d   T)rc   Miscupdateupdate_idletasksr;   r<   rY   rz   drawrA   toolbarconfigure_subplotsget_tk_widgetr\   r[   )rc   rL   rO   r   r   r   test_never_update   s   r   r7   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   )HomePanZoomr   )r   tr   r   r   r      s    z4test_missing_back_button.<locals>.Toolbar.<listcomp>N)r   
__module____qualname__	toolitemsr   r   r   r   Toolbar   s    r   r   )	r;   r<   r>   r   rY   rK   rA   managerwindow)rL   r   rO   r   r   r   test_missing_back_button   s   r   c                     s~   dd l } dd lm g  fdd}|    g d dj d|   r=t	d d S d S )Nr   c                     sD    j  } |  s|   |  | krd     d S r`   )rA   r   winfo_viewablewait_visibilityfocus_lastforrb   r[   destroy)tkcanvasrO   rL   r^   r   r   r   check_focus   s   

z&test_canvas_focus.<locals>.check_focusrk   r   r   )
rc   r;   r<   rd   rY   rZ   r\   rz   re   rK   )rH   r   r   r   r   test_canvas_focus   s   r   )N)r*   r/   r   platformr-   r   r   r   r   r,   markbackendrW   rf   skipifpython_implementationflakyr~   r   r   r   r   r   r   r   <module>   sB    
1