
    7bh/                        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
j4                          yy)    N)support)	os_helperscript_helperc                 D     	 t        j                          fd       }|S )Nc                      t        j                         5 }|j                  d        | i |cd d d        S # 1 sw Y   y xY w)NSOURCE_DATE_EPOCH)r   EnvironmentVarGuardunsetargskwargsenvfxns      >/opt/python-3.12.12/usr/lib/python3.12/test/test_py_compile.pywrapperz*without_source_date_epoch.<locals>.wrapper   s7    **,II)*'' -,,s	   9A	functoolswrapsr   r   s   ` r   without_source_date_epochr      s(    5__S( ( N    c                 D     	 t        j                          fd       }|S )Nc                  r    t        j                         5 }d|d<    | i |cd d d        S # 1 sw Y   y xY w)N	123456789r   )r   r	   r   s      r   r   z'with_source_date_epoch.<locals>.wrapper   s5    **,'2C#$'' -,,s   -6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 ]F  }|j                  d      st	        ||      }|rt        |      }nt        |      }t        |||       H |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__&   sg    godD%5HDw'sD)$4T:G7=GT7+  
r   )__name__
__module____qualname__r!   __classcell__)r.   s   @r   r   r   %   s     r   r   c                      e Zd Zd Zd Zd Zd Z ej                  e	j                  j                  e	j                         xs% e	j                  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j4                  j6                  dkD  d      d        Zd Zd Zd Zy)PyCompileTestsBasec                    t        j                  t        j                               | _        t        j
                  j                  | j                  d      | _        | j                  dz   | _        t        j                  j                  | j                        | _        t        j
                  j                  t        j                               d   | _        t        j
                  j                  | j                        d   }|rt        j                  |       t!        | j                  d      5 }|j#                  d       d d d        y # 1 sw Y   y xY w)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    !))biik:77<<
C((3.#..::4;K;KL++BIIK8;
 ""4#3#34Q7HHUO$""C(DJJ{# )((s   1EEc                     t        j                  | j                         | j                  r t	        j
                  | j                         y y N)shutilrmtreer>   rH   r<   rI   rL   s    r   tearDownzPyCompileTestsBase.tearDownG   s.    dnn%>>HHT^^$ r   c                 8   t        j                  | j                  | j                         | j	                  t
        j                  j                  | j                               | j                  t
        j                  j                  | j                               y rQ   )

py_compilecompilerA   rB   
assertTruer<   r?   existsassertFalserF   rT   s    r   test_absolute_pathz%PyCompileTestsBase.test_absolute_pathL   sX    4++T]];t}}5689r   c                 T   	 t        j                  | j                  dz   | j                         | j                  t              5  t        j                  | j                  | j                         d d d        y # 1 sw Y   y xY w# t        t        f$ r | j                  d       Y y 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JJt}}y0$--@
 ""?3""4#3#3T]]C 433	 $W- 	LMMJK	Ls   -B +A88B B'&B'z7requires os.devnull and for it to be a non-regular filec                     | j                  t              5  t        j                  | j                  t
        j                         d d d        y # 1 sw Y   y xY wrQ   )r_   r`   rW   rX   rA   r<   devnullrT   s    r   &test_do_not_overwrite_nonregular_filesz9PyCompileTestsBase.test_do_not_overwrite_nonregular_files]   s8    
 /t//< 0//s   /AAc                     t        j                  | j                         | j                  t        j
                  j                  | j                               y rQ   )rW   rX   rA   rY   r<   r?   rZ   rF   rT   s    r   test_cache_pathz"PyCompileTestsBase.test_cache_pathe   s3    4++,t78r   c                    t        j                  | j                        5  t        j                  t
        j                  j                  | j                        t
        j                  j                  | j                               d d d        | j                  t
        j                  j                  | j                               | j                  t
        j                  j                  | j                               y # 1 sw Y   zxY wrQ   )r   
change_cwdr>   rW   rX   r<   r?   basenamerA   rB   rY   rZ   r[   rF   rT   s    r   test_cwdzPyCompileTestsBase.test_cwdi   s    !!$..1rww//0@0@A!ww//>@ 2 	t}}5689	 21s   A%C>>Dc                    t        j                  t        j                  j	                  | j
                        t        j                  j	                  | j                               | j                  t        j                  j                  | j                               | j                  t        j                  j                  | j                               y rQ   )rW   rX   r<   r?   relpathrA   rB   rY   rZ   r[   rF   rT   s    r   test_relative_pathz%PyCompileTestsBase.test_relative_pathp   su    277??4+;+;<77??4==9	;t}}5689r   ntz/cannot control directory permissions on Windowsc                    t        j                  | j                        }t        j                  | j                  t        j                         	 | j                  t              5  t        j                  | j                  | j                         d d d        t        j                  | j                  |j                         y # 1 sw Y   4xY w# 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     wwt~~&
.	3""7+""4#3#3T]]C , HHT^^T\\2 ,+ HHT^^T\\2s$   C $+CC CC ,C:c                    t         j                  j                  t         j                  j                  t              dd      }t        j                         5  | j                  t        j                  |d             d d d        | j                  t         j                  j                  t        j                  j                  |                   y # 1 sw Y   UxY w)Ntokenizedata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    WW\\"''//(";"0"24
 $$&j00UKL 'NN,,Z8: 	; '&s   'CCc                 X   t        j                  | j                  | j                         | j	                  t
        j                  j                  | j                               | j                  t
        j                  j                  | j                               t        | j                  d      5 }t        j                  j                  |j                         di       }d d d        t
        j                  j!                  d      rd}nd}| j#                  |       y # 1 sw Y   @xY w)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689$--&"11??	62'E ' ::>>-.!N!N/ '&s   10D  D)r   ztest does not work with -Oc           	      R   t         j                  j                  | j                  d      }t        j
                  j                  |      }|dz   }t         j                  j                  |      \  }}t         j                  j                  |      }| j                  t         j                  j                  ||      t         j                  j                  ddj                  t        j                  j                                     t        |d      5 }|j                  d       d d d        t!        j"                  |       | j%                  t         j                  j'                  |             | j)                  t         j                  j'                  |             y # 1 sw Y   {xY w)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    WW\\$..,?
^^55jA
#WW]]:.
d77++D1GGLL)40GGLL ''(:(:(D(DEG	H
 *c"dJJ{# #:&z2312	 #"s   FF&c                 f    | j                  dt        j                  | j                  d             y )Nzopt-2   )optimize)assertInrW   rX   rA   rT   s    r   test_optimization_pathz)PyCompileTestsBase.test_optimization_path   s#    gz11$2B2BQOPr   c                    t        j                  | j                  t         j                  j                         t        | j                  d      5 }t        j                  j                  |j                         di       }d d d        | j                  d       t        j                  | j                  t         j                  j                         t        | j                  d      5 }t        j                  j                  |j                         di       }d d d        | j                  |d       y # 1 sw Y   xY w# 1 sw Y   (xY w)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I	
 $//4(B11??	62'E ) 	%(<<KK	
 $//4(B11??	62'E ) 	$ )( )(s   0D4)0E 4D= E	c                 N   t         j                  j                  t         j                  j                  t              dd      }t        j                         5 }| j                  t        j                  |dd             | j                  t        j                  |dd             | j                  |j                         d       | j                  t        j                        5  t        j                  |dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	Nr{   r|   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    WW\\"''//(";"0"24
 $$&&j00URSTUj00TQRSTV__.3"":#<#<="":t1E >	 '& >=	 '&s%   BD%D>DD	DD$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 X__

33Qrww~~bjj7QNP=P=9:: ##X__RWW_FH((
3 )H $
3;0 X__SYY''!+-IJ3 K3&Q%$	Fr   r4   c                       e Zd Zy)PyCompileTestsWithSourceEpochNr/   r0   r1   r   r   r   r   r           	r   r   T)	metaclassr*   c                       e Zd Zy) PyCompileTestsWithoutSourceEpochNr   r   r   r   r   r      r   r   r   Fc                   p    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y)PyCompileCLITestCasec                 l   t        j                         | _        t        j                  j                  | j                  d      | _        t        j                  j                  | j                  d      | _
        t        | j                  d      5 }|j                  d       d d d        y # 1 sw Y   y xY w)Nr6   r   )optimizationr8   r9   )r:   r;   r>   r<   r?   r@   rA   rC   rD   rE   rF   rJ   rK   )rL   rN   s     r   rO   zPyCompileCLITestCase.setUp   s~    !))+77<<
C#..::4;K;KBC ; E$""C(DJJ{# )((s   B**B3c                 B    t        j                  | j                         y rQ   )r   rS   r>   rT   s    r   rU   zPyCompileCLITestCase.tearDown   s    (r   c                     d}|rG|d   dk(  r?d|v r;t        j                  t        j                  |ddg|d   j	                         d      S t        j                  |dg|i |S )Nz-Omr   -inputrW   T)r   capture_output)
subprocessrunr   
executableencoder   assert_python_ok)rL   r   r   optss       r   pycompilecmdz!PyCompileCLITestCase.pycompilecmd   so    
 ',DGsNw&'8>>3>>4s"K(.w(>(>(@157 7 --dLR4R6RRr   c                 0    t        j                  ddg| S )Nz-mrW   )r   assert_python_failure)rL   r   s     r   pycompilecmd_failurez)PyCompileCLITestCase.pycompilecmd_failure   s    224MMMr   c                    | j                  t        j                  j                  | j                               | j                  d| j                        }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  t        j                  j                  | j                               y )Nr   )r   r   r   )r[   r<   r?   rZ   rF   r   rA   r   
returncodestdoutr   rY   )rL   results     r   
test_stdinzPyCompileCLITestCase.test_stdin   s    89""3d.>.>"?**A.,,t78r   c                 4   | j                  | j                  | j                        \  }}}| j                  |d       | j                  |d       | j                  |d       | j                  t        j
                  j                  | j                               y )Nr   r   )r   rA   r   rY   r<   r?   rZ   rF   )rL   rcr   r   s       r   test_with_filesz$PyCompileCLITestCase.test_with_files  st    !..t/?/?AQAQRFFQ%%t78r   c                    t         j                  j                  t         j                  j                  t              dd      }| j                  |      \  }}}| j                  |d       | j                  |d       | j                  d|       y )Nr{   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  sp    WW\\"''//(";"0"57
 "66zBFFQ%nf-r   c                     t         j                  j                  t         j                  j                  t              dd      }| j                  d|      \  }}}| j                  |d       | j                  |d       | j                  |d       y )Nr{   r   -qr   r   )r<   r?   r@   r~   r   r   r   r   s        r   test_bad_syntax_with_quietz/PyCompileCLITestCase.test_bad_syntax_with_quiet  st    WW\\"''//(";"0"57
 "66tZHFFQ%%r   c                 N   t         j                  j                  t         j                  j                  t              d      }| j                  | j                  |      \  }}}| j                  |d       | j                  |d       | j                  d|j                                y )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  sz    GGLL)BDZ[!66t7G7GIZ[FFQ%2FLLNCr   c                 4   t         j                  j                  t         j                  j                  t              d      }| j                  d| j                  |      \  }}}| j                  |d       | j                  |d       | j                  |d       y )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%  sw    GGLL)BDZ[!66tT=M=MO`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      sR    $) !W  "	S #	SN99.&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d8#4#45  [F [F|	$6$,$5$5.E6:		'9'/'8'81H9>	I&8,, I&X zHMMO r   