+
     ]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            	      s  <a \         P                  ! R 4        \        S\        \	        RRR7      R7      p . ROpV P
                  P                  4        Uau. uFG  o\        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       g   KE  SNKI  	  up'       d   Q hV P                  P                  R4      S8X  g   Q hR# u upi   \        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_envc              3   s,   <"   T F	  qS9  x  K  	  R # 5iN )Z.0Zmsglines   & G/usr/lib64/python3.14/site-packages/matplotlib/tests/test_backend_tk.pyZ	<genexpr>Z7_isolated_tk_test.<locals>.test_func.<locals>.<genexpr>E   s     H-3$-s   FTsuccessz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dictZstderrZ
splitlinesZallZstdoutZcount
subprocessZTimeoutExpiredZfailZCalledProcessErrorstr)ZprocZignored_linesr	   Zefuncsuccess_counts     ` r
   	test_funcZ$_isolated_tk_test.<locals>.test_func!   s   " 	I&	A(mt&c8CDDFM)-)?)?)A J)A3H-H333H-HH )A J J J J;;$$Y/=@@@J (( 	0KK./,, 	)KKGahh-( ) )	)s;   C C(C?CC+EEE0EE)   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dtyper   )   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)r3   r   s   r
   r2   ZCtest_figuremanager_preserves_host_mainloop.<locals>.legitimate_quitu   s    		tr   r   )r   r#   r$   Tkr1   mainloopr(   )r   r4   r2   r*   r3   r        @@@@r
   *test_figuremanager_preserves_host_mainloopr:   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(   )r;   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.cbookr;   r7   r0   ZEventZThreadZstartshowZsetZjoin)	r   rA   r3   r>   Zthreadr;   r*   r<   r=   s	        @@@@r
   &test_figuremanager_cleans_own_mainlooprC      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/   rB   drawr&   toolbarZconfigure_subplotsget_tk_widgetr1   r)   )r   r*   r,   s      r
   test_never_updaterG      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>.Toolbarr   N)ZHomeZPanZZoom)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z	toolitemsZ__static_attributes__)ZtrH   s   0r
   ToolbarrI      s:     4 > > 6 >1qT44 Q > 6	 6s   99rJ   r   )	r#   r$   r%   rH   r/   r(   r&   managerZwindow)r*   rJ   r,   rH   s      @r
   test_missing_back_buttonrL      sQ    #F6& 6
 **,C	)CJJ

**112	)r   c                  sN   ^ 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       VR8X  g   Q h\        R4       RRR4       VP                  VRR7      ;_uu_ 4        VP                  P                  P                  P                  4       pVe   Q h\        R4       RRR4       R#   + '       g   i     Lu; i  + '       g   i     R# ; i)r    N)mockz$tkinter.filedialog.asksaveasfilenamez
foobar.png)Zreturn_valuer   Z )r#   r$   ZunittestrM   r/   Zpatchr&   rK   rE   Zsave_figurer   Zremover(   )r*   rM   r,   ZpropZfnames        r
   test_save_figure_returnrN      s    #
**,C1D	D|	4	4

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

""**668}}i 
+	* 
5	4
 
+	*	*s   AD 6A D 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# r5   )r&   rF   Zwinfo_viewableZwait_visibilityZfocus_lastforr6   r)   Zdestroy)Ztkcanvasr,   r*   r3   r   s    r
   check_focusZ&test_canvas_focus.<locals>.check_focus   sa    ::++-&&(($$& !!#x/NN4 		r   r   r@   )
r   r#   r$   r7   r/   r0   r1   rB   r8   r(   )r'   rO   r,   r*   r3   r   r9   r
   test_canvas_focusrP      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)FigureCanvasTkAggrH   )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_subplotr0   rD   Zmpl_connectrF   ZpackZforget)	rT   r,   r-   r&   rE   rS   rQ   rH   rR   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%   rQ   rH   Zmatplotlib.backend_basesrR   Zmatplotlib.figurerS   r7   r(   Ztk_setPalette)r'   r3   rU   rS   rQ   rH   rR   s      @@@@r
   test_embeddingrV      sd    1:(557D   	)
 	*/")  +	)r   r   )r   r   r   r   r   r   r   r+   r   Zmatplotlib.testingr   r   r   r.   r:   r   r   Zpython_implementationZflakyrC   rG   rL   rN   rP   rV   r   r   r
   <module>rW      s_     	   
  ( 4 7t #5 $5: # $. H224	AO  P !# $ P
2 !# $ , # $ # $  # $8 #" $"r   