o
    j"                     @   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mZ d dl	m
Z
 dZd ddZeddd	d
 Zedddd Zejje dkddejjddedddd Zejjdded ddd Zedddd Zedddd Zedddd Zedddd ZdS )!    N)_c_internal_utils)subprocess_run_helper<   c                    s    du r
t tS dtjv r S tjjtj	
d ddtjjtjdko)t  ddtjjdtjv s9d	tjv oFtjd
koFtjdd dk ddt   fdd}|S )z
    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
    NMPL_TEST_ESCAPE_HATCHtkinterzmissing tkinterreasonlinuxz$DISPLAY is unsetZTF_BUILDZGITHUB_ACTIONdarwin   )      z%Tk version mismatch on Azure macOS CIc               
      s   t d ztttdddd} W n- tjy"   t d Y d S  tjy? } zt dt	|j
  W Y d }~d S d }~ww g d  fd	d
| j
 D rRJ | jdks\J d S )Nr   ZTkAgg1)Z
MPLBACKENDr   )timeoutZ	extra_envzSubprocess timed outz,Subprocess failed to test intended behavior
)ZOpenGLz!CFMessagePort: bootstrap_registerz%/usr/include/servers/bootstrap_defs.hc                    s&   g | ] t  fd dD r qS )c                 3   s    | ]}| vV  qd S N ).0msgliner   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/matplotlib/tests/test_backend_tk.py	<genexpr>E   s    zB_isolated_tk_test.<locals>.test_func.<locals>.<listcomp>.<genexpr>)all)r   Zignored_linesr   r   
<listcomp>D   s    
z8_isolated_tk_test.<locals>.test_func.<locals>.<listcomp>success)pytestZimportorskipr   _test_timeoutdict
subprocessTimeoutExpiredZfailCalledProcessErrorstrstderr
splitlinesstdoutcount)procefuncsuccess_countr   r   	test_func!   s$   

	z$_isolated_tk_test.<locals>.test_func)	functoolspartial_isolated_tk_testosenvironr   markskipif	importlibutil	find_specsysplatformr   Zxdisplay_is_validZxfailversion_infowraps)r+   r*   r,   r   r)   r   r/      s,   	
r/      )r+   c               	   C   s   dd l m}  dd l}dd l}ddlm}m} |  \}}|jj	}|j
d|jd}d}	|	D ]!}
z||j t|||jd|
 W q, tyM   td Y q,w | | |||d d S )Nr   )_backend_tk_tkagg)   r>   r>   )Zdtype))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pyplotnumpy!matplotlib.backends.backend_tkaggZmatplotlib.backendsr<   r=   ZsubplotscanvasZ_tkphotoZonesZuint8ZblittkZ
interpaddrr"   ZTK_PHOTO_COMPOSITE_OVERLAY
ValueErrorprintclose)pltnp
matplotlibr<   r=   figaxZ
photoimagedataZ	bad_boxesZbad_boxr   r   r   	test_blitK   s&   
rP   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plotrI   afterr   )legitimate_quitrJ   rootr   r   do_ploto   s   z;test_figuremanager_preserves_host_mainloop.<locals>.do_plotc                      s       d d S NT)quitappendr   )rV   r   r   r   rU   u   s   zCtest_figuremanager_preserves_host_mainloop.<locals>.legitimate_quitr   )r   rA   rB   TkrT   mainlooprH   )r   rW   r   )rU   rJ   rV   r   r   *test_figuremanager_preserves_host_mainloopi   s   r]   CPythonzZPyPy does not support Tkinter threading: https://foss.heptapod.net/pypy/pypy/-/issues/1929r   r   )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   rQ   c                      s>   d  ks d d  kr   rtd d S d S )NrF   g{Gz?r   )sleeprI   waitrH   r   r_   rJ   Zshow_finished_eventtimer   r   target   s   


z6test_figuremanager_cleans_own_mainloop.<locals>.targetT)re   daemonblock)r   rd   rA   rB   	threadingZmatplotlib.cbookr_   r[   rS   EventThreadstartshowsetjoin)r   ri   rV   re   threadr   rc   r   &test_figuremanager_cleans_own_mainloop   s   rq   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   Frg   d   T)r   ZMiscupdateZupdate_idletasksrA   rB   rR   rm   drawrE   toolbarZconfigure_subplotsget_tk_widgetrT   rI   )r   rJ   rM   r   r   r   test_never_update   s   rw   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HomePanZZoomr   )r   tr   r   r   r      s    z4test_missing_back_button.<locals>.Toolbar.<listcomp>N)__name__
__module____qualname__Z	toolitemsr   rx   r   r   Toolbar   s    r   r   )	rA   rB   rD   ry   rR   rH   rE   managerZwindow)rJ   r   rM   r   rx   r   test_missing_back_button   s   r   c                  C   s   dd l m}  ddlm} |  }d}|j|dd |jjj	 }t
d |dks,J td W d    n1 s:w   Y  |j|dd |jjj	 }|d u sTJ td W d    d S 1 scw   Y  d S )Nr   )mockz$tkinter.filedialog.asksaveasfilenamez
foobar.png)return_valuer    )rA   rB   Zunittestr   rR   patchrE   r   ru   Zsave_figurer0   removerH   )rJ   r   rM   propfnamer   r   r   test_save_figure_return   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 rX   )rE   rv   Zwinfo_viewableZwait_visibilityZfocus_lastforrZ   rI   destroy)ZtkcanvasrM   rJ   rV   r   r   r   check_focus   s   

z&test_canvas_focus.<locals>.check_focusr`   rr   r   )
r   rA   rB   r[   rR   rS   rT   rm   r\   rH   )rF   r   r   r   r   test_canvas_focus   s   r   c                     s~   dd l } ddlmm ddlm ddlm  |  } fdd}|| t	d |j
dd	d
d || t	d d S )Nr   )FigureCanvasTkAggry   )key_press_handler)Figurec                    s     }|  }|g d || d}|  |d | jddd || dd}|jdd	d |   |  d S )
Nr`   )masterZkey_press_eventTZboth)expandfillF)Zpack_toolbarx)Zadd_subplotrS   rt   Zmpl_connectrv   packZforget)r   rM   rN   rE   ru   r   r   ry   r   r   r   test_figure   s   z#test_embedding.<locals>.test_figurer   zsky bluezmidnight bluewhite)
backgroundZselectColor
foreground)r   rD   r   ry   Zmatplotlib.backend_basesr   Zmatplotlib.figurer   r[   rH   Ztk_setPalette)rF   rV   r   r   r   r   test_embedding   s   r   r   )r-   r4   r0   r8   r   r7   r   rL   r   Zmatplotlib.testingr   r   r/   rP   r]   r2   r3   python_implementationZflakyrq   rw   r   r   r   r   r   r   r   r   <module>   s@    
:




