
    ;e(                     ^   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Zd dlmZmZ 	 d dlmZ d dlmZ  e             dZn# eef$ r dZY nw xY w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 Z!d Z"d Z# G d d          Z$ G d de$ej%        e d          Z& G d de$ej%        e d          Z' ej(        ej)        d           G d dej%                              Z* G d d          Z+ G d de+ej%        e d          Z, G d de+ej%        e d          Z- ej         e.ed          d            G d! d"                      Z/ G d# d$e/ej%        e d          Z0 G d% d&e/ej%        e d          Z1e2d'k    r ej3                     dS dS )(    N)mock
skipUnless)ProcessPoolExecutor)_check_system_limitsTF)support)	os_helper)script_helper)without_source_date_epoch)SourceDateEpochTestMetac                 L    |sd}t           j                            | |          S )N optimization)	importlibutilcache_from_source)scriptopts     +/usr/lib/python3.11/test/test_compileall.pyget_pycr   #   s*     >++F+EEE    c                        fddD             S )Nc                 0    g | ]}t          |          S  )r   ).0r   r   s     r   
<listcomp>zget_pycs.<locals>.<listcomp>+   s#    666SGFC  666r   r         r   r   s   `r   get_pycsr!   *   s    6666I6666r   c                 r    t          j        |           j        }t          j        |          j        }||k    S )z8Returns True if two files have the same inode (hardlink))osstatst_ino)	filename1	filename2inode1inode2s       r   is_hardlinkr*   .   s1    WY&FWY&FVr   c                      e 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d Zd Zd Zd Z eed           ej        d          d                         Zd Z eed           ej        d          d                         Z eed           ej        d           ej        d          d                                     Z eed           ej        dd           ej        d          d                                     Z d  Z!d!d"d#Z"d$ Z# eed          d%             Z$d& Z% eed          d'             Z&d( Z'd) Z(d* Z)d+ Z*d, Z+e,j-        d-             Z.dS ).CompileallTestsBasec                 `   t          j                    | _        t          j                            | j        d          | _        t          j        	                    | j                  | _
        t          | j        dd          5 }|                    d           d d d            n# 1 swxY w Y   t          j                            | j        d          | _        t          j        	                    | j                  | _        t          j        | j        | j                   t          j                            | j        d          | _        t          j        | j                   t          j                            | j        d          | _        t          j        | j        | j                   d S )	N_test.pywutf-8encodingzx = 123
z	_test2.py_subdirz	_test3.py)tempfilemkdtemp	directoryr#   pathjoinsource_pathr   r   r   bc_pathopenwritesource_path2bc_path2shutilcopyfilesubdirectorymkdirsource_path3selffiles     r   setUpzCompileallTestsBase.setUp7   st   !)++7<<
CC ~778HII$"C'::: 	$dJJ{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$GLLEE!889JKK($*;<<<GLLCC
"###GLL):KHH($*;<<<<<s   B%%B),B)c                 8    t          j        | j                   d S Nr?   rmtreer6   rE   s    r   tearDownzCompileallTestsBase.tearDownE       dn%%%%%r   c                     t           j                            | j        d          | _        t          | j        dd          5 }|                    d           d d d            d S # 1 swxY w Y   d S )Nz_test_bad.pyr/   r0   r1   zx (
)r#   r7   r8   r6   bad_source_pathr;   r<   rD   s     r   add_bad_source_filez'CompileallTestsBase.add_bad_source_fileH   s    !w||DNNKK$&g>>> 	 $JJw	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   A%%A),A)c                 6   t          | j        d          5 }|                    d          }d d d            n# 1 swxY w Y   t          t	          j        | j                  j                  }t          j	        dt          j        j        d|dz            }||fS )Nrb   <4sLLr       )r;   r:   readintr#   r$   r9   st_mtimestructpackr   r   MAGIC_NUMBER)rE   rF   datamtimecompares        r   timestamp_metadataz&CompileallTestsBase.timestamp_metadataM   s    $,%% 	!99R==D	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!BGD,--677+gy~'BA#k13 3W}s   8<<c                 j   	 t          j        | j        d           n,# t          t          f$ r |                     d           Y nw xY wt          j        t          j	                              5  | 
                    t          j        | j                             d d d            d S # 1 swxY w Y   d S )N)rV   rV   z0filesystem doesn't support timestamps near 2**32r#   utimer9   OverflowErrorOSErrorskipTest
contextlibredirect_stdoutioStringIO
assertTrue
compileallcompile_filerL   s    r    test_year_2038_mtime_compilationz4CompileallTestsBase.test_year_2038_mtime_compilationU   s   	NHT%'=>>>>w' 	N 	N 	NMMLMMMMM	N'66 	G 	GOOJ3D4DEEFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G!    &AA.-B((B,/B,c                 j   	 t          j        | j        d           n,# t          t          f$ r |                     d           Y nw xY wt          j        t          j	                              5  | 
                    t          j        | j                             d d d            d S # 1 swxY w Y   d S )N)         rq   z+filesystem doesn't support large timestampsrb   rL   s    r   test_larger_than_32_bit_timesz1CompileallTestsBase.test_larger_than_32_bit_times_   s   	IHT%~6666w' 	I 	I 	IMMGHHHHH	I'66 	G 	GOOJ3D4DEEFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gro   c                    t           j                            d          rt          j        d          t          j        | j                    | j        | 	                                  t          | j        d          5 }|                                t          |          d         }ddd           n# 1 swxY w Y   t          | j        d          5 }|                    |           |                    |           ddd           n# 1 swxY w Y    | j        | 	                                  t!          j        | j        dd            | j        | 	                                  dS )	zOCheck that compileall recreates bytecode when the new metadata is
        used.SOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setrS   NwbFTforcequiet)r#   environgetunittestSkipTest
py_compilecompiler9   assertEqualr`   r;   r:   rW   lenr<   assertNotEqualrl   compile_dirr6   rk   )rE   metadatarF   bcs       r   recreation_checkz$CompileallTestsBase.recreation_checki   s    :>>-.. 	@#$>???4+,,,$113344$,%% 	-S]]^^,B	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-$,%% 	JJx   JJrNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	T446677t~U$GGGG00223333s$   >*B44B8;B8+DDDc                 x    |                      t          j        dt          j        j        dd                     d S )NrU   r   r   )r   rZ   r[   r   r   r\   rL   s    r   
test_mtimezCompileallTestsBase.test_mtimey   s@    fk'9>3N*+Q0 0 	1 	1 	1 	1 	1r   c                 0    |                      d           d S )Ns       )r   rL   s    r   test_magic_numberz%CompileallTestsBase.test_magic_number~   s    k*****r   c                    | j         | j        fD ]}	 t          j        |           #  Y xY w|                     t          j        | j        dd                     |                     t          j        	                    | j                   o$t          j        	                    | j                              t          j        | j                    |                     t          j
        | j        dd                     |                     t          j        	                    | j                   o#t          j        	                    | j                             t          j        | j                    t          j        | j                   |                                  |                     t          j        | j        dd                     |                     t          j
        | j        dd                     d S )NFTrv   r   )r:   r>   r#   unlinkrk   rl   rm   r9   r7   isfiler   r6   rQ   assertFalserP   )rE   fns     r   test_compile_filesz&CompileallTestsBase.test_compile_files   s   </ 	 	B	"
/0@6;4I I I 	J 	J 	Jt|44 :GNN4=999	; 	; 	;
	$,
.t~U59; ; ; 	< 	< 	<t|44 6t}55	7 	7 	7
	$,
	$-     """01E7<AG G G 	H 	H 	H/6;1F F F 	G 	G 	G 	G 	Gs   '+c                    |                      t          j                            | j                             t          j                    5 }|                     t          j	        t          j        | j                                       d d d            n# 1 swxY w Y   |                     |                                d           |                     t          j                            | j                             d S )Nz&Compiling ([^WindowsPath|PosixPath].*))r   r#   r7   r   r:   r   captured_stdoutrk   rl   rm   pathlibPathr9   assertRegexgetvalue)rE   stdouts     r   test_compile_file_pathlikez.CompileallTestsBase.test_compile_file_pathlike   s
   55666$&& 	U&OOJ3GLAQ4R4RSSTTT	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U**,UVVVt|4455555s   ?BBBc                    |                      t          j                            | j                             |                     t          j        t          j	        | j
                  t          j	        d          d                     |                     t          j                            | j                             d S )N	ddir_pathr   )ddirrx   r   r#   r7   r   r:   rk   rl   rm   r   r   r9   rL   s    r   test_compile_file_pathlike_ddirz3CompileallTestsBase.test_compile_file_pathlike_ddir   s    55666
/T=M0N0N5<\+5N5N679 9 9 	: 	: 	: 	t|4455555r   c                    |                      t          j                            | j                             |                     t          j        t          j	        | j
                  t          j	        d          d                     |                     t          j                            | j                             d S Nstripdir_pathr   )stripdirrx   r   rL   s    r   #test_compile_file_pathlike_stripdirz7CompileallTestsBase.test_compile_file_pathlike_stripdir   s    55666
/T=M0N0N9@o9V9V679 9 9 	: 	: 	: 	t|4455555r   c                    |                      t          j                            | j                             |                     t          j        t          j	        | j
                  t          j	        d          d                     |                     t          j                            | j                             d S Nprependdir_pathr   )
prependdirrx   r   rL   s    r   %test_compile_file_pathlike_prependdirz9CompileallTestsBase.test_compile_file_pathlike_prependdir   s    55666
/T=M0N0N;B<HY;Z;Z679 9 9 	: 	: 	: 	t|4455555r   c                    t           j        j                            | j        g          5  |                     t          j        d                     d d d            n# 1 swxY w Y   t           j        j                            | j        g          5  |                                  | 	                    t          j        ddd                     d d d            d S # 1 swxY w Y   d S )Nr7   r   rx   FT)skip_curdirrw   rx   )
testtest_importlibr   import_stater6   rk   rl   compile_pathrQ   r   rL   s    r   test_compile_pathz%CompileallTestsBase.test_compile_path   s    %228H2II 	> 	>OOJ3!<<<===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>  %228H2II 	K 	K$$&&&Z4;?qJ J J K K K	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	Ks#   )A!!A%(A%?C##C'*C'c                    t           j                            | j        d          }t           j                            |d          }t          j        |           t          |d          5  	 d d d            n# 1 swxY w Y   t          j        |           |                     t           j        	                    t           j                            |d                               d S )Nr]   rF   ru   __pycache__)
r#   r7   r8   r6   rB   r;   rl   rm   r   exists)rE   data_dir	data_files      r   test_no_pycache_in_non_packagez2CompileallTestsBase.test_no_pycache_in_non_package   s     7<<77GLL622	
)T"" 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 		***X}(M(MNNOOOOOs   *A88A<?A<c                    |                                   t          j        t          j                              5  |                     t          j        | j                             d d d            d S # 1 swxY w Y   d S rI   )	rQ   rg   rh   ri   rj   r   rl   rm   rP   rL   s    r   #test_compile_file_encoding_fallbackz7CompileallTestsBase.test_compile_file_encoding_fallback   s      """'66 	L 	LZ4T5IJJKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls   -A44A8;A8c                 X   d\  }}t          j        | j        d|           t          j                            | j        |          }|                     t          j	        
                    |                     t          j                            | j        |          }|                     t          j	        
                    |                     t          j                            | j        |          }|                     t          j	        
                    |                     d S )NF)r   r   )r   r   Trx   optimizer   )rl   r   r6   r   r   r   r9   rk   r#   r7   r   r=   rC   )rE   r   r   cachedcached2cached3s         r   test_optimizez!CompileallTestsBase.test_optimize   s     29#t~THMMMM11$2B?B 2 D Dv..///.2243D@C 3 E Ew//000.2243D@C 3 E Ew//00000r   c                    |                      t          j                            | j                             t          j                    5 }t          j        t          j
        | j                             d d d            n# 1 swxY w Y   |                                                                d         }|                     |d           |                     t          j                            | j                             d S )Nr   z$Listing ([^WindowsPath|PosixPath].*))r   r#   r7   r   r:   r   r   rl   r   r   r   r6   r   
splitlinesr   rk   )rE   r   lines      r   test_compile_dir_pathlikez-CompileallTestsBase.test_compile_dir_pathlike   s   55666$&& 	A&"7<#?#?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A  ++--a0FGGGt|4455555s   ,BB
Bc                    |                      t          j                            | j                             |                     t          j        t          j	        | j
                  t          j	        d          d                     |                     t          j                            | j                             d S r   r   r#   r7   r   r:   rk   rl   r   r   r   r6   rL   s    r   "test_compile_dir_pathlike_stripdirz6CompileallTestsBase.test_compile_dir_pathlike_stripdir   s    55666
.w|DN/K/K8?_8U8U568 8 8 	9 	9 	9 	t|4455555r   c                    |                      t          j                            | j                             |                     t          j        t          j	        | j
                  t          j	        d          d                     |                     t          j                            | j                             d S r   r   rL   s    r   $test_compile_dir_pathlike_prependdirz8CompileallTestsBase.test_compile_dir_pathlike_prependdir   s    55666
.w|DN/K/K:A,GX:Y:Y568 8 8 	9 	9 	9 	t|4455555r   requires multiprocessingz&concurrent.futures.ProcessPoolExecutorc                 r    t          j        | j        dd           |                     |j                   d S NT   rx   workersrl   r   r6   rk   calledrE   	pool_mocks     r   test_compile_pool_calledz,CompileallTestsBase.test_compile_pool_called   s9     	t~T1EEEE	()))))r   c                     |                      t          d          5  t          j        | j        d           d d d            d S # 1 swxY w Y   d S )Nz%workers must be greater or equal to 0)r   )assertRaisesRegex
ValueErrorrl   r   r6   rL   s    r   !test_compile_workers_non_positivez5CompileallTestsBase.test_compile_workers_non_positive   s    ##J$KM M 	? 	?"4>2>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   AA	A	c                     t          j        | j        dd           |                     |j        d         d         d            d S )NTr   r   r   max_workers)rl   r   r6   r   	call_argsr   s     r   test_compile_workers_cpu_countz2CompileallTestsBase.test_compile_workers_cpu_count  sG     	t~T1EEEE,Q/>EEEEEr   zcompileall.compile_filec                     t          j        | j        d           |                     |j                   |                     |j                   d S )NTr   )rl   r   r6   r   r   rk   )rE   compile_file_mockr   s      r   test_compile_one_workerz+CompileallTestsBase.test_compile_one_worker  sO     	t~T::::)***)011111r   Nnewc                 r    t          j        | j        dd           |                     |j                   d S r   r   )rE   r   s     r   $test_compile_missing_multiprocessingz8CompileallTestsBase.test_compile_missing_multiprocessing  s:     	t~T1EEEE)011111r   c                    d}| j         }t          d|dz             D ]s}t          j                            |d|           }t          j                            |d          }t          j        |           t          j        | j        |           tt          j
                            |          }t          j        | j         d|dz
             |                     t          j                            |                     t          j        | j         d|           |                     t          j                            |                     d S )N   r   dir_z	script.pyT)rx   	maxlevels)r6   ranger#   r7   r8   rB   r?   r@   r9   r   r   r   rl   r   r   r   rk   )rE   depthr7   isourcepyc_filenames         r   test_compile_dir_maxlevelsz.CompileallTestsBase.test_compile_dir_maxlevels  s   ~q%!)$$ 	6 	6A7<<jQjj11DW\\$44FHTNNNOD,f5555 ~77??t~TUQYOOOO55666t~TUKKKK|4455555r   T)parallelc                   ddg}| j         }g }|D ]u}t          j                            ||          }t          j        |           t          j        |dd           |                    t          j        |dd                     vt          j	        | j         d||rdnd	
           | 
                    |           |D ]}| 
                    |                    | j                   |           t          j                            |          }|t          | j         t          j        z             d         }	t          j        |          \  }
}
}t          j                            ||	          }t$          j        j                            |          }|                     |j        |           |                     d| dt          j        |                     dS )z@Recursive compile_dir ddir must contain package paths; bpo39769.r   foo__init__r   modzdef fn(): 1/0
fn()
Tr   r   )rx   r   r   N")r6   r#   r7   r8   rB   r	   make_scriptappendrl   r   rk   
startswithr   r   r   r   sepassert_python_failurer   r   get_code_from_pycr   co_filenameassertInfsdecode)rE   r   r   fullpathr7   modssubdirr   modcodemodpath_errexpected_inmod_code_objs                 r   _test_ddir_onlyz#CompileallTestsBase._test_ddir_only+  s   E?~ 	L 	LF7<<f--DHTNNN%dJ;;;KK1$2IK K L L L Ld%,1	. 	. 	. 	. 	 	@ 	@COOCNN4>::C@@@n66s;;G#dnRV344556G%;GDDIAq#',,tW55K.3EEgNNL\5{CCCMM,k,,,bk#.>.>????	@ 	@r   c                 0    |                      dd          S )=Recursive compile_dir ddir= contains package paths; bpo39769.
<a prefix>Fr   r   r  rL   s    r   test_ddir_only_one_workerz-CompileallTestsBase.test_ddir_only_one_workerD  s    ###FFFr   c                 0    |                      dd          S )r  r  Tr	  r
  rL   s    r   test_ddir_multiple_workersz.CompileallTestsBase.test_ddir_multiple_workersH  s     ###EEEr   c                 0    |                      dd          S )?Recursive compile_dir ddir='' contains package paths; bpo39769.r   Fr	  r
  rL   s    r   test_ddir_empty_only_one_workerz3CompileallTestsBase.test_ddir_empty_only_one_workerM  s    ##e#<<<r   c                 0    |                      dd          S )r  r   Tr	  r
  rL   s    r    test_ddir_empty_multiple_workersz4CompileallTestsBase.test_ddir_empty_multiple_workersQ  s     ##d#;;;r   c                    g d}t          j        j        | j        g|R  }t          j        |           t          j        |dd          }t          j        	                    |          }t          j        j        | j        g|d d         R  }t          j        |d|           t          j        |          \  }}}t          j        j        |dd           }	|                     |	t          |t          j                                         |                     |t          |t          j                                         d S )Nr   buildrealr7   r   1 / 0r   T)rx   r   r1   r#   r7   r8   r6   makedirsr	   r   r   r   r   rl   r   r   r   strsysgetdefaultencodingassertNotIn)
rE   r   r7   r   r   r   rcoutr  r  s
             r   test_strip_onlyz#CompileallTestsBase.test_strip_onlyV  s:   444w|DN6X666
D*4AA^--f557<>"1">>>t4(CCCC$:2>>CglHQRRL1c466777	
 	
 	
 	c466777	
 	
 	
 	
 	
r   c                    g d}t          j        j        | j        g|R  }t          j        |           t          j        |dd          }t          j        	                    |          }d}t          j        |d|           t          j        |          \  }}}t          j        j        || j        g|R  }	|                     |	t          |t          j                                         d S )Nr  r   r  /fooT)rx   r   r1   )r#   r7   r8   r6   r  r	   r   r   r   r   rl   r   r   r   r  r  r  )
rE   r   r7   r   r   r   r  r  r  r  s
             r   test_prepend_onlyz%CompileallTestsBase.test_prepend_onlyi  s    444w|DN6X666
D*4AA^--f55
t4JGGGG$:2>>Cgl:t~IIIIc466777	
 	
 	
 	
 	
r   c                    g d}t          j        j        | j        g|R  }t          j        |           t          j        |dd          }t          j        	                    |          }t          j        j        | j        g|d d         R  }d}t          j        |d||           t          j        |          \  }}}	t          j        j        |g|dd          R  }
|                     |
t          |	t          j                                         |                     |t          |	t          j                                         d S )	Nr  r   r  r   r"  T)rx   r   r   r1   r  rE   r   r7   r   r   r   r   r  r  r  r  s              r   test_strip_and_prependz*CompileallTestsBase.test_strip_and_prependx  sY   444w|DN6X666
D*4AA^--f557<>"1">>>
t4(0Z	I 	I 	I 	I$:2>>Cgl:====c466777	
 	
 	
 	c466777	
 	
 	
 	
 	
r   c                 2   g d}t          j        j        | j        g|R  }t          j        |           t          j        |dd           |                     t                    5  t          j
        |dddd           d d d            d S # 1 swxY w Y   d S )N)r   r  r  r7   r   r   r  Tz/barr"  )rx   r   r   r   )r#   r7   r8   r6   r  r	   r   assertRaisesr   rl   r   )rE   r   r7   s      r   test_strip_prepend_and_ddirz/CompileallTestsBase.test_strip_prepend_and_ddir  s   <<<w|DN6X666
D!$888z** 	G 	G"4t&,2vG G G G	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   %BBBc                    t          j        | j        dd          }g }dD ]6}|                    t          j                            ||                     7ddgddgddgg dg}|D ]}t          j        |d	|
           |D ]e}| 	                    t          j                            ||                              	 t          j        ||                    V# t          $ r Y bw xY wd S )Ntest_optimizationa = 0r   r   r   r   r   r   r   r   r   Tr   )r	   r   r6   r   r   r   r   rl   rm   rk   r#   r7   r   r   	Exception)rE   r   r   	opt_leveltest_combinationsopt_combinations         r   !test_multiple_optimization_levelsz5CompileallTestsBase.test_multiple_optimization_levels  sB   *4>+>+24 4 $ 	P 	PIIIin66vDM 7 O O P P P PVaVaVYYY?0 	 	O#F$-<> > > >,  	r)} = =>>>Ibm,,,,    D		 	s   =C
C%$C%c                    t           j                            | j        ddd          }t           j                            | j        ddd          }t           j                            | j        ddd          }t          j        |           t          j        |           t          j        |           t          j        |dd          }t          j        |dd          }t           j                            |d	          }t           j                            |d
          }t          j        ||           t          j        ||           t          j	        
                    |          }t          j	        
                    |          }	t          j        |d|           |                     t           j                            |                     |                     t           j                            |	                     d S )Nr   dirallowedsymlinks
prohibitedtest_allowedr,  test_prohibitedtest_allowed.pytest_prohibited.pyT)rx   limit_sl_dest)r#   r7   r8   r6   r  r	   r   symlinkr   r   r   rl   r   rk   r   r   
rE   allowed_pathsymlinks_pathprohibited_pathallowed_scriptprohibited_scriptallowed_symlinkprohibited_symlink
allowed_bcprohibited_bcs
             r   test_ignore_symlink_destinationz3CompileallTestsBase.test_ignore_symlink_destination  s    w||DNFE9MMT^VUJOO',,t~vulSS
L!!!
M"""
O$$$ '2<QXYY)5oGXZabb',,}6GHHW\\-9MNN

>?333

$&8999^55oFF
!889KLL}DUUUUz223336677777r   )/__name__
__module____qualname__rG   rM   rQ   r`   rn   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _have_multiprocessingr   patchr   r   r   r   r   r   r  r  r  r  r  r   r#  r&  r)  r2  r   skip_unless_symlinkrH  r   r   r   r,   r,   5   s       = = =& & &     
  G G GG G G4 4 4 1 1 1
+ + +G G G26 6 66 6 66 6 66 6 6K K K
P 
P 
PL L L1 1 16 6 66 6 66 6 6 Z%'ABBTZ899* * :9 CB*? ? ?
 Z%'ABBTZ899F F :9 CBF Z%'ABBTZ899TZ)**2 2 +* :9 CB2
 Z%'ABBTZ8dCCCTZ)**2 2 +* DC CB26 6 6" 15 @ @ @ @ @2G G G Z%'ABBF F CBF= = = Z%'ABB< < CB<
 
 
&
 
 

 
 
*G G G  & "8 8 #"8 8 8r   r,   c                       e Zd ZdS )CompileallTestsWithSourceEpochNrI  rJ  rK  r   r   r   rP  rP             	Dr   rP  )	metaclasssource_date_epochc                       e Zd ZdS )!CompileallTestsWithoutSourceEpochNrQ  r   r   r   rV  rV    rR  r   rV  z tempdir is not encodable on WASIc                   $    e Zd ZdZd Zd Zd ZdS )EncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.c                 >   t          j                    | _        t          j                            | j        d          | _        t          | j        dd          5 }|                    d           |                    d           d d d            d S # 1 swxY w Y   d S )Nr.   r/   r0   r1   z# -*- coding: utf-8 -*-
u   print u"€"
)	r4   r5   r6   r#   r7   r8   r9   r;   r<   rD   s     r   rG   zEncodingTest.setUp  s    !)++7<<
CC$"C'::: 	,dJJ2333JJ*+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   +BBBc                 8    t          j        | j                   d S rI   rJ   rL   s    r   rM   zEncodingTest.tearDown  rN   r   c                     	 t           j        }t          j        t          j                    d          t           _        t          j        | j                   |t           _        d S # |t           _        w xY w)Nasciir1   )r  r   ri   TextIOWrapperBytesIOrl   r   r6   )rE   orig_stdouts     r   
test_errorzEncodingTest.test_error  s\    	%*K)"*,,HHHCJ"4>222$CJJJCJ$$$$s   AA& &A4N)rI  rJ  rK  __doc__rG   rM   r`  r   r   r   rX  rX    sK         , , ,& & &% % % % %r   rX  c                      e Zd ZdZd Zej        d             Zd Zd Z	d Z
d Zd Zd	 Zed
             Zd Zddg fdddgfdddgffD ]\  ZZZeefdZe e            dez   <   d Zd Zed             Zd Zd Zej        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* e+e,d)          d*             Z- e.j/        d+          d,             Z0d- Z1d. Z2ej        d/             Z3d0 Z4d1 Z5d2S )3CommandLineTestsBasezTest compileall's CLI.c                    t          j                    | _        |                     t          j        | j                   t          j                            | j        d          | _	        t          j
        | j	                   t          j                            | j	        d          | _        t          j        | j	        dd          | _        t          j        | j	        dd          | _        d S )Nr   r   r   r   bar)r4   r5   r6   
addCleanupr   rK   r#   r7   r8   pkgdirrB   pkgdir_cachedirr	   r   initfnbarfnrL   s    r   rG   zCommandLineTestsBase.setUp  s    !)++	($.999gll4>599
!w||DKGG#/ZLL".t{E2FF


r   c              #      K   t           j        }t          j                            | j        d          }	 |t           _        | j        |dV  |t           _        dS # |t           _        w xY w)z&Adjust and restore sys.pycache_prefix.__testcache__)
PYTHONPATHPYTHONPYCACHEPREFIXN)r  pycache_prefixr#   r7   r8   r6   )rE   
old_prefix
new_prefixs      r   temporary_pycache_prefixz-CommandLineTestsBase.temporary_pycache_prefix  sy       '
W\\$./BB
	,!+C"n'1    
 ",CC++++s   A A)c                 <    g t          j                    ddd|S )Nz-S-mrl   )r   !optim_args_from_interpreter_flags)rE   argss     r   _get_run_argsz"CommandLineTestsBase._get_run_args  s<    :<< ( 	r   c                     t          j        |                     |          i |ddi\  }}}|                     d|           |S )NPYTHONIOENCODINGr0   r   )r	   assert_python_okrw  r   rE   rv  env_varsr  r  r  s         r   assertRunOKz CommandLineTestsBase.assertRunOK  sb    $5,,T2236>3 3*13 3 3C 	c"""
r   c                 d    t          j        |                     |          i |ddi\  }}}|||fS )Nry  r0   )r	   r   rw  r{  s         r   assertRunNotOKz#CommandLineTestsBase.assertRunNotOK  sS    $:++D1125=2 2)02 2 2C 3|r   c                     t           j                            |          }|                     t          j                            |                     d S rI   )r   r   r   rk   r#   r7   r   rE   r   r7   s      r   assertCompiledz#CommandLineTestsBase.assertCompiled  s=    ~//33t,,-----r   c                     t           j                            |          }|                     t          j                            |                     d S rI   )r   r   r   r   r#   r7   r   r  s      r   assertNotCompiledz&CommandLineTestsBase.assertNotCompiled  s?    ~//33--.....r   c                 B   t          j        | j        dd          }|                                 5 } | j        di | |                     |           |                     | j                   |                     | j                   d d d            d S # 1 swxY w Y   d S )Nbazr   r   )	r	   r   r6   rr  r}  r  r  ri  rj  )rE   bazfnenvs      r   test_no_args_compiles_pathz/CommandLineTestsBase.test_no_args_compiles_path   s    )$.%DD**,, 	/D##s###&&&""4;///""4:...		/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   ABBBc                 h   t          j        | j        dd          }|                                 5 } | j        di | t
          j                            |          }d d d            n# 1 swxY w Y   t          j	        |t          j
                    dz
  fdz             t          j        |          j        } | j        di | t          j        |          j        }|                     ||            | j        di | t          j        |          j        }|                     ||           d S )Nr  r   <   r   -fr   )r  )r	   r   r6   rr  r}  r   r   r   r#   rc   timer$   rY   r   r   )rE   r  r  pycpathr^   mtime2s         r    test_no_args_respects_force_flagz5CommandLineTestsBase.test_no_args_respects_force_flag)  sj   )$.%DD**,, 	>D##s###n66u==G	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	49;;r>+A-...  )3!!*'''%%%%%!!*E6*****s   -A))A-0A-c                     t          j        | j        dd           |                                 5 } | j        di |}d d d            n# 1 swxY w Y   |                     d|            | j        di |}|                     d|           d S )Nr  r   s   Listing -qr   )r  )r	   r   r6   rr  r}  r   r  )rE   r  noisyrx   s       r    test_no_args_respects_quiet_flagz5CommandLineTestsBase.test_no_args_respects_quiet_flag;  s    !$.%<<<**,, 	,$D$++s++E	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,k5)))  ----e,,,,,s   A

AAnormalpycr   z	opt-1.pyc-Odoubleoptimizez	opt-2.pycz-OOc                    t          j        |ddd| j        gz     |                     t          j                            | j                             t          fddD                       }| 	                    t          t	          j
        | j                            |           |                     fdt	          j
        | j                  D                        d S )Nrt  rl   r  c              3   b   K   | ])}|                     t          j        j                  V  *d S rI   )formatr  implementation	cache_tag)r   baseexts     r   	<genexpr>z)CommandLineTestsBase.f.<locals>.<genexpr>O  sS       K K"& #kk#*<*FLL K K K K K Kr   )z__init__.{}.{}z	bar.{}.{}c                 >    g | ]}|                               |S r   )endswith)r   r   r  s     r   r   z*CommandLineTestsBase.f.<locals>.<listcomp>S  s9     3 3 3R!#S!1!13b 3 3 3r   )r	   rz  rg  rk   r#   r7   r   rh  sortedr   listdirr   )rE   r  switchexpecteds    `  r   fzCommandLineTestsBase.fJ  s	   *V|T4;7.8 : : OOBGNN4+?@@AAA K K K K*IK K K K KHVBJt/C$D$DEExPPP 3 3 3 32:dk+B+B 3 3 3 4 4 4 4 4r   test_pep3147_paths_c                 B   |                      dd| j                   |                     t          j                            | j                             t          g d          }|                     t          t          j	        | j                            |           d S )Nz-br  )__init__.pyz__init__.pyczbar.pyzbar.pyc)
r}  rg  r   r#   r7   r   rh  r  r   r  )rE   r  s     r   test_legacy_pathsz&CommandLineTestsBase.test_legacy_pathsW  s     	tT[111(<==>>> & & & ' '
4; 7 788(CCCCCr   c                 `   |                      d| j                   |                     t          j                            | j                             t          j                            | j        d          }|                     t          j                            |                     |                      d| j                   |                     t          j                            | j                             |                     t          j                            |                     d S )Nr  r   )	r}  rg  rk   r#   r7   r   rh  r8   r   )rE   cachecachedirs     r   test_multiple_runsz'CommandLineTestsBase.test_multiple_runsa  s     	t{+++t';<<===T%9=II66777t{+++t';<<===6677777r   c                 :   |                      d| j                   t          j                            | j                  }t          j        |t          j                    dz
  fdz             t          j	        |          j
        }|                      d| j                   t          j	        |          j
        }|                     ||           |                      dd| j                   t          j	        |          j
        }|                     ||           d S )Nr  r  r   r  )r}  rg  r   r   r   rj  r#   rc   r  r$   rY   r   r   )rE   r  r^   r  s       r   
test_forcezCommandLineTestsBase.test_forcen  s    t{+++.224:>>
49;;r>+A-...  )t{+++!!*'''tT[111!!*E6*****r   c                 \   t           j                            | j        d          }t          j        |           t          j        |dd          }t          j        |dd          }|                     dd| j                   |                     |           | 	                    t           j        
                    t           j                            |d                               |                     d| j                   |                     |           |                     |           d S )Nspamr   r   hamr  z-lr   )r#   r7   r8   rg  rB   r	   r   r}  r  r   r   r  )rE   
subpackage	subinitfnhamfns       r   test_recursion_controlz+CommandLineTestsBase.test_recursion_control~  s    W\\$+v66

!-j*bII	)*eR@@tT[111y)))Z(O(OPPQQQt{+++I&&&E"""""r   c                 D   t           j                            | j        d          }t           j                            |d          }t           j                            |d          }|||fD ]}t	          j        |           t           j                            |d          }t	          j        |dd          }t	          j        |dd          }t	          j        |dd          }|                     dd| j                   |                     |           | 	                    t           j        
                    t           j                            |d	                               |                     dd
| j                   |                     |           |                     |           |                     |           |                     dd| j                   |                     |           |                     |           |                     |           |                     |           |                     dd| j                   |                     |           |                     |           |                     |           |                     |           d S )Nr  r  eggsr  r   eggr  z-r 0r   z-r 1z-r 2z-r 5)r#   r7   r8   rg  r	   make_pkgr   r}  r  r   r   r  )	rE   r  subpackage2subpackage3pkgr  r  spamfneggfns	            r   test_recursion_limitz)CommandLineTestsBase.test_recursion_limit  sZ   W\\$+v66
gll:u55gll;77[9 	( 	(C"3''''GLL];;	)*eR@@*;CC)+ubAAvt{333y)))GNN27<<
MBBCC	E 	E 	E 	vt{333I&&&E"""v&&&vt{333I&&&E"""F###u%%%vt{333I&&&E"""F###E"""""r   c           	         t           j                            | j        d          }t	          j        |           t          j        dt           j                            |d                     t          j        dt           j                            |d                     |                     d| j                   |                     t           j                            | j        dddd                     d S )Nr  .evilevil2r  r  )	r#   r7   r8   rg  r	   r  r=  r}  r  )rE   r  s     r   test_symlink_loopz&CommandLineTestsBase.test_symlink_loop  s    
 gll4;//s###

3S&11222

3S'22333t{+++BGLLK-
 
 	 	 	 	 	r   c                     |                      | j                  }|                      d| j                  }|                     d|           |                     d|           d S )Nr  r   )r}  rg  r   r   )rE   r  rx   s      r   
test_quietzCommandLineTestsBase.test_quiet  s`      --  t{33C'''e$$$$$r   c                    t          j        | j        dd           |                     d| j                  \  }}}|                     d| j                  \  }}}|                     d|           |                     d|           d S )Ncrunchyfrog
bad(syntaxr  z-qqr   )r	   r   rg  r  r   r   )rE   r  rx   silents       r   test_silentz CommandLineTestsBase.test_silent  s    !$+}lKKK))$<<5!**5$+>>61C'''f%%%%%r   c                     |                      ddd| j                   |                     | j                   |                     | j                   d S )Nr  z-xz
ba[^\\/]*$)r}  rg  r  rj  r  ri  rL   s    r   test_regexpz CommandLineTestsBase.test_regexp  sP    t]DK@@@tz***DK(((((r   c                    t           j                            | j        d          }t          j        |           t          j        |dd          }t          j        |dd          }|                     d| j        |           | 	                    | j
                   | 	                    | j                   | 	                    |           | 	                    |           d S )Nfoo2r   r   bar2r  )r#   r7   r8   r6   rB   r	   r   r}  rg  r  ri  rj  )rE   pkgdir2init2fnbar2fns       r   test_multiple_dirsz'CommandLineTestsBase.test_multiple_dirs  s    ',,t~v66
+GZDD*7FB??t{G444DK(((DJ'''G$$$F#####r   c                     t          j        | j        dd           |                     ddd| j                  \  }}}|                     |d           d S )Nr  r  r  -ddinsdale   File "dinsdale)r	   r   rg  r  r   rE   r  r  r  s       r   test_d_compile_errorz)CommandLineTestsBase.test_d_compile_error  sW    !$+}lKKK**4z4;OOC/00000r   c                    t          j        | j        dd          }|                     ddd| j                   t          j        | j        dd          }t          j                            |          }t          j        |t          j	        
                    | j        d                     t          j        |           t          j        |d	
          \  }}}|                     |d           d S )Nr  zraise Exceptionr  r  r  bingz
import bazzbaz.pycF)
__isolatedr  )r	   r   rg  r}  r   r   r   r#   renamer7   r8   remover   r   )rE   r  r   r  r  r  r  s          r   test_d_runtime_errorz)CommandLineTestsBase.test_d_runtime_error  s    )$+u>OPPtZ===&t{FLIIn..u55
	#rw||DK;;<<<
	%$:2%PPPC/00000r   c                    |                      dt          j                            | j        d          | j                  \  }}}|                     |d           |                     |d           |                     t          j        	                    t          j                            | j                                       d S )N-i
nosuchfiles   rror.*nosuchfiles	   Traceback)r  r#   r7   r8   r6   rg  r   assertNotRegexr   r   r   r   r   rh  r  s       r   test_include_bad_filez*CommandLineTestsBase.test_include_bad_file  s    **"',,t~|<<dkK KC1222C...	(H(H,0,@)B )B C C 	D 	D 	D 	D 	Dr   c                    t          j        | j        dd          }t          j        | j        dd          }t          j        | j        dd          }t          j        | j        dd          }t          t          j                            | j        d          dd	          5 }|                    t          j                            | j        d
          t          j	        z              |                    t          j                            | j        d          t          j	        z              d d d            n# 1 swxY w Y   | 
                    dt          j                            | j        d          |           |                     |           |                     |           |                     |           |                     |           d S )Nf1r   f2f3f4l1r/   r0   r1   f1.pyf2.pyr  )r	   r   rg  r;   r#   r7   r8   r6   r<   linesepr}  r  r  rE   r  r  r  r  r  s         r   test_include_file_with_argz/CommandLineTestsBase.test_include_file_with_arg  s   &t{D"==&t{D"==&t{D"==&t{D"=="',,t~t44cGLLL 	DPRHHRW\\$+w77
BCCCHHRW\\$+w77
BCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	rw||DNDAA2FFFBBr"""Bs   "BD99D= D=c                    t          j        | j        dd          }t          j        | j        dd          }t          j        | j        dd          }t          j        | j        dd          }t          t          j                            | j        d          dd	          5 }|                    t          j                            | j        d
          t          j	        z              d d d            n# 1 swxY w Y   | 
                    dt          j                            | j        d                     |                     |           |                     |           |                     |           |                     |           d S )Nr  r   r  r  r  r  r/   r0   r1   r  r  )r	   r   rg  r;   r#   r7   r8   r6   r<   r  r}  r  r  r  s         r   test_include_file_no_argz-CommandLineTestsBase.test_include_file_no_arg  s   &t{D"==&t{D"==&t{D"==&t{D"=="',,t~t44cGLLL 	DPRHHRW\\$+w77
BCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Drw||DNDAABBBr"""Br"""r"""""s   "AC44C8;C8c                 n   t          j        | j        dd          }t          j        | j        dd          }t          j        | j        dd          }t          j        | j        dd          }t          j        |                     d          ddgz    }|j                            |t          j        z   	                    d	                     t          j
        |           |                     |           |                     |           |                     |           |                     |           d S )
Nr  r   r  r  r  r   r  -r\  )r	   r   rg  spawn_pythonrw  stdinr<   r#   r  encodekill_pythonr  r  )rE   r  r  r  r  ps         r   test_include_on_stdinz*CommandLineTestsBase.test_include_on_stdin	  s   &t{D"==&t{D"==&t{D"==&t{D"==&););B)?)?4+)MO	r"*},,W55666!!$$$r"""r"""Br"""""r   c                 F   t          j        | j        dd          }|                     d| j        || j                  \  }}}|                     |d           |                     |           |                     | j                   |                     | j                   d S )Nr  zsyntax(errorr  s   rror)	r	   r   rg  r  ri  rj  r   r  r  )rE   bingfnr  r  r  s        r   !test_compiles_as_much_as_possiblez6CommandLineTestsBase.test_compiles_as_much_as_possible  s    *4;OO**<+14:? ?Cg&&&v&&&DK(((DJ'''''r   c                 \    |                      d          }|                     |d           d S )Nbadfilenames   Can't list 'badfilename')r}  r   )rE   r  s     r   !test_invalid_arg_produces_messagez6CommandLineTestsBase.test_invalid_arg_produces_message  s2    }--9:::::r   c                    t          j        | j        dd           t          j                            t          j                            | j        d                    }| 	                    d| j                   t          |d          5 }|                                }d d d            n# 1 swxY w Y   |                     t                              |dd         d          d	           | 	                    d
| j                   t          |d          5 }|                                }d d d            n# 1 swxY w Y   |                     t                              |dd         d          d           d S )Nr  r   r  z --invalidation-mode=checked-hashrS         littler   z"--invalidation-mode=unchecked-hashr   )r	   r   rg  r   r   r   r#   r7   r8   r}  r;   rW   r   rX   
from_bytes)rE   r  fpr]   s       r   test_pyc_invalidation_modez/CommandLineTestsBase.test_pyc_invalidation_mode#  s   !$+tR888n..GLLg..0 0;T[III#t__ 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	QqS	8<<dCCC=t{KKK#t__ 	7799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	QqS	8<<dCCCCCs$   	B**B.1B.D88D<?D<r   c                    t          j        | j        dd          }g }t          d          D ]}t          j                            | j        d                    |                    }t	          j        |           t          j        |dd          }|	                    t          j        |dd                     | 
                    | j        dd           |                     |           |D ]}|                     |           d S )Nr  r   r   zfoo{}r   z-j0)r	   r   r6   r   r#   r7   r8   r  rB   r   r}  r  )rE   r  filessuffixrg  r   rF   s          r   test_workersz!CommandLineTestsBase.test_workers0  s    *4>62FFAhh 	H 	HFW\\$.'..2H2HIIFHV*6:rBBBLL2662FFGGGGs333F### 	& 	&D%%%%	& 	&r   zcompileall.compile_dirc                 0   t          j        dt          j        | j        dg          5  t          j                     |                     |j                   | 	                    |j
        d         d         d           d d d            d S # 1 swxY w Y   d S )Nzsys.argvz-j0r   r   r   r   )r   rM  r  
executabler6   rl   mainrk   r   r   r   )rE   r   s     r   test_workers_available_coresz1CommandLineTestsBase.test_workers_available_cores?  s    Z
 ^T^UCE E E 	F 	FOOOK.///[226yA1EEE		F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   ABBBc                    g d}t          j        j        | j        g|R  }t          j        |           t          j        |dd          }t          j        	                    |          }t          j        j        | j        g|d d         R  }d}| 
                    d|d||           t          j        |          \  }}}	t          j        j        |g|dd          R  }
|                     |
t          |	t          j                                         |                     |t          |	t          j                                         d S )	Nr  r   r  r   r"  z-sz-pr1   )r#   r7   r8   r6   r  r	   r   r   r   r   r}  r   r   r  r  r  r  r%  s              r   r&  z+CommandLineTestsBase.test_strip_and_prependG  sN   444w|DN6X666
D*4AA^--f557<>"1">>>
xz4@@@$:2>>Cgl:====c466777	
 	
 	
 	c466777	
 	
 	
 	
 	
r   c           
      Z   t           j                            | j        d          }t          j        |           t          j        |dd          }g }dD ]6}|                    t          j	        
                    ||                     7ddgddgddgg d	g}|D ]} | j        |gd
 |D             R   |D ]r}|                     t           j                            |t          |                                        	 t          j        ||                    c# t           $ r Y ow xY wd S )Noptimizationsr+  r,  r-  r   r  12)r  r  r  c              3   :   K   | ]}d t          |          z   V  dS )z-oN)r  )r   ns     r   r  zICommandLineTestsBase.test_multiple_optimization_levels.<locals>.<genexpr>j  s,      $L$LqTCFF]$L$L$L$L$L$Lr   )r#   r7   r8   r6   r  r	   r   r   r   r   r   r}  rk   r   rX   r   r.  )rE   r7   r   r   r/  r0  r1  s          r   r2  z6CommandLineTestsBase.test_multiple_optimization_levels[  s~   w||DNO<<
D*4+>+24 4 $ 	P 	PIIIin66vDM 7 O O P P P P!3Z!3Z!3Z,__.  1 	 	ODTM$L$LO$L$L$LMMMM,  	r#i../A B BCCCIbm,,,,    D		 	s   ?D
D'&D'c                    t           j                            | j        ddd          }t           j                            | j        ddd          }t           j                            | j        ddd          }t          j        |           t          j        |           t          j        |           t          j        |dd          }t          j        |dd          }t           j                            |d	          }t           j                            |d
          }t          j        ||           t          j        ||           t          j	        
                    |          }t          j	        
                    |          }	|                     |d|           |                     t           j                            |                     |                     t           j                            |	                     d S )Nr   r4  r5  r6  r7  r8  r,  r9  r:  r;  z-e)r#   r7   r8   r6   r  r	   r   r=  r   r   r   r}  rk   r   r   r>  s
             r   rH  z4CommandLineTestsBase.test_ignore_symlink_destinationr  s    w||DNFE9MMT^VUJOO',,t~vulSS
L!!!
M"""
O$$$ '2<QXYY)5oGXZabb',,}6GHHW\\-9MNN

>?333

$&8999^55oFF
!889KLLl;;;z223336677777r   c                 >    |                      | j        dd           d S )N-o 1--hardlink-dupes)r  r6   rL   s    r   test_hardlink_bad_argsz+CommandLineTestsBase.test_hardlink_bad_args  s%     	DNF4FGGGGGr   c           
         dD ]:}t          j                    5 }|                     |          5  t          j        |dd          }t          |          }g d}|r|                    d            | j        |g|R   |                     t          |d         |d                   |           |                     t          |d         |d	                   |           |                     t          |d         |d	                   |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   <d S )
N)TFdedupr   r,  )r  z-o 0r  z-o 2r  r   r   r   )
r4   TemporaryDirectorysubTestr	   r   r!   r   r}  r   r*   )rE   r!  r7   r   pycsrv  s         r   test_hardlinkz"CommandLineTestsBase.test_hardlink  s    # 	K 	KE,.. K$\\\.. K K*6tXwOOF#F++D999D 8$6777$D$T1D1111$$[a$q'%B%BEJJJ$$[a$q'%B%BEJJJ$$[a$q'%B%BEJJJK K K K K K K K K K K K K K KK K K K K K K K K K K K K K K	K 	Ks5   D2CDD2DD2"D#D22D6	9D6	N)6rI  rJ  rK  ra  rG   rg   contextmanagerrr  rw  r}  r  r  r  r  r
   r  r  namer  r  r  localsr  r  r  r  r  r   rN  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r   rL  r  r   rM  r  r&  r2  rH  r  r%  r   r   r   rc  rc    s@         G G G , , ,  
    . . ./ / // / / + + +"- - - 
5"	[4&)	;0 3 3c6
 F 
	4 
	4 
	4 
	4 23&-..D D D8 8 8 + + +
# 
# 
# #  #  #D "  #"% % %& & &) ) )
	$ 	$ 	$1 1 1
1 1 1D D D     # # ## # #( ( (; ; ;D D D Z%'ABB& & CB& TZ())F F *)F
 
 
(  . "8 8 #"80H H H
K K K K Kr   rc  c                       e Zd ZdS )CommandLineTestsWithSourceEpochNrQ  r   r   r   r*  r*    rR  r   r*  c                       e Zd ZdS )CommandLineTestsNoSourceEpochNrQ  r   r   r   r,  r,    rR  r   r,  linkzrequires os.linkc                       e Zd Zd Zej        d             ZddZddddd	Zd
 Z	ddZ
d Zd ZddZd Zd Zd Zd Zd ZdS )HardlinkDedupTestsBasec                     d | _         d S rI   r   rL   s    r   rG   zHardlinkDedupTestsBase.setUp  s    			r   c              #      K   t          j                    5 }|| _        |V  d | _        d d d            d S # 1 swxY w Y   d S rI   )r4   r"  r7   )rE   r7   s     r   temporary_directoryz*HardlinkDedupTestsBase.temporary_directory  s      (** 	dDIJJJDI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   6::r   c                 8    t          j        | j        ||          S rI   )r	   r   r7   )rE   coder'  s      r   r   z"HardlinkDedupTestsBase.make_script  s    (D$???r   Tr   F)r!  r   rw   c                B    t          j        | j        d|||           d S )NT)rx   r   hardlink_dupesrw   )rl   r   r7   )rE   r!  r   rw   s       r   r   z"HardlinkDedupTestsBase.compile_dir  s9    tyx.35	B 	B 	B 	B 	B 	Br   c                    |                                  5  |                     d           |                     t                    5  t	          j        | j        ddd           d d d            n# 1 swxY w Y   |                     t                    5  t	          j        | j        dddgd           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NpassTr   )rx   r   r6  )r2  r   r(  r   rl   r   r7   rL   s    r   test_bad_argsz$HardlinkDedupTestsBase.test_bad_args  s    %%'' 		< 		<V$$$"":.. < <&tyq6:< < < << < < < < < < < < < < < < < < "":.. < < &ty1v6:< < < << < < < < < < < < < < < < < <		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		<sY   0CA/#C/A3	3C6A3	7C C 4C C	CC	CCCc                     g }|r|                     d           |                     d           |r|                     d           d                    |          S )Nz'module docstring'zx = 1zassert x == 1
)r   r8   )rE   	docstring	assertionliness       r   create_codez"HardlinkDedupTestsBase.create_code  s`     	/LL-...W 	*LL)))yyr   c              #   Z   K   dD ]%}dD ] }|                      ||          }|||fV  !&d S )N)FTr<  r=  )r?  )rE   r<  r=  r4  s       r   
iter_codesz!HardlinkDedupTestsBase.iter_codes  sa      & 	3 	3I* 3 3	'')y'QQY	222223	3 	3r   c           
         |                                  D ])\  }}}|                     ||          5  |                                 5  |                     |          }t	          |          }|                     d           |                     t          |d         |d                              |                     t          |d         |d                              |                     t          |d         |d                              d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   +d S )NrA  Fr   r   r   r   )rB  r#  r2  r   r!   r   r   r*   )rE   r4  r<  r=  r   r$  s         r   test_disabledz$HardlinkDedupTestsBase.test_disabled  s   *.//*;*; 	D 	D&D)Y	YGG D D--// D D!--d33F#F++D$$5$111$$[a$q'%B%BCCC$$[a$q'%B%BCCC$$[a$q'%B%BCCCD D D D D D D D D D D D D D DD D D D D D D D D D D D D D D	D 	Ds6   D3CDD3D  D3#D $D33D7	:D7	c                 P   t          |          }|                     t          |d         |d                   |            |                     t          |d         |d                   | o|            |                     t          |d         |d                   |            d S )Nr   r   r   )r!   r   r*   )rE   r   r<  r=  r$  s        r   check_hardlinksz&HardlinkDedupTestsBase.check_hardlinks  s    T!Wd1g66&	( 	( 	(T!Wd1g66&8y=	: 	: 	:T!Wd1g66&	( 	( 	( 	( 	(r   c                 r   |                                  D ]\  }}}|                     ||          5  |                                 5  |                     |          }|                                  |                     |||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )NrA  )rB  r#  r2  r   r   rF  )rE   r4  r<  r=  r   s        r   r%  z$HardlinkDedupTestsBase.test_hardlink  sb   *.//*;*; 	G 	G&D)Y	YGG G G--// G G!--d33F$$&&&((IFFFG G G G G G G G G G G G G G GG G G G G G G G G G G G G G G	G 	Gs6   B+ABB+BB+BB++B/	2B/	c           	         dD ]}|                      |          5  |                                 5  |                     |                                           }|                     |           t          ||d                   }t          ||d                   }|                     t          ||                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N))r   r   )r   r   )r   r   )optsr   r   r   )r#  r2  r   r?  r   r   rk   r*   )rE   rI  r   pyc1pyc2s        r   test_only_two_levelsz+HardlinkDedupTestsBase.test_only_two_levels  sf   , 		= 		=D4(( = =--// = = "--d.>.>.@.@AAF$$d$333"64733D"64733DOOKd$;$;<<<= = = = = = = = = = = = = = == = = = = = = = = = = = = = =		= 		=s5   C BC	=C 	CC CC  C$	'C$	c                 d   |                                  5  |                     |                                           }|                     g d           t	          |d          }t	          |d          }|                     t          ||                     d d d            d S # 1 swxY w Y   d S )N)r   r   r   r   rJ  r   r   )r2  r   r?  r   r   rk   r*   )rE   r   rK  rL  s       r   test_duplicated_levelsz-HardlinkDedupTestsBase.test_duplicated_levels  s     %%'' 	5 	5 %%d&6&6&8&899Flll33361%%D61%%DOOKd33444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   BB%%B),B)c                 *   |                                  5  |                     d          }|                                  |                     |           t	          |          }t          j        |d                   j        }|                     d          }|                     ddgd           |                     |t          j        |d                   j                   | 	                    t          |d         |d                              |                     |t          j        |d                   j                   |                     t          j        |d         |d         d                     d d d            d S # 1 swxY w Y   d S )	Nr,  r   print(0)r   T)r   rw   r   shallow)r2  r   r   rF  r!   r#   r$   r%   r   rk   r*   r   r   filecmpcmprE   r   r$  inodes       r   test_recompilationz)HardlinkDedupTestsBase.test_recompilation  s    %%'' 	J 	J%%g..F  (((F##DGDG$$+E %%j11F q!fD999 UBGDG$4$4$;<<<OOKQa99:::rwtAw'7'7'>???W[a$q'4HHHIII)	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   E&FFFc                 `   |                                  5  |                     |                                 d          }|                                  |                     |           t          |          }t          j        |d                   j        }|                     dd          }t          j
        dddd| j        	           |                     |t          j        |d                   j                   |                     |t          j        |d
                   j                   |                     t          |d         |d
                              |                     t          j        |d         |d
         d                     d d d            d S # 1 swxY w Y   d S )Nmodule)r'  r   rQ  r  z-czimport moduleF)r  rm  r   r   TrR  )r2  r   r?  r   rF  r!   r#   r$   r%   r	   rz  r7   r   r   r*   rT  rU  rV  s       r   test_importz"HardlinkDedupTestsBase.test_import7  s    %%'' 	J 	J%%d&6&6&8&8x%HHF  (((F##DGDG$$+E %%jx%@@F *dO$)   
 UBGDG$4$4$;<<<UBGDG$4$4$;<<<[a$q'::;;;W[a$q'4HHHIII-	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   FF##F'*F'Nr    )FF)rI  rJ  rK  rG   rg   r&  r2  r   r   r9  r?  rB  rD  rF  r%  rM  rO  rX  r[  r   r   r   r/  r/    s/            @ @ @ @ $()5 B B B B B< < <       3 3 3
D 
D 
D( ( ( (G G G= = =
5 
5 
5J J J2J J J J Jr   r/  c                       e Zd ZdS )!HardlinkDedupTestsWithSourceEpochNrQ  r   r   r   r]  r]  S  rR  r   r]  c                       e Zd ZdS )HardlinkDedupTestsNoSourceEpochNrQ  r   r   r   r_  r_  Z  rR  r   r_  __main__)4rl   rg   rT  importlib.utilr   ri   r#   r   r}   r?   rZ   r  r4   test.test_importlib.utilr   r  r{   r   r   concurrent.futuresr   concurrent.futures.processr   rL  NotImplementedErrorModuleNotFoundErrorr   test.supportr   r	   test.test_py_compiler
   r   r   r!   r*   r,   TestCaserP  rV  skipIfis_wasirX  rc  r*  r,  hasattrr/  r]  r_  rI  r  r   r   r   <module>rm     sU                				 				        



        % % % % % % % %" 766666?????? 01 " " "!"       " " " " " " & & & & & & : : : : : : 8 8 8 8 8 8F F F7 7 7  K8 K8 K8 K8 K8 K8 K8 K8\	 	 	 	 	%8%-%6/F7;	 	 	 		 	 	 	 	(;(0(92I:?	 	 	 	 "DEE% % % % %8$ % % FE%.xK xK xK xK xK xK xK xKv	 	 	 	 	&:'/'81H9=	 	 	 		 	 	 	 	$8%-%6/F7<	 	 	 	 WWR((*<==ZJ ZJ ZJ ZJ ZJ ZJ ZJ >=ZJz	 	 	 	 	(>(0(92I:>	 	 	 		 	 	 	 	&<&.&70G8=	 	 	 	 zHMOOOOO s   A 	A+*A+