
    (g5l                     ,   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 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 dlmZ d dlmZ d dlmZ d dlmZ ej,                  Z G d d	ej.                        Zed
k(  r ej4                          yy)    N)support)import_helper)	os_helper)script_helper)socket_helper)warnings_helperc                      e Zd Zed        Zed        Zd Zd Zd Zd Z	 e
j                  d      d        Zd	 Zd
 Zd Zd Z ej$                         d        Z ej$                         d        Z ej$                         d        Zd Zd Zd Zd Z ej4                         d        Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d  Z'd! Z(d" Z)d# Z*d$ Z+d% Z,d& Z- G d' d(      Z. G d) d*      Z/d+ Z0d, Z1d- Z2 e
jf                   e4e5d.      xr	  e4e5d/      d0       ej4                         d1               Z6 ejn                         dBd3       Z8 ejr                  d4      d5        Z:d6 Z; e
jx                  ejz                  d7       e
jx                  ej|                  d8      d9               Z?d: Z@d; ZAd< ZBd= ZCd> ZDd? ZEd@ ZFdA ZGy2)CTestSupportc                     t        t        j                        }t        j                  dd      | _        t        j                  t        d      | _        t        t        j                        |dz   k(  sJ y )Nztest.support.warnings_helperz.*used in test_support.*)likez!.*You should NOT be seeing this.*   )lenwarningsfiltersr   ignore_deprecations_from_warnings_helper_token__name___test_support_tokenclsorig_filter_lens     (/usr/lib/python3.12/test/test_support.py
setUpClasszTestSupport.setUpClass   sf    h../%,%E%E*1K&
" #*"B"B>#
 8##$!(;;;;    c                     t        t        j                        }t        j                  | j
                  | j                         t        t        j                        |dz
  k(  sJ y )Nr   )r   r   r   r   clear_ignored_deprecationsr   r   r   s     r   tearDownClasszTestSupport.tearDownClass&   sR    h../**&&##	
 8##$!(;;;;r   c                 <   t        j                  d      5 }t        j                          t        j                  dt
               |D cg c]  }t        |j                         }}ddd       | j                  t              d|       yc c}w # 1 sw Y   +xY w)z9Test support.ignore_deprecations_from() silences warningsT)recordzYou should NOT be seeing this.Nr   )
r   catch_warningsr   _warn_about_deprecationwarnDeprecationWarningstrmessageassertEqualr   )selfwarning_objswmessagess       r   $test_ignored_deprecations_are_silentz0TestSupport.test_ignored_deprecations_are_silent/   s{    $$D1 	>\335MM:<NO0<=1AII=H=	> 	X84 >	> 	>s   3B
B&BBBc                     t        j                  d       | j                  t        j                  t         j                  d       y )Nftplibfoo)r   import_moduleassertRaisesunittestSkipTestr'   s    r   test_import_modulezTestSupport.test_import_module7   s1    ##H-(++'55u	>r   c                 .    t        j                  d       y )Nr-   )r   import_fresh_moduler3   s    r   test_import_fresh_modulez$TestSupport.test_import_fresh_module<   s    ))(3r   c                     | j                  t        j                  | d      | j                         | j	                  t
        j                  t        j                  | d       y )Ntest_get_attributer.   )r&   r   get_attributer9   r0   r1   r2   r3   s    r   r9   zTestSupport.test_get_attribute?   sI    ..t5IJ//	1(++W-B-BD%Pr   zfailing buildbotsc                 h    | j                  t        j                         t        j                         y N)r&   r   get_original_stdoutsysstdoutr3   s    r   test_get_original_stdoutz$TestSupport.test_get_original_stdoutD   s    446

Cr   c                     dd l }| j                  dt        j                         t	        j
                  d       | j                  dt        j                         y )Nr   sched)rB   assertInr>   modulesr   unloadassertNotIn)r'   rB   s     r   test_unloadzTestSupport.test_unloadH   s9    gs{{+W%#++.r   c                    t        t        dd      5 }	 d d d        t        j                  t               | j	                  t
        j                  j                  t                     t        j                  t               y # 1 sw Y   nxY w)Nr)   utf-8encoding)openTESTFNr   unlinkassertFalseospathexists)r'   fs     r   test_unlinkzTestSupport.test_unlinkN   s_    &#0 	A	 /0 		 	s   BBc                    t         j                  dz   }t        j                  j	                  |d      }t        j
                  |       t        j
                  |       t        j                  |       | j                  t        j                  j                  |             t        j                  t        dd      5  t        j                  |       d d d        t        j
                  |       t        j
                  |       t        j                  |t        j                  t        j                  z         t        j                  t        dd      5  t        j                  |       d d d        | j                  t        j                  j                  |             t        j
                  |       t        j
                  |       t        j                  |d       t        j                  t        dd      5  t        j                  |       d d d        | j                  t        j                  j                  |             y # 1 sw Y   xxY w# 1 sw Y   xY w# 1 sw Y   QxY w)Ndsubdirverboser   )r   rM   rP   rQ   joinmkdirrmtreerO   rR   r   	swap_attrchmodstatS_IRUSRS_IXUSR)r'   dirpath
subdirpaths      r   test_rmtreezTestSupport.test_rmtreeU   s   ""S(WW\\'84


!01w	15 	&W%	& 	

$,,t||34w	15 	&W%	&01


!w	15 	&W%	&01	& 	&	& 	&	& 	&s$   <II;I!II!I*c                    t         dz   }t        |dd      5 }t        d|       d d d        t        j                  j                  dt        j                         t        j                          	 t        t               }| j                  t         t        j                         t        j                  t                | j                  t         t        j                         t        j                  d= t!        j"                  |       t!        j$                  d       y # 1 sw Y   xY w# t        j                  d= t!        j"                  |       t!        j$                  d       w xY w)	Nz.pyr)   rI   rJ   zfoo = 1filer   __pycache__)rM   rL   printr>   rQ   insertrP   curdir	importlibinvalidate_caches
__import__rC   rD   r   forgetrF   r   rN   r[   )r'   mod_filenamerS   mods       r   test_forgetzTestSupport.test_forgetm   s    ~,g6 	%!)!$	%299%##%		,V$CMM&#++.  (VS[[1\*]+	% 	% \*]+s   D1A0D) D&)=E&c                 n    t        j                  t        j                  df      }|j	                          y )Nr   )socketcreate_serverr   HOSTcloser'   ss     r   	test_HOSTzTestSupport.test_HOST~   s&      -"4"4a!89		r   c                     t        j                         }t        j                  t         j                  |f      }|j                          y r<   )r   find_unused_portrs   rt   ru   rv   )r'   portrx   s      r   test_find_unused_portz!TestSupport.test_find_unused_port   s4    --/  -"4"4d!;<		r   c                     t        j                          }t        j                  |       |j                          |j	                          y r<   )rs   r   	bind_portlistenrv   rw   s     r   test_bind_portzTestSupport.test_bind_port   s-    MMO"	
		r   c                    t        j                         }t        j                  j	                  |      }	 t        j                  j                  |d      }| j                  t        j                  j                  |             t        j                  |      5 }| j                  ||       | j                  t        j                  j                  |             ddd       | j                  t        j                  j                  |             t        j                  |       y# 1 sw Y   MxY w# t        j                  |       w xY w)z8Test that temp_dir() creates and destroys its directory.tempN)tempfilemkdtemprP   rQ   realpathrY   rO   isdirr   temp_dirr&   
assertTruer[   )r'   
parent_dirrQ   	temp_paths       r   test_temp_dirzTestSupport.test_temp_dir   s    %%'
WW%%j1
	)77<<
F3DRWW]]401##D) 5Y  D1d 345 RWW]]401Z(5 5
 Z(s%   A#D1 AD%6D1 %D.*D1 1Ec                    t        j                         5 }| j                  t        j                  j                  |             ddd       | j                  t        j                  j                               y# 1 sw Y   8xY w)zTest passing no path.N)r   r   r   rP   rQ   r   rO   )r'   r   s     r   test_temp_dir__path_nonez$TestSupport.test_temp_dir__path_none   sY    ! 	6YOOBGGMM)45	6y12	6 	6s   /A;;Bc                    d }t        j                         }t        j                  j	                  |      }	 | j                  t        j                  j                  |             | j                  t        ||       | j                  t        j                  j                  |             t        j                  |       y# t        j                  |       w xY w)z-Test passing a directory that already exists.c                 \    t        j                  |       5 }t        d      # 1 sw Y   y xY wNzshould not get here)r   r   	Exception)rQ   r   s     r   call_temp_dirzMTestSupport.test_temp_dir__existing_dir__quiet_default.<locals>.call_temp_dir   s.    ##D) 7Y 5667 7   "+N)r   r   rP   rQ   r   r   r   r0   FileExistsErrorshutilr[   )r'   r   rQ   s      r   *test_temp_dir__existing_dir__quiet_defaultz6TestSupport.test_temp_dir__existing_dir__quiet_default   s    	7 !ww%	 OOBGGMM$/0o}dCOOBGGMM$/0MM$FMM$s   A3C Cc                    t        j                         }t        j                  j	                  |      }	 t        j                         5 }t        j                  |d      5 }| j                  ||       ddd       |j                  D cg c]  }t        |j                         }}ddd       | j                  t        j                  j                  |             t        j                   |       | j                  t#              d|       |d   }| j                  |j%                  d|d      |       y# 1 sw Y   xY wc c}w # 1 sw Y   xY w# t        j                   |       w xY w)z=Test passing a directory that already exists with quiet=True.TquietN   r   z5tests may fail, unable to create temporary directory : )r   r   rP   rQ   r   r   check_warningsr   r   r&   r   r$   r%   r   r   r   r[   r   
startswith)r'   rQ   recorderr   r)   r   r"   s          r   'test_temp_dir__existing_dir__quiet_truez3TestSupport.test_temp_dir__existing_dir__quiet_true   s,   !ww%	  //1 GX''D9 6Y$$T9564<4E4EFqC		NFFG
 OOBGGMM$/0MM$X84{ +??Chb)J K	6 6FG G MM$sG   E 	E!D:4E
E&E(6E :E	?EEE E.c                 V    t        j                  dt        j                  d             y)z?Test that a forked child process does not remove the directory.-ca  
            import os
            from test import support
            from test.support import os_helper
            with os_helper.temp_cwd() as temp_path:
                pid = os.fork()
                if pid != 0:
                    # parent process

                    # wait for the child to terminate
                    support.wait_process(pid, exitcode=0)

                    # Make sure that temp_path is still present. When the child
                    # process leaves the 'temp_cwd'-context, the __exit__()-
                    # method of the context must not remove the temporary
                    # directory.
                    if not os.path.isdir(temp_path):
                        raise AssertionError("Child removed temp_path.")
        N)r   assert_python_oktextwrapdedentr3   s    r   test_temp_dir__forked_childz'TestSupport.test_temp_dir__forked_child   s$    
 	&&tX__ > . 	r   c                    t        j                         }t        j                         5 }t        j                  |      5 }| j                  ||       | j                  t        j                         |       d d d        d d d        | j                  t        j                         |       y # 1 sw Y   6xY w# 1 sw Y   :xY wr<   )rP   getcwdr   r   
change_cwdr&   )r'   original_cwdr   new_cwds       r   test_change_cwdzTestSupport.test_change_cwd   s    yy{! 	7Y%%i0 7G  )4  g67	7
 	l3	7 7	7 	7s"   B77B+6B7+B4	0B77C c                 :   t        j                         }d }t        j                         5 }t         j                  j                  |d      }| j                  t        ||       ddd       | j                  t        j                         |       y# 1 sw Y   .xY w)z&Test passing a non-existent directory.c                 \    t        j                  |       5 }t        d      # 1 sw Y   y xY wr   )r   r   r   )rQ   r   s     r   call_change_cwdzFTestSupport.test_change_cwd__non_existent_dir.<locals>.call_change_cwd   s.    %%d+ 7w 5667 7r   does_not_existN)	rP   r   r   r   rQ   rY   r0   FileNotFoundErrorr&   )r'   r   r   r   non_existent_dirs        r   !test_change_cwd__non_existent_dirz-TestSupport.test_change_cwd__non_existent_dir   s{    yy{	7 ! 	0Z!ww||J8HI/.0	0
 	l3	0 	0s   8BBc                    t        j                         }t        j                         5 }t         j                  j                  |d      }t        j                         5 }t        j                  |d      5 }| j                  ||       | j                  t        j                         |       ddd       |j                  D cg c]  }t        |j                         }}ddd       ddd       | j                  t              d|       |d   }| j                  |j                  dd      |       y# 1 sw Y   xY wc c}w # 1 sw Y   ixY w# 1 sw Y   mxY w)	z6Test passing a non-existent directory with quiet=True.r   Tr   Nr   r   Btests may fail, unable to change the current working directory to r   )rP   r   r   r   rQ   rY   r   r   r   r&   r   r$   r%   r   r   r   )	r'   r   r   bad_dirr   r   r)   r   r"   s	            r   -test_change_cwd__non_existent_dir__quiet_truez9TestSupport.test_change_cwd__non_existent_dir__quiet_true   s3   yy{! 	GZggll:/?@G //1 GX))'> ;'$$Wl;$$RYY[':; 5=4E4EFqC		NFF	G	G 	X84{ +..5[)< = 	; ; G	G G	G 	GsG   5EE	67D8-E	EE	!E8E=E		E	EEc                    t         dz   }t        j                         5 }t        j                  |d      5  	 ddd       |j
                  D cg c]  }t        |j                         }}ddd       | j                  t              d|       |d   }| j                  |j                  d|d      |       y# 1 sw Y   xY wc c}w # 1 sw Y   axY w)	z0Check the warning message when os.chdir() fails._does_not_existT)rQ   r   Nr   r   r   r   )rM   r   r   r   r   r   r$   r%   r&   r   r   r   )r'   rQ   r   r)   r*   msgs         r   test_change_cwd__chdir_warningz*TestSupport.test_change_cwd__chdir_warning  s    ))++- 	C%%4t< 080A0AB1AIIBHB	C
 	X84qk *--1HB(8 9 	 B	C 	Cs-   CB;CC*C;C	 CCc                    t        j                         }t        j                  t              5  | j                  t         j                  j                  t        j                               t               d d d        | j                  t         j                  j                  t                     | j                  t        j                         |       y # 1 sw Y   `xY w)Nname)
rP   r   r   temp_cwdrM   r&   rQ   basenamerO   rR   )r'   heres     r   test_temp_cwdzTestSupport.test_temp_cwd&  s    yy{V, 	DRWW--biik:FC	D/0d+	D 	Ds   ACCc                    t        j                         }t        j                  d      5 }| j	                  ||       | j                  t         j                  j                  |             | j                  t        j                         |       ddd       | j                  t        j                         |       y# 1 sw Y   .xY w)z Test passing None to temp_cwd().Nr   )	rP   r   r   r   assertNotEqualr   rQ   r   r&   )r'   r   r   s      r   test_temp_cwd__name_nonez$TestSupport.test_temp_cwd__name_none.  s    yy{T* 	3g6OOBGGMM'23RYY['2	3 	l3		3 	3s   A%B==Cc                 V    | j                  t        j                  dddd      d       y )N   r   r   )r   r   r   z{1: 1, 2: 2, 3: 3})r&   r   sortdictr3   s    r   test_sortdictzTestSupport.test_sortdict7  s$    ))Q!q/:<PQr   c                    t        j                         }| j                  t              5 }t	        j
                  |d       d d d        | j                  j                  j                  t        j                         y # 1 sw Y   >xY w)Ns   foo)
r   make_bad_fdr0   OSErrorrP   writer&   	exceptionerrnoEBADF)r'   fdcms      r   test_make_bad_fdzTestSupport.test_make_bad_fd:  sa    ""$w' 	!2HHR 	!++U[[9	! 	!s   A>>Bc                     t        j                  | ddd       | j                  t              5  t        j                  | d       d d d        y # 1 sw Y   y xY w)Nz	def classr      )linenooffsetzx=1)r   check_syntax_errorr0   AssertionErrorr3   s    r   test_check_syntax_errorz#TestSupport.test_check_syntax_error@  sI    ""4QqI~. 	4&&tU3	4 	4 	4s   AAc                     dd l }t        j                  d      5   |j                  d       d d d        y # 1 sw Y   y xY w)Nr   pprint)rk   r   CleanImportr/   )r'   rk   s     r   test_CleanImportzTestSupport.test_CleanImportE  s8    &&x0 	.#I##H-	. 	. 	.s   6?c                 Z   t        j                  dd      5  | j                  dt        j                         | j                  dt        j                         d d d        | j                  dt        j                         | j                  dt        j                         y # 1 sw Y   JxY w)Nr.   bar)r   DirsOnSysPathrC   r>   rQ   rF   r3   s    r   test_DirsOnSysPathzTestSupport.test_DirsOnSysPathJ  su    ((6 	+MM%*MM%*	+ 	))		+ 	+s   AB!!B*c                     t        j                         5 }t        d       d d d        | j                  j	                         d       y # 1 sw Y   *xY w)Nhellohello
)r   captured_stdoutrh   r&   getvalue)r'   r?   s     r   test_captured_stdoutz TestSupport.test_captured_stdoutQ  sC    $$& 	&'N	*I6	 	s   A

Ac                     t        j                         5 }t        dt        j                         d d d        | j                  j                         d       y # 1 sw Y   *xY w)Nr   re   r   )r   captured_stderrrh   r>   stderrr&   r   )r'   r   s     r   test_captured_stderrz TestSupport.test_captured_stderrV  sJ    $$& 	,&'

+	,*I6	, 	,s   AA#c                     t        j                         5 }|j                  d       |j                  d       t	               }d d d        | j                  d       y # 1 sw Y   xY w)Nr   r   r   )r   captured_stdinr   seekinputr&   )r'   stdincaptureds      r   test_captured_stdinzTestSupport.test_captured_stdin[  sU    ##% 	KK	"JJqMwH		
 	7+	 	s   -AA&c                 ,    t        j                          y r<   )r   
gc_collectr3   s    r   test_gc_collectzTestSupport.test_gc_collectc  s    r   c                 T    | j                  t        j                         t               y r<   )assertIsInstancer   python_is_optimizedboolr3   s    r   test_python_is_optimizedz$TestSupport.test_python_is_optimizedf  s    g99;TBr   c                     G d d      } |       }d|_         t        j                  |dd      5 }| j                  |j                   d       | j                  |d       d d d        | j                  |j                   d       t        j                  |dd      5 }| j                  |j                  d       | j                  |       d d d        | j                  t        |d             t        j                  |dd      5  |`d d d        | j                  t        |d             y # 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   =xY w)Nc                       e Zd Zy)'TestSupport.test_swap_attr.<locals>.ObjN)r   
__module____qualname__ r   r   Objr   j  s    r   r  r   xr   y)r  r   r\   r&   r  assertIsNonerO   hasattr)r'   r  objr  r  s        r   test_swap_attrzTestSupport.test_swap_attri  s    	 	esC+ 	#qSUUA&Q"	# 	"sC+ 	!qSUUA&a 	! 	c*+sC+ 		c*+	# 	#	! 	!	 	s#   /D).D5E)D25D>E
c                 &   ddi}t        j                  |dd      5 }| j                  |d   d       | j                  |d       d d d        | j                  |d   d       t        j                  |dd      5 }| j                  |d   d       | j                  |       d d d        | j	                  d|       t        j                  |dd      5  |d= d d d        | j	                  d|       y # 1 sw Y   xY w# 1 sw Y   ]xY w# 1 sw Y   4xY w)Nr  r   r   r  )r   	swap_itemr&   r  rF   )r'   Dr  r  s       r   test_swap_itemzTestSupport.test_swap_itemz  s	   Gq#q) 	#QQsVQ'Q"	# 	3#q#q) 	!QQsVQ'a 	! 	a q#q) 	#	a 	# 	#	! 	!	 	s#   (C/8'C;D/C8;DDc                       e Zd ZdZdZdZdZy)TestSupport.RefClassN)r   r   r   
attribute1
attribute2_hidden_attribute1__magic_1__r  r   r   RefClassr    s    

!r   r  c                       e Zd ZdZdZdZdZy)TestSupport.OtherClassN)r   r   r   r  
attribute3r  __magic_2__r  r   r   
OtherClassr    s    

r   r  c                     t        j                  | j                  | j                        }| j	                  dh|       t        j                  | j                  | j                        }| j	                  ddh|       y )Nr  r  r  )r   detect_api_mismatchr  r  r&   )r'   missing_itemss     r   test_detect_api_mismatchz$TestSupport.test_detect_api_mismatch  se    33DMM48OOE,733DOO48MMC,6Fr   c                 $   g d}t        j                  | j                  | j                  |      }| j	                  t               |       t        j                  | j                  | j                  |      }| j	                  t               |       y )N)r  r  r  not_in_either)ignore)r   r  r  r  r&   set)r'   r  r  s      r    test_detect_api_mismatch__ignorez,TestSupport.test_detect_api_mismatch__ignore  si    M33tv?.33v?.r   c                     dh}dh}t        j                  | t        ||       h d}h d}t        j                  | t        d||       | j	                  t
        t         j                  | t               y )Ntempdirtemplate)extranot_exported>   	makeSuitefindTestCasesTextTestResultinstallHandlergetTestCaseNames>   
load_testsTestProgramBaseTestSuite)zunittest.resultzunittest.casezunittest.suitezunittest.loaderzunittest.mainzunittest.runnerzunittest.signalszunittest.async_case)r   check__all__r   r1   r0   r   )r'   r%  r&  s      r   test_check__all__zTestSupport.test_check__all__  su    "|T%#(*6	8

 FT%I $)*6	8 	.'*>*>hOr   waitpidWNOHANGz need os.waitpid() and os.WNOHANGc                    t        j                          t        j                         }|dk(  rt        j                  d       t         j
                  }	 dt         _        t        j                         }t        j                  t         j                        D ]V  }t        j                  t         j                  d|      5  t        j                          d d d        t         j
                  sV n d|z  }| j                  ||j                                | j                  t         j
                         |t         _        t        j                          y # 1 sw Y   xY w# |t         _        w xY w)Nr   Forig_stderrz2Warning -- reap_children() reaped child process %s)r   reap_childrenrP   fork_exitenvironment_alteredioStringIOsleeping_retrySHORT_TIMEOUTr\   print_warningrC   r   r   )r'   pidwas_alteredr   _r   s         r   test_reap_childrenzTestSupport.test_reap_children  s   
 	 ggi!8HHQK11	6*/G'[[]F++G,A,AB &&w'<'<mVT ,))+,
 .. GLCMM#v01OOG778*5G' 	!, , +6G's,   A*E >EE ,AE E	E E,Nc                    d| d| d}t         j                  g|d|}t        j                  j	                         D ci c]  \  }}|j                  d      s|| }}}t        j                  |t        j                  t        j                  d|      }	||}| j                  |	j                  j                         t        |             | j                  |	j                  d       y c c}}w )	Nzfrom test.support import z; print(repr(z()))r   PYTHONT)r?   r   universal_newlinesenvr   )r>   
executablerP   environitemsr   
subprocessrunPIPEDEVNULLr&   r?   rstriprepr
returncode)
r'   argsfuncexpectedcodecmdkeyvaluerE  procs
             r   check_optionszTestSupport.check_options  s    *4&dV4H~~11d1D1,.JJ,<,<,> 0jc5nnX. Ez 0 0~~c%/__%/%7%715"%	'
 H++-tH~>!,0s   C-cpuc                    g dgdgdgdgdgdgdgdgd	gd
gdgdgddgg dddgddgddgddgddgfD ]/  }| j                  |      5  | j                  |d       d d d        1 | j                  g ddd	g       y # 1 sw Y   RxY w)Nz-B-sz-S-Ez-vz-b-Pz-q-Iz-bbz-vvv-Wignore-Xdev)r_  r`  ra  faulthandler
importtimeshowrefcounttracemallocztracemalloc=3optsargs_from_interpreter_flags)r^  r\  r[  r]  subTestrX  r'   rg  s     r    test_args_from_interpreter_flagsz,TestSupport.test_args_from_interpreter_flags  s    
 FFFFFFFFFGHL5M%>"< >"=!?#3
 	HD6 4( H""4)FGH H7	H< 	38 6	#H Hs   A::B	c                     g dgdgdgfD ]/  }| j                  |      5  | j                  |d       d d d        1 y # 1 sw Y   <xY w)Nz-Oz-OOz-OOOOrf  !optim_args_from_interpreter_flagsri  rk  s     r   &test_optim_args_from_interpreter_flagsz2TestSupport.test_optim_args_from_interpreter_flags  si     FGI
 	ND 4( N""4)LMN N	NN Ns	   =A	zUnstable in EmscriptenzUnavailable on WASIc                 .   t        j                         }t        j                  t        t        j
                        }	 t        j                         }t        j                  |       | j                  ||z
  d       y # t        j                  |       w xY wNr   )r   fd_countrP   rL   __file__O_RDONLYrv   r&   )r'   startr   mores       r   test_fd_countzTestSupport.test_fd_count)  sg     ""$WWXr{{+	%%'DHHRLq) HHRLs   A= =Bc                 
   t        j                         }t        j                  t        j                  d|      5  t        j                  |       d d d        | j                  |j                         |       y # 1 sw Y   *xY w)Nr4  )r9  r:  r   r\   r=  r&   r   )r'   r   rR  r   s       r   check_print_warningzTestSupport.check_print_warning9  s_    w44mVL 	'!!#&	'*H5	' 	's   A99Bc                 L    | j                  dd       | j                  dd       y )Nr   zWarning -- msg
za
bzWarning -- a
Warning -- b
)ry  r3   s    r   test_print_warningzTestSupport.test_print_warning?  s)      !3	5  !?	Ar   c                     t         j                  st        j                  dk(  r | j	                  t         j
                         y | j                  t         j
                         y )Nwin32)r   is_emscriptenr>   platformrO   has_strftime_extensionsr   r3   s    r   test_has_strftime_extensionsz(TestSupport.test_has_strftime_extensionsE  s<      CLLG$;W<<=OOG;;<r   c                 Z    t        j                  d      }t        j                  d|       y )Nap  
            from test import support
            import sys

            def check(cond):
                if not cond:
                    raise AssertionError("test failed")

            # depth 1
            check(support.get_recursion_depth() == 1)

            # depth 2
            def test_func():
                check(support.get_recursion_depth() == 2)
            test_func()

            def test_recursive(depth, limit):
                if depth >= limit:
                    # cannot call get_recursion_depth() at this depth,
                    # it can raise RecursionError
                    return
                get_depth = support.get_recursion_depth()
                print(f"test_recursive: {depth}/{limit}: "
                      f"get_recursion_depth() says {get_depth}")
                check(get_depth == depth)
                test_recursive(depth + 1, limit)

            # depth up to 25
            with support.infinite_recursion(max_depth=25):
                limit = sys.getrecursionlimit()
                print(f"test with sys.getrecursionlimit()={limit}")
                test_recursive(2, limit)

            # depth up to 500
            with support.infinite_recursion(max_depth=500):
                limit = sys.getrecursionlimit()
                print(f"test with sys.getrecursionlimit()={limit}")
                test_recursive(2, limit)
        r   )r   r   r   r   )r'   rS  s     r   test_get_recursion_depthz$TestSupport.test_get_recursion_depthK  s(     &  &N 	&&tT2r   c                    fddD ]Y  }t        j                  |      5  t        j                         } |       	  |dz          | j                  d       d d d        [ t        j                  d      5  	  d       | j                  d       d d d        y # t        $ r Y Nw xY w# 1 sw Y   xY w# t        $ r Y /w xY w# 1 sw Y   y xY w)Nc                 "    | r | dz
         y y rq  r  )depthrecursive_functions    r   r  z6TestSupport.test_recursion.<locals>.recursive_functionx  s    "519- r   )r         r   zRecursionError was not raisedr   )r   infinite_recursionget_recursion_availablefailRecursionError)r'   	max_depth	availabler  s      @r   test_recursionzTestSupport.test_recursionv  s    	. & 	?I++I6 ?#;;=	 #9-
?&y1}5 II=>? ?	?$ ''* 	;;"1% 		9:	; 	; & ? ?( " 	; 	;s^   B-B
B-:C<B9C	B*'B-)B**B--B6	9	CCCCCc                 ,   t         j                  }d}|dz  }|dz  }|dz  }| j                   |d      d       | j                   |d      d|z         | j                   |d      t        d|z               | j                   |d      t        d	|z               | j                   |d
      |       dD ]C  }| j	                  |      5  | j                  t              5   ||       d d d        d d d        E y # 1 sw Y   xY w# 1 sw Y   \xY w)Ni   0kr   3kr   z2.4mg333333@4g   1t) 3z3.5.10k10x)limit)r   _parse_memlimitr&   intrj  r0   
ValueError)r'   parseKiBMiBGiBTiBr  s          r   test_parse_memlimitzTestSupport.test_parse_memlimit  s   ''DjDjDjta(ta#g.vC#I7tc!c'l3tc*0 	!EE* !&&z2 !%L!! !	!! !! !s$   D
"	C>+D
>DD

D	c                 *   d}d}t         j                  }t         j                  }	 t        j                  dkD  rt        j
                  d       | j                  t         j                  |       | j                  t         j                  |       ddz  |z  }t        j
                  | d       | j                  t         j                  t        j                         | j                  t         j                  ||z         nct        j
                  d       | j                  t         j                  t        j                         | j                  t         j                  |       |t         _        |t         _        y # |t         _        |t         _        w xY w)Nl        l        r  r   d   t)r   
max_memusereal_max_memuser>   maxsizeset_memlimitr&   )r'   _4GiBr  old_max_memuseold_real_max_memusebigs         r   test_set_memlimitzTestSupport.test_set_memlimit  s%    ++%55	:{{U"$$T*  !3!3U;  !8!8%@fm$$uAY/  !3!3S[[A  !8!8#)D$$T*  !3!3S[[A  !8!8%@!/G&9G# "0G&9G#s   D=E: :Fc                    t        j                  d      }|st        j                  d      }t        j                  j	                  |      }t        j                  j                  |      s| j                  d|       t        j                  j                  |d      }t        j                  j                  |      s| j                  d|d       ddh}t        j                  |      }| j                  t        j                  ||      |dhz         t        j                  j                  |d	      }| j                  t        j                  |t        j                  |            |dd
hz         t        j                  j                  |d      }| j                  t        j                  |t        j                  |            |       y )N
abs_srcdirsrcdirz,cannot access Python source code directory: Modulesz landmark is missingz.gitrg   buildDocvenvObjects)	sysconfigget_config_varrP   rQ   abspathrR   skipTestrY   listdirr&   r   copy_python_src_ignore)r'   src_dirlandmarkignorednamesrQ   s         r   test_copy_python_src_ignorez'TestSupport.test_copy_python_src_ignore  sr   **<8..x8G''//'* ww~~g&MM %[* + 77<<3ww~~h'MM &\)=? @ =)

7#77G G9,	. ww||GU+77bjj>NO GV#44	6 ww||GY/77bjj>NO 	"r   r<   )Hr   r   r   classmethodr   r   r+   r4   r7   r9   r1   skipr@   rG   rT   rc   rq   r   requires_working_socketry   r}   r   r   r   r   r   requires_forkr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r!  r0  
skipUnlessr  rP   rA  requires_subprocessrX  requires_resourcerl  ro  skipIfr~  is_wasirw  ry  r{  r  r  r  r  r  r  r  r   r   r
   r
      s   < < < <5>
4Q
 X]]&'D (D/!20," %W$$& ' %W$$& '
 %W$$& ')3  * W 444*",4R:4
.
*7
7
,C,"!  G	/P6 XY/JGB	4J;=W   =  D !W  "- #- Wu%"# &"#H
N X__W**,DEX__W__&;<* = F*6A=)3V;@!":.""r   r
   __main__)r   rk   r9  rP   r   rs   r^   rI  r>   r  r   r   r1   r   testr   test.supportr   r   r   r   r   rM   TestCaser
   r   mainr  r   r   <module>r     s{      	 	     
       & " & & (			F"(## F"| zHMMO r   