
    5\h                     j   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 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          Z0 ej         e1ed           d!           G d" d#                      Z2 G d$ d%e2ej(        e#d          Z3 G d& d'e2ej(        e#d          Z4e5d(k    r ej6                     dS dS ))    N)mock
skipUnless)_cleanup_tests)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     >/opt/python-3.11.14/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 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                   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	directory
addCleanupshutilrmtreer$   pathjoinsource_pathr   r   r   bc_pathopenwritesource_path2bc_path2copyfilesubdirectorymkdirsource_path3selffiles     r   setUpzCompileallTestsBase.setUp8   s   !)++t~666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   (C

CC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.pyr0   r1   r2   zx (
)r$   r;   r<   r7   bad_source_pathr?   r@   rG   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%   r=   st_mtimestructpackr   r   MAGIC_NUMBER)rH   rI   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)rR   rR   z0filesystem doesn't support timestamps near 2**32r$   utimer=   OverflowErrorOSErrorskipTest
contextlibredirect_stdoutioStringIO
assertTrue
compileallcompile_filerH   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)         rn   z+filesystem doesn't support large timestampsr^   rj   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rl   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 setrO   NwbFTforcequiet)r$   environgetunittestSkipTest
py_compilecompiler=   assertEqualr\   r?   r>   rS   lenr@   assertNotEqualrh   compile_dirr7   rg   )rH   metadatarI   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 )NrQ   r   r   )r   rV   rW   r   r   rX   rj   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   rj   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 )NFTrs   r    )r>   rB   r$   unlinkrg   rh   ri   r=   r;   isfiler   r7   rM   assertFalserL   )rH   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$   r;   r   r>   r   captured_stdoutrg   rh   ri   pathlibPathr=   assertRegexgetvalue)rH   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    )ddirru   r   r$   r;   r   r>   rg   rh   ri   r   r   r=   rj   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    )stripdirru   r   rj   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    )
prependdirru   r   rj   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r;   r    ru   FT)skip_curdirrt   ru   )
testtest_importlibr   import_stater7   rg   rh   compile_pathrM   r   rj   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 )NrY   rI   rr   __pycache__)
r$   r;   r<   r7   rE   r?   rh   ri   r   exists)rH   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 N)	rM   rc   rd   re   rf   r   rh   ri   rL   rj   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 )NT)r   r   )r   r   ru   optimizer   )rh   r   r7   r   r   r   r=   rg   r$   r;   r   rA   rF   )rH   r   r   cachedcached2cached3s         r   test_optimizez!CompileallTestsBase.test_optimize   s     #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$   r;   r   r>   r   r   rh   r   r   r   r7   r   
splitlinesr   rg   )rH   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$   r;   r   r>   rg   rh   r   r   r   r7   rj   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   rj   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   ru   workersrh   r   r7   rg   calledrH   	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
ValueErrorrh   r   r7   rj   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)rh   r   r7   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   )rh   r   r7   r   r   rg   )rH   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   )rH   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)ru   	maxlevels)r7   ranger$   r;   r<   rE   r9   rC   r=   r   r   r   rh   r   r   r   rg   )rH   depthr;   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                     v|r|                     t                     t          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   )ru   r   r   N")r7   r$   r;   r<   rE   r
   make_scriptappendr8   multiprocessing_cleanup_testsrh   r   rg   
startswithr   r   r   r}   sepassert_python_failurer   r   get_code_from_pycr|   co_filenameassertInfsdecode)rH   r   r   fullpathr;   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  	;OO9:::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  rj   s    r   test_ddir_only_one_workerz-CompileallTestsBase.test_ddir_only_one_workerH  s    ###FFFr   c                 0    |                      dd          S )r  r  Tr  r	  rj   s    r   test_ddir_multiple_workersz.CompileallTestsBase.test_ddir_multiple_workersL  s     ###EEEr   c                 0    |                      dd          S )?Recursive compile_dir ddir='' contains package paths; bpo39769.r   Fr  r	  rj   s    r   test_ddir_empty_only_one_workerz3CompileallTestsBase.test_ddir_empty_only_one_workerQ  s    ##e#<<<r   c                 0    |                      dd          S )r  r   Tr  r	  rj   s    r    test_ddir_empty_multiple_workersz4CompileallTestsBase.test_ddir_empty_multiple_workersU  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realr;   r   1 / 0r    T)ru   r   r2   r$   r;   r<   r7   makedirsr
   r   r   r   r   rh   r   r   r   strsysgetdefaultencodingassertNotIn)
rH   r   r;   r   r   r   rcoutr  r  s
             r   test_strip_onlyz#CompileallTestsBase.test_strip_onlyZ  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)ru   r   r2   )r$   r;   r<   r7   r  r
   r   r   r   r   rh   r   r   r   r  r  r  )
rH   r   r;   r   r   r   r  r  r  r  s
             r   test_prepend_onlyz%CompileallTestsBase.test_prepend_onlym  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)ru   r   r   r2   r  rH   r   r;   r   r   r   r   r  r  r  r  s              r   test_strip_and_prependz*CompileallTestsBase.test_strip_and_prepend|  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  r;   r   r   r  Tz/barr!  )ru   r   r   r   )r$   r;   r<   r7   r  r
   r   assertRaisesr   rh   r   )rH   r   r;   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   r7   r   r   r   r   rh   ri   rg   r$   r;   r   r   	Exception)rH   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)ru   limit_sl_dest)r$   r;   r<   r7   r  r
   r   symlinkr   r   r   rh   r   rg   r   r   
rH   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__rJ   rM   r\   rk   ro   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(  r1  r	   skip_unless_symlinkrG  r   r   r   r-   r-   6   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 @ @ @ @ @: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rH  rI  rJ  r   r   r   rO  rO             	Dr   rO  )	metaclasssource_date_epochc                       e Zd ZdS )!CompileallTestsWithoutSourceEpochNrP  r   r   r   rU  rU    rQ  r   rU  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/   r0   r1   r2   z# -*- coding: utf-8 -*-
u   print u"€"
)	r5   r6   r7   r$   r;   r<   r=   r?   r@   rG   s     r   rJ   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 r   )r9   r:   r7   rj   s    r   tearDownzEncodingTest.tearDown  s    dn%%%%%r   c                     	 t           j        }t          j        t          j                    d          t           _        t          j        | j                   |t           _        d S # |t           _        w xY w)Nasciir2   )r  r   re   TextIOWrapperBytesIOrh   r   r7   )rH   orig_stdouts     r   
test_errorzEncodingTest.test_error  s\    	%*K)"*,,HHHCJ"4>222$CJJJCJ$$$$s   AA& &A4N)rH  rI  rJ  __doc__rJ   rZ  r`  r   r   r   rW  rW    sK         , , ,& & &% % % % %r   rW  c                   Z   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 ej        d
          d                         Z ej        d
          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/ e0j1        d,          d-             Z2d. Z3d/ Z4ej        d0             Z5d1 Z6d2 Z7d3S )4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)r5   r6   r7   r8   r	   r:   r$   r;   r<   pkgdirrE   pkgdir_cachedirr
   r   initfnbarfnrj   s    r   rJ   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$   r;   r<   r7   )rH   
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-mrh   )r   !optim_args_from_interpreter_flags)rH   argss     r   _get_run_argsz"CommandLineTestsBase._get_run_args
  s<    :<< ( 	r   c                     t          j        |                     |          i |ddi\  }}}|                     d|           |S )NPYTHONIOENCODINGr1   r   )r
   assert_python_okrv  r|   rH   ru  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 )Nrx  r1   )r
   r   rv  rz  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 r   )r   r   r   rg   r$   r;   r   rH   r   r;   s      r   assertCompiledz#CommandLineTestsBase.assertCompiled  s=    ~//33t,,-----r   c                     t           j                            |          }|                     t          j                            |                     d S r   )r   r   r   r   r$   r;   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   r7   rq  r|  r  r  rh  ri  )rH   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cpuc                 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   r7   rq  r|  r   r   r   r$   r_   timer%   rU   r|   r~   )rH   r  r  pycpathrZ   mtime2s         r    test_no_args_respects_force_flagz5CommandLineTestsBase.test_no_args_respects_force_flag-  sl    )$.%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   r7   rq  r|  r   r  )rH   r  noisyru   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 )Nrs  rh   r  c              3   b   K   | ])}|                     t          j        j                  V  *d S r   )formatr  implementation	cache_tag)r   baseexts     r   	<genexpr>z)CommandLineTestsBase.f.<locals>.<genexpr>U  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>Y  s9     3 3 3R!#S!1!13b 3 3 3r   )r
   ry  rf  rg   r$   r;   r   rg  sortedr|   listdirr   )rH   r  switchexpecteds    `  r   fzCommandLineTestsBase.fP  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|  rf  r   r$   r;   r   rg  r  r|   r  )rH   r  s     r   test_legacy_pathsz&CommandLineTestsBase.test_legacy_paths]  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|  rf  rg   r$   r;   r   rg  r<   r   )rH   cachecachedirs     r   test_multiple_runsz'CommandLineTestsBase.test_multiple_runsg  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|  rf  r   r   r   ri  r$   r_   r  r%   rU   r|   r~   )rH   r  rZ   r  s       r   
test_forcezCommandLineTestsBase.test_forcet  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$   r;   r<   rf  rE   r
   r   r|  r  r   r   r  )rH   
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$   r;   r<   rf  r
   make_pkgr   r|  r  r   r   r  )	rH   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$   r;   r<   rf  r
   r  r<  r|  r  )rH   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|  rf  r~   r|   )rH   r  ru   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   rf  r~  r~   r|   )rH   r   ru   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|  rf  r  ri  r  rh  rj   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$   r;   r<   r7   rE   r
   r   r|  rf  r  rh  ri  )rH   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   rf  r~  r   rH   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   rf  r|  r   r   r   r$   renamer;   r<   remover   r   )rH   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$   r;   r<   r7   rf  r   assertNotRegexr   r   r   r   r   rg  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l1r0   r1   r2   f1.pyf2.pyr  )r
   r   rf  r?   r$   r;   r<   r7   r@   linesepr|  r  r  rH   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  r0   r1   r2   r  r  )r
   r   rf  r?   r$   r;   r<   r7   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   rf  spawn_pythonrv  stdinr@   r$   r  encodekill_pythonr  r  )rH   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   rf  r~  rh  ri  r   r  r  )rH   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   )rH   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-hashrO         littler   z"--invalidation-mode=unchecked-hashr   )r
   r   rf  r   r   r   r$   r;   r<   r|  r?   rS   r|   rT   
from_bytes)rH   r  fprY   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   r7   r   r$   r;   r<   r  rE   r   r|  r  )rH   r  filessuffixrf  r   rI   s          r   test_workersz!CommandLineTestsBase.test_workers6  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   rL  r  
executabler7   rh   mainrg   r   r|   r   )rH   r   s     r   test_workers_available_coresz1CommandLineTestsBase.test_workers_available_coresE  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-pr2   )r$   r;   r<   r7   r  r
   r   r   r   r   r|  r   r   r  r  r  r  r$  s              r   r%  z+CommandLineTestsBase.test_strip_and_prependM  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>p  s,      $L$LqTCFF]$L$L$L$L$L$Lr   )r$   r;   r<   r7   r  r
   r   r   r   r   r   r|  rg   r   rT   r   r-  )rH   r;   r   r   r.  r/  r0  s          r   r1  z6CommandLineTestsBase.test_multiple_optimization_levelsa  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   r3  r4  r5  r6  r7  r+  r8  r9  r:  z-e)r$   r;   r<   r7   r  r
   r   r<  r   r   r   r|  rg   r   r   r=  s
             r   rG  z4CommandLineTestsBase.test_ignore_symlink_destinationx  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~  r7   rj   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    )
r5   TemporaryDirectorysubTestr
   r   r"   r   r|  r|   r+   )rH   r!  r;   r   pycsru  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)8rH  rI  rJ  ra  rJ   rc   contextmanagerrq  rv  r|  r~  r  r  r  r   r   requires_resourcer  r  namer  r  r  localsr  r  r  r  r  r	   rM  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r   rK  r  r   rL  r  r%  r1  rG  r  r%  r   r   r   rc  rc    sr         G G G , , ,  
    . . ./ / // / / Wu%%+ + &% +" Wu%%- - &%- 
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 )CommandLineTestsWithSourceEpochNrP  r   r   r   r+  r+    rQ  r   r+  c                       e Zd ZdS )CommandLineTestsNoSourceEpochNrP  r   r   r   r-  r-    rQ  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 r   r   rj   s    r   rJ   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 r   )r5   r"  r;   )rH   r;   s     r   temporary_directoryz*HardlinkDedupTestsBase.temporary_directory  s      (** 	dDIJJJDI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   6::r   c                 8    t          j        | j        ||          S r   )r
   r   r;   )rH   coder(  s      r   r   z"HardlinkDedupTestsBase.make_script  s    (D$???r   Tr   F)r!  r   rt   c                B    t          j        | j        d|||           d S )NT)ru   r   hardlink_dupesrt   )rh   r   r;   )rH   r!  r   rt   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   )ru   r   r7  )r3  r   r'  r   rh   r   r;   rj   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   r<   )rH   	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@  )rH   r=  r>  r5  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 )NrB  Fr   r   r   r    )rC  r#  r3  r   r"   r   r   r+   )rH   r5  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+   )rH   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 )NrB  )rC  r#  r3  r   r   rG  )rH   r5  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#  r3  r   r@  r   r   rg   r+   )rH   rJ  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   rK  r   r   )r3  r   r@  r   r   rg   r+   )rH   r   rL  rM  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   rt   r   shallow)r3  r   r   rG  r"   r$   r%   r&   r|   rg   r+   r~   r   filecmpcmprH   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   rR  r  z-czimport moduleF)r  rl  r    r   TrS  )r3  r   r@  r   rG  r"   r$   r%   r&   r
   ry  r;   r|   r   r+   rU  rV  rW  s       r   test_importz"HardlinkDedupTestsBase.test_import=  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)rH  rI  rJ  rJ   rc   r&  r3  r   r   r:  r@  rC  rE  rG  r%  rN  rP  rY  r\  r   r   r   r0  r0    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   r0  c                       e Zd ZdS )!HardlinkDedupTestsWithSourceEpochNrP  r   r   r   r^  r^  Y  rQ  r   r^  c                       e Zd ZdS )HardlinkDedupTestsNoSourceEpochNrP  r   r   r   r`  r`  `  rQ  r   r`  __main__)7rh   rc   rU  importlib.utilr   re   r$   r   rz   r9   rV   r  r5   test.test_importlib.utilr   r  rx   r   r   multiprocessing.utilr   r   concurrent.futuresr   concurrent.futures.processr   rK  NotImplementedErrorModuleNotFoundErrorr   test.supportr	   r
   test.test_py_compiler   r   r   r"   r+   r-   TestCaserO  rU  skipIfis_wasirW  rc  r+  r-  hasattrr0  r^  r`  rH  r  r   r   r   <module>ro     sh                				 				        



        % % % % % % % %	" UTTTTT666666?????? 01 " " "!"       " " " " " " & & & & & & : : : : : : 8 8 8 8 8 8F F F7 7 7  N8 N8 N8 N8 N8 N8 N8 N8b	 	 	 	 	%8%-%6/F7;	 	 	 		 	 	 	 	(;(0(92I:?	 	 	 	 "DEE% % % % %8$ % % FE%.zK zK zK zK zK zK zK zKz	 	 	 	 	&:'/'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% %	A10A1