
    <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mZ d dlmZmZ d Zd Z G d d e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 G d de
j                  Zedk    r e
j                     dS dS )    N)support)	os_helperscript_helperc                 F     t          j                    fd            }|S )z+Runs function with SOURCE_DATE_EPOCH unset.c                      t          j                    5 }|                    d            | i |cd d d            S # 1 swxY w Y   d S )NSOURCE_DATE_EPOCH)r   EnvironmentVarGuardunsetargskwargsenvfxns      +/usr/lib/python3.11/test/test_py_compile.pywrapperz*without_source_date_epoch.<locals>.wrapper   s    *,, 	(II)***3'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   ?AA	functoolswrapsr   r   s   ` r   without_source_date_epochr      8    _S( ( ( ( ( N    c                 F     t          j                    fd            }|S )z)Runs function with SOURCE_DATE_EPOCH set.c                  x    t          j                    5 }d|d<    | i |cd d d            S # 1 swxY w Y   d S )N	123456789r   )r   r	   r   s      r   r   z'with_source_date_epoch.<locals>.wrapper   s    *,, 	('2C#$3'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   /33r   r   s   ` r   with_source_date_epochr      r   r   c                        e Zd Z fdZ xZS )SourceDateEpochTestMetac                "   t                                          | |||          }t          |          D ]Y}|                    d          rBt	          ||          }|rt          |          }nt          |          }t          |||           Z|S )Ntest_)super__new__dir
startswithgetattrr   r   setattr)
mclsnamebasesdctsource_date_epochclsattrmethr   	__class__s
            r   r"   zSourceDateEpochTestMeta.__new__&   s    ggoodD%55HH 	, 	,Dw'' ,sD))$ >4T::GG7==GT7+++
r   )__name__
__module____qualname__r"   __classcell__)r/   s   @r   r   r   %   s8                r   r   c                      e Zd Zd Zd Zd Zd Z ej        e	j
                            e	j                   pe	j
                            e	j                  d          d             Zd Zd Zd	 Zej         ej        e	j        d
k    d          ej        d                                     Zd Zd Z ej        ej        j        dk    d          d             Zd Zd Zd ZdS )PyCompileTestsBasec                    t          j        t          j                              | _        t          j                            | j        d          | _        | j        dz   | _        t          j
                            | j                  | _        t          j                            t          j                              d         | _        t          j                            | j                  d         }|rt          j        |           t!          | j        d          5 }|                    d           d d d            d S # 1 swxY w Y   d S )N)r#   _test.pycr   wx = 123
)tempfilemkdtemposgetcwd	directorypathjoinsource_pathpyc_path	importlibutilcache_from_source
cache_path
splitdrive	cwd_drivechdiropenwrite)selfdrivefiles      r   setUpzPyCompileTestsBase.setUp7   s<   !)bikk:::7<<
CC(3.#.::4;KLL++BIKK88;
 ""4#344Q7 	HUOOO$"C(( 	$DJJ{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   EEEc                 |    t          j        | j                   | j        rt	          j        | j                   d S d S N)shutilrmtreer?   rI   r=   rJ   rM   s    r   tearDownzPyCompileTestsBase.tearDownG   s@    dn%%%> 	%HT^$$$$$	% 	%r   c                     t          j        | j        | j                   |                     t
          j                            | j                             |                     t
          j                            | j	                             d S rR   )

py_compilecompilerB   rC   
assertTruer=   r@   existsassertFalserG   rU   s    r   test_absolute_pathz%PyCompileTestsBase.test_absolute_pathL   sf    4+T];;;t}556668899999r   c                 J   	 t          j        | j        dz   | j                   |                     t                    5  t          j        | j        | j                   d d d            d S # 1 swxY w Y   d S # t          t          f$ r | 
                    d           Y d S w xY w)Nz.actualz.need to be able to create a symlink for a file)r=   symlinkrC   assertRaisesFileExistsErrorrX   rY   rB   NotImplementedErrorOSErrorskipTestrU   s    r   test_do_not_overwrite_symlinksz1PyCompileTestsBase.test_do_not_overwrite_symlinksQ   s   	DJt}y0$-@@@
 ""?33 D D"4#3T]CCCD D D D D D D D D D D D D D D D D D	 $W- 	L 	L 	LMMJKKKKKK	Ls"   "A8  A++A/2A/8&B"!B"z7requires os.devnull and for it to be a non-regular filec                     |                      t                    5  t          j        | j        t
          j                   d d d            d S # 1 swxY w Y   d S rR   )r`   ra   rX   rY   rB   r=   devnullrU   s    r   &test_do_not_overwrite_nonregular_filesz9PyCompileTestsBase.test_do_not_overwrite_nonregular_files]   s    
 // 	= 	=t/<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   %AAAc                     t          j        | j                   |                     t          j                            | j                             d S rR   )rX   rY   rB   rZ   r=   r@   r[   rG   rU   s    r   test_cache_pathz"PyCompileTestsBase.test_cache_pathe   s>    4+,,,t7788888r   c                    t          j        | j                  5  t          j        t
          j                            | j                  t
          j                            | j	                             d d d            n# 1 swxY w Y   | 
                    t
          j                            | j	                             |                     t
          j                            | j                             d S rR   )r   
change_cwdr?   rX   rY   r=   r@   basenamerB   rC   rZ   r[   r\   rG   rU   s    r   test_cwdzPyCompileTestsBase.test_cwdi   s   !$.11 	@ 	@rw//0@AA!w//>>@ @ @	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	t}556668899999s   AB  BBc                    t          j        t          j                            | j                  t          j                            | j                             |                     t          j                            | j                             | 	                    t          j                            | j
                             d S rR   )rX   rY   r=   r@   relpathrB   rC   rZ   r[   r\   rG   rU   s    r   test_relative_pathz%PyCompileTestsBase.test_relative_pathp   s    27??4+;<<7??4=99	; 	; 	;t}556668899999r   ntz/cannot control directory permissions on Windowsc                    t          j        | j                  }t          j        | j        t          j                   	 |                     t                    5  t          j        | j	        | j
                   d d d            n# 1 swxY w Y   t          j        | j        |j                   d S # t          j        | j        |j                   w xY wrR   )r=   statr?   chmodS_IREADr`   IOErrorrX   rY   rB   rC   st_mode)rM   modes     r   test_exceptions_propagatez,PyCompileTestsBase.test_exceptions_propagatev   s     wt~&&
...	3""7++ D D"4#3T]CCCD D D D D D D D D D D D D D D HT^T\22222BHT^T\2222s/   B1  B9B1 B		B1 B	B1 1!Cc                    t           j                            t           j                            t                    d          }t          j                    5  |                     t          j	        |d                     d d d            n# 1 swxY w Y   | 
                    t           j                            t          j                            |                               d S )Nbad_coding2.pyF)doraise)r=   r@   rA   dirname__file__r   captured_stderrassertIsNonerX   rY   r\   r[   rD   rE   rF   )rM   
bad_codings     r   test_bad_codingz"PyCompileTestsBase.test_bad_coding   s   W\\"'//(";";=MNN
$&& 	M 	Mj0UKKKLLL	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	MN,,Z88: : 	; 	; 	; 	; 	;s   *BBBc                 T   t          j        | j        | j                   |                     t
          j                            | j                             |                     t
          j                            | j	                             t          | j        d          5 }t          j                            |                                di           }d d d            n# 1 swxY w Y   t
          j                            d          rd}nd}|                     ||           d S )Nrbtestr      r   )rX   rY   rB   rC   rZ   r=   r@   r[   r\   rG   rK   rD   _bootstrap_external_classify_pycreadenvirongetassertEqual)rM   fpflagsexpected_flagss       r   test_source_date_epochz)PyCompileTestsBase.test_source_date_epoch   s,   4+T];;;t}5566688999$-&& 	'"1??		62' 'E	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' :>>-.. 	"!NN!N/////s   #4C##C'*C'r   ztest does not work with -Oc           	      l   t           j                            | j        d          }t          j                            |          }|dz   }t           j                            |          \  }}t           j                            |          }| 	                    t           j                            ||          t           j                            dd
                    t          j        j                                       t          |d          5 }|                    d           d d d            n# 1 swxY w Y   t!          j        |           |                     t           j                            |                     |                     t           j                            |                     d S )Nz
foo.bar.pyr8   __pycache__zfoo.bar.{}.pycr9   r:   )r=   r@   rA   r?   rD   rE   rF   splitrm   r   formatsysimplementation	cache_tagrK   rL   rX   rY   rZ   r[   r\   )rM   
weird_pathrG   rC   headtailpenultimate_tailrO   s           r   test_double_dot_no_clobberz-PyCompileTestsBase.test_double_dot_no_clobber   s    W\\$.,??
^55jAA
#W]]:..
d7++D11GLL)400GLL ''(:(DEEG G	H 	H 	H
 *c"" 	$dJJ{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$:&&&z223331122222s   D11D58D5c                 d    |                      dt          j        | j        d                     d S )Nzopt-2   )optimize)assertInrX   rY   rB   rU   s    r   test_optimization_pathz)PyCompileTestsBase.test_optimization_path   s/    gz1$2BQOOOPPPPPr   c                    t          j        | j        t           j        j                   t          | j        d          5 }t          j        	                    |
                                di           }d d d            n# 1 swxY w Y   |                     |d           t          j        | j        t           j        j                   t          | j        d          5 }t          j        	                    |
                                di           }d d d            n# 1 swxY w Y   |                     |d           d S )N)invalidation_moder   r   r      )rX   rY   rB   PycInvalidationModeCHECKED_HASHrK   rG   rD   r   r   r   r   UNCHECKED_HASH)rM   r   r   s      r   test_invalidation_modez)PyCompileTestsBase.test_invalidation_mode   s   (<I	
 	
 	
 	
 $/4(( 	'B1??		62' 'E	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	%%%(<K	
 	
 	
 	
 $/4(( 	'B1??		62' 'E	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	$$$$$s$    4B  BB 4D  D$'D$c                 v   t           j                            t           j                            t                    d          }t          j                    5 }|                     t          j	        |dd                     |                     t          j	        |dd                     | 
                    |                                d           |                     t          j                  5  t          j	        |d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 )Nr|   Fr   )r}   quietT r   )r=   r@   rA   r~   r   r   r   r   rX   rY   r   getvaluer`   PyCompileError)rM   r   stderrs      r   
test_quietzPyCompileTestsBase.test_quiet   s   W\\"'//(";";=MNN
$&& 	F&j0URSTTTUUUj0TQRSSSTTTV__..333"":#<== F F":t1EEEEF F F F F F F F F F F F F F F		F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs7   BD.2D
D.D	D.D	D..D25D2N) r0   r1   r2   rP   rV   r]   re   unittestskipIfr=   r@   r[   rg   isfilerh   rj   rn   rq   r   skip_if_dac_overrider(   skip_unless_working_chmodrz   r   r   r   r   r   r   r   r   r    r   r   r5   r5   5   s       $ $ $ % % %
: : :

D 
D 
D X_
333Qrw~~bj7Q7QNP P= =P P=9 9 9: : :: : : #X_RW_FH H(
3 
3 )(H H $#
3; ; ;0 0 0 X_SY'!+-IJJ3 3 KJ3&Q Q Q% % %$F F F F Fr   r5   c                       e Zd ZdS )PyCompileTestsWithSourceEpochNr0   r1   r2   r   r   r   r   r               	Dr   r   T)	metaclassr+   c                       e Zd ZdS ) PyCompileTestsWithoutSourceEpochNr   r   r   r   r   r      r   r   r   Fc                   t    e Z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S )PyCompileCLITestCasec                 b   t          j                    | _        t          j                            | j        d          | _        t          j        	                    | j                  | _
        t          | j        d          5 }|                    d           d d d            d S # 1 swxY w Y   d S )Nr7   r9   r:   )r;   r<   r?   r=   r@   rA   rB   rD   rE   rF   rG   rK   rL   )rM   rO   s     r   rP   zPyCompileCLITestCase.setUp   s    !)++7<<
CC#.::4;KLL$"C(( 	$DJJ{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   B$$B(+B(c                 8    t          j        | j                   d S rR   )r   rT   r?   rU   s    r   rV   zPyCompileCLITestCase.tearDown   s    (((((r   c                     |rM|d         dk    rAd|v r=t          j        t          j        dddg|d                                         d          S t          j        ddg|R i |S )Nr   -input-mrX   T)r   capture_output)
subprocessrunr   
executableencoder   assert_python_ok)rM   r   r   s      r   pycompilecmdz!PyCompileCLITestCase.pycompilecmd   s    
  	7DGsNNw&'8'8>3>4s"K(.w(>(>(@(@157 7 7 7 -dLR4RRR6RRRr   c                 (    t          j        ddg|R  S )Nr   rX   )r   assert_python_failure)rM   r   s     r   pycompilecmd_failurez)PyCompileCLITestCase.pycompilecmd_failure   s    24MMMMMr   c                 N   |                      d| j                  }|                     |j        d           |                     |j        d           |                     |j        d           |                     t          j        	                    | j
                             d S )Nr   )r   r   r   )r   rB   r   
returncodestdoutr   rZ   r=   r@   r[   rG   )rM   results     r   
test_stdinzPyCompileCLITestCase.test_stdin   s    ""3d.>"??*A...,,,,,,t7788888r   c                 @   |                      | j        | j                  \  }}}|                     |d           |                     |d           |                     |d           |                     t          j                            | j                             d S )Nr   r   )r   rB   r   rZ   r=   r@   r[   rG   )rM   rcr   r   s       r   test_with_filesz$PyCompileCLITestCase.test_with_files   s    !..t/?AQRRFFQ%%%%%%t7788888r   c                 @   t           j                            t           j                            t                    d          }|                     |          \  }}}|                     |d           |                     |d           |                     d|           d S )Nbadsyntax_3131.pyr   r   s   SyntaxError)r=   r@   rA   r~   r   r   r   r   rM   
bad_syntaxr   r   r   s        r   test_bad_syntaxz$PyCompileCLITestCase.test_bad_syntax  s    W\\"'//(";";=PQQ
!66zBBFFQ%%%nf-----r   c                 B   t           j                            t           j                            t                    d          }|                     d|          \  }}}|                     |d           |                     |d           |                     |d           d S )Nr   -qr   r   )r=   r@   rA   r~   r   r   r   r   s        r   test_bad_syntax_with_quietz/PyCompileCLITestCase.test_bad_syntax_with_quiet  s    W\\"'//(";";=PQQ
!66tZHHFFQ%%%%%%%%r   c                 p   t           j                            t           j                            t                    d          }|                     | j        |          \  }}}|                     |d           |                     |d           |                     d|	                                           d S )Nshould_not_exists.pyr   r   s   no such file or directory)
r=   r@   rA   r~   r   r   rB   r   r   lowerrM   should_not_existsr   r   r   s        r   test_file_not_existsz)PyCompileCLITestCase.test_file_not_exists  s    GLL)B)BDZ[[!66t7GIZ[[FFQ%%%2FLLNNCCCCCr   c                 N   t           j                            t           j                            t                    d          }|                     d| j        |          \  }}}|                     |d           |                     |d           |                     |d           d S )Nr   r   r   r   )r=   r@   rA   r~   r   r   rB   r   r   s        r   test_file_not_exists_with_quietz4PyCompileCLITestCase.test_file_not_exists_with_quiet  s    GLL)B)BDZ[[!66tT=MO`aaFFQ%%%%%%%%r   N)r0   r1   r2   rP   rV   r   requires_subprocessr   r   r   r   r   r   r   r   r   r   r   r   r      s        $ $ $) ) ) !W ""S S #"SN N N9 9 99 9 9. . .& & &D D D& & & & &r   r   __main__)r   importlib.utilrD   r=   rX   rS   rt   r   r   r;   r   r   r   test.supportr   r   r   r   typeTestCaser   r5   r   r   r   r0   mainr   r   r   <module>r      s           				           



         1 1 1 1 1 1 1 1        dd8#455    WF WF WF WF WF WF WF WFt	 	 	 	 	$6$,$5.E6:	 	 	 		 	 	 	 	'9'/'81H9>	 	 	 	B& B& B& B& B&8, B& B& B&J zHMOOOOO r   