+
     ]i"  c                   s4   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^<tRR lt]! ^R7      R 4       t]! ^R7      R 4       t]P                  P!                  ]P"                  ! 4       R8g  R	R
7      ]P                  P%                  ^R7      ]! ^R7      R 4       4       4       t]P                  P%                  ^R7      ]! ^ R7      R 4       4       t]! ^R7      R 4       t]! ^R7      R 4       t]! ^R7      R 4       t]! ^R7      R 4       tR# )    N)_c_internal_utils)subprocess_run_helperc                s
  a a Sf   \         P                  ! \        S 4      # R\        P                  9   d   S# \
        P                  P                  \        P                  P                  R4      '       * RR7      \
        P                  P                  \        P                  R8H  ;'       d    \        P                  ! 4       '       * RR7      \
        P                  P                  R\        P                  9   ;'       g    R\        P                  9   ;'       d6    \        P                  R	8H  ;'       d    \        P                   R
,          R8  RR7      \         P"                  ! S4      VV 3R l4       4       4       4       pV# )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
MPL_TEST_ESCAPE_HATCHtkinterzmissing tkinterZreasonZlinuxz$DISPLAY is unsetZTF_BUILDZGITHUB_ACTIONZdarwin:N   Nz%Tk version mismatch on Azure macOS CIc            	      sz  <a \         P                  ! R 4        \        S\        \	        RRR7      R7      p . ROpR#   \
        P                   d    \         P                  ! R4        R# \
        P                   d<   p\         P                  ! R\        TP                  4      ,           4        Rp?R# Rp?ii ; i)	r   ZTkAggZ1)Z
MPLBACKENDr   )ZtimeoutZ	extra_envzSubprocess timed outz,Subprocess failed to test intended behavior
N)ZOpenGLz!CFMessagePort: bootstrap_registerz%/usr/include/servers/bootstrap_defs.h)pytestZimportorskipr   _test_timeoutZdict
subprocessZTimeoutExpiredZfailZCalledProcessErrorstrZstderr)ZprocZignored_linesZeZlinefuncsuccess_counts      @G/usr/lib64/python3.14/site-packages/matplotlib/tests/test_backend_tk.py	test_funcZ$_isolated_tk_test.<locals>.test_func!   s    " 	I&	A(mt&c8CDDFM (( 	0KK./,, 	)KKGahh-( ) )	)s!   = +B:+B:>B:?0B55B:)   i   )	functoolsZpartial_isolated_tk_testosZenvironr   markskipif	importlibZutilZ	find_specsysplatformr   Zxdisplay_is_validZxfailZversion_infoZwraps)r   r   r   s   ff r   r   r      sA    |  !2MBB"**,[[NN$$Y//    [[MM(9(K(K(M$M"   [[	rzz	!	B	B_

%B 	D 	D 	D 	D%(%5%5b%9G%C6  
 __TA 		A2     )r   c            	      s   ^ RI Hp  ^ RIp^ RIp^ RIHpHp V P                  4       w  rVVP                  P                  pVP                  RVP                  R7      pRp	V	 FE  p
 VP                  VP                  P                  4       \        V4      VVP                   RV
4       KG  	  V P'                  V4       VP                  WxR4       R#   \"         d    \%        R4        K  i ; i)r    N)_backend_tk_tkagg)Zdtypesuccess)   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numpy!matplotlib.backends.backend_tkaggZmatplotlib.backendsr   r   ZsubplotscanvasZ_tkphotoZonesZuint8ZblittkZ
interpaddrr
   ZTK_PHOTO_COMPOSITE_OVERLAYZ
ValueErrorprintclose)pltZnp
matplotlibr   r   figaxZ
photoimageZdataZ	bad_boxesZbad_boxs              r   	test_blitr+   K   s    #,7llnGC$$J779BHH7-DI 	KK((*C
OT11<J  IIcNZ|4  	)	s   $ACC('C(c                  s   aaaa ^ RI p ^ RIHo . oVVV3R lpVV3R loV P                  4       oSP	                  ^ V4       SP                  4        S'       d   \        R4       R# R# )r    Nc                  s   < SP                  4        SP                  ^^.^^.4       SP                  4        SP                  ^ S 4       R# )r   N)figureplotr&   after)legitimate_quitr'   roots   r   do_plotZ;test_figuremanager_preserves_host_mainloop.<locals>.do_ploto   s9    

!Q!Q 		

1o&r   c                  sJ   < S P                  4        SP                  R 4       R# TN)Zquitappend)r0   r   s   r   r/   ZCtest_figuremanager_preserves_host_mainloop.<locals>.legitimate_quitu   s    		tr   r   )r   r    r!   Tkr.   mainloopr%   )r   r1   r/   r'   r0   r        @@@@r   *test_figuremanager_preserves_host_mainloopr7   i   sL    #G' ::<DJJq'MMOi r   ZCPythonzZPyPy does not support Tkinter threading: https://foss.heptapod.net/pypy/pypy/-/issues/1929r   )Zrerunsc                  sf  aaaa ^ RI p ^ RIo^ RIHo ^ RIp^ RIHo V P                  4       pSP                  . RO. RO4       VVVV3R lpVP                  4       oVP                  VRR7      pVP                  4        SP                  RR7       SP                  4        VP                  4        R# )	r    N)"_get_running_interactive_frameworkc                  s   < R S ! 4       8X  g   SP                  R4       K  SP                  4        SP                  4       '       d   \        R4       R# R# )r$   g{Gz?r   N)Zsleepr&   Zwaitr%   )r8   r'   show_finished_eventtimes   r   targetZ6test_figuremanager_cleans_own_mainloop.<locals>.target   s?    <>>JJsO		##%%) &r   T)r;   ZdaemonZblockr   r   r   )r   r   i   )r   r:   r    r!   	threadingZmatplotlib.cbookr8   r4   r-   ZEventZThreadZstartshowZsetZjoin)	r   r>   r0   r;   Zthreadr8   r'   r9   r:   s	        @@@@r   &test_figuremanager_cleans_own_mainloopr@      s     #C::<DHHY	"  $//+VD9F
LLNHH4H
KKMr   c                  s   ^ RI p V P                  =V P                  =^ RIHp VP                  4       pVP                  RR7       VP                  4        VP                  P                  P                  4        VP                  P                  4       P                  ^dVP                  V4       VP                  RR7       R# )r    NFr<   T)r   ZMiscZupdateZupdate_idletasksr    r!   r,   r?   drawr#   toolbarZconfigure_subplotsget_tk_widgetr.   r&   )r   r'   r)   s      r   test_never_updaterD      s     %#
**,CHH5HHHJJJ))+JJ$$S#))S9 HH4Hr   c                  s   a ^ RI Hp  ^ RIHo  ! V3R lRS4      pV P	                  4       p\        R4       V! VP                  VP                  P                  P                  4       \        R4       R# )r    N)NavigationToolbar2Tkc                   s|   < ] tR t^t ZP                   U u. uF  p V ^ ,          R9   g   K  V NK  	  up tRtR# u up i ))test_missing_back_button.<locals>.Toolbar N)ZHomeZPanZZoom)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z	toolitemsZ__static_attributes__)ZtrE   s   0r   ToolbarrF      s:     4 > > 6 >1qT44 Q > 6	 6s   99rH   r   )	r    r!   r"   rE   r,   r%   r#   managerZwindow)r'   rH   r)   rE   s      @r   test_missing_back_buttonrJ      sQ    #F6& 6
 **,C	)CJJ

**112	)r   c                  s0   ^ RI Hp  ^ RIHp V P	                  4       pRpVP                  VRR7      ;_uu_ 4        VP                  P                  P                  P                  4       p\        P                  ! R4       \        R4       RRR4       VP                  VRR7      ;_uu_ 4        VP                  P                  P                  P                  4       p\        R4       RRR4       R#   + '       g   i     Lo; i  + '       g   i     R# ; i)r    N)mockz$tkinter.filedialog.asksaveasfilenamez
foobar.png)Zreturn_valuer   Z )r    r!   ZunittestrK   r,   Zpatchr#   rI   rB   Zsave_figurer   Zremover%   )r'   rK   r)   ZpropZfnames        r   test_save_figure_returnrL      s    #
**,C1D	D|	4	4

""**668
		,i	 
5
 
Dr	*	*

""**668i 
+	* 
5	4
 
+	*	*s   AC1-:D1D	D	c                  sD  aaaa ^ RI p ^ RIHo . oVVVV3R lpV P                  4       oSP	                  4       oSP                  . RO4       SP                  ^ SP                  4       SP                  ^dV4       SP                  4        S'       d   \        R4       R# R# )r    Nc                  s  < SP                   P                  4       p V P                  4       '       g   V P                  4        V P	                  4       V 8X  d   SP                  R 4       SP                  4        SP                  4        R# r2   )r#   rC   Zwinfo_viewableZwait_visibilityZfocus_lastforr3   r&   Zdestroy)Ztkcanvasr)   r'   r0   r   s    r   check_focusZ&test_canvas_focus.<locals>.check_focus   sa    ::++-&&(($$& !!#x/NN4 		r   r   r=   )
r   r    r!   r4   r,   r-   r.   r?   r5   r%   )r$   rM   r)   r'   r0   r   r6   r   test_canvas_focusrN      su    #G
 
 557D
**,CHHYJJq#((JJsK MMOi r   c                  s   aaaa ^ RI p ^ RIHoHo ^ RIHo ^ RIHo V P                  4       pVVVV3R lpV! V4       \        R4       VP                  RRR	R
7       V! V4       \        R4       R# )r    N)FigureCanvasTkAggrE   )key_press_handler)Figurec                 s  < S! 4       pVP                  4       pVP                  . R
O4       S! WR7      pVP                  4        VP                  RS4       VP	                  4       P                  RRR7       S! W0RR7      pVP                  RRR7       VP	                  4       P                  4        VP                  4        R	# )r   )masterZkey_press_eventTZboth)ZexpandZfillF)Zpack_toolbarZxNr=   )Zadd_subplotr-   rA   Zmpl_connectrC   ZpackZforget)	rR   r)   r*   r#   rB   rQ   rO   rE   rP   s	   &    r   test_figureZ#test_embedding.<locals>.test_figure   s    h__
	"36,.?@##4f#=&vEJDs+%%'r   r   zsky bluezmidnight blueZwhite)Z
backgroundZselectColorZ
foreground)r   r"   rO   rE   Zmatplotlib.backend_basesrP   Zmatplotlib.figurerQ   r4   r%   Ztk_setPalette)r$   r0   rS   rQ   rO   rE   rP   s      @@@@r   test_embeddingrT      sd    1:(557D   	)
 	*/")  +	)r   )N)r   r   r   r   r	   r   r   r(   r   Zmatplotlib.testingr   r   r   r+   r7   r   r   Zpython_implementationZflakyr@   rD   rJ   rL   rN   rT   rG   r   r   <module>rU      s_     	   
  ( 4 7t #5 $5: # $. H224	AO  P !# $ P
2 !# $ , # $ # $  # $8 #" $"r   