
    <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                 H     	 t          j                    fd            }|S )Nc                      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      s;    5_S( ( ( ( ( N    c                 H     	 t          j                    fd            }|S )Nc                  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      s;    3_S( ( ( ( ( Nr   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>   rH   r<   rI   rL   s    r   tearDownzPyCompileTestsBase.tearDownG   s@    dn%%%> 	%HT^$$$$$	% 	%r   c                     t          j        | j        | j                   |                     t
          j                            | j                             |                     t
          j                            | j	                             d S rQ   )

py_compilecompilerA   rB   
assertTruer<   r?   existsassertFalserF   rT   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<   symlinkrB   assertRaisesFileExistsErrorrW   rX   rA   NotImplementedErrorOSErrorskipTestrT   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 rQ   )r_   r`   rW   rX   rA   r<   devnullrT   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 rQ   )rW   rX   rA   rY   r<   r?   rZ   rF   rT   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 rQ   )r   
change_cwdr>   rW   rX   r<   r?   basenamerA   rB   rY   rZ   r[   rF   rT   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 rQ   )rW   rX   r<   r?   relpathrA   rB   rY   rZ   r[   rF   rT   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rQ   )r<   statr>   chmodS_IREADr_   IOErrorrW   rX   rA   rB   st_mode)rL   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?   r@   dirname__file__r   captured_stderrassertIsNonerW   rX   r[   rZ   rC   rD   rE   )rL   
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   )rW   rX   rA   rB   rY   r<   r?   rZ   r[   rF   rJ   rC   _bootstrap_external_classify_pycreadenvirongetassertEqual)rL   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.pyr7   __pycache__zfoo.bar.{}.pycr8   r9   )r<   r?   r@   r>   rC   rD   rE   splitrl   r   formatsysimplementation	cache_tagrJ   rK   rW   rX   rY   rZ   r[   )rL   
weird_pathrF   rB   headtailpenultimate_tailrN   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)assertInrW   rX   rA   rT   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      )rW   rX   rA   PycInvalidationModeCHECKED_HASHrJ   rF   rC   r   r   r   r   UNCHECKED_HASH)rL   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?   r@   r}   r~   r   r   r   rW   rX   r   getvaluer_   PyCompileError)rL   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) r/   r0   r1   rO   rU   r\   rd   unittestskipIfr<   r?   rZ   rf   isfilerg   ri   rm   rp   r   skip_if_dac_overrider'   skip_unless_working_chmodry   r   r   r   r   r   r   r   r   r    r   r   r4   r4   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   r4   c                       e Zd ZdS )PyCompileTestsWithSourceEpochNr/   r0   r1   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 )Nr6   r8   r9   )r:   r;   r>   r<   r?   r@   rA   rC   rD   rE   rF   rJ   rK   )rL   rN   s     r   rO   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 rQ   )r   rS   r>   rT   s    r   rU   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-mrW   T)r   capture_output)
subprocessrunr   
executableencoder   assert_python_ok)rL   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   rW   )r   assert_python_failure)rL   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   rA   r   
returncodestdoutr   rY   r<   r?   rZ   rF   )rL   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   rA   r   rY   r<   r?   rZ   rF   )rL   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?   r@   r}   r~   r   r   r   rL   
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?   r@   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?   r@   r}   r~   r   rA   r   r   lowerrL   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?   r@   r}   r~   r   rA   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)r/   r0   r1   rO   rU   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.utilrC   r<   rW   rR   rs   r   r   r:   r   r   r   test.supportr   r   r   r   typeTestCaser   r4   r   r   r   r/   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   