a ze+@sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddZddZGdd d ee jZGd d d ZGd d d ee jeddZGdddee jeddZGddde jZedkre dS)N)support) script_helpercstfdd}|S)z+Runs function with SOURCE_DATE_EPOCH unset.csDt(}|d|i|WdS1s60YdS)NSOURCE_DATE_EPOCH)rEnvironmentVarGuardZunsetargskwargsenvfxnH/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_py_compile.pywrappers  z*without_source_date_epoch..wrapper functoolswrapsr rr r r without_source_date_epochsrcstfdd}|S)z)Runs function with SOURCE_DATE_EPOCH set.csBt&}d|d<|i|WdS1s40YdS)NZ 123456789r)rrrr r r rs z'with_source_date_epoch..wrapperrrr r r with_source_date_epochsrcseZdZfddZZS)SourceDateEpochTestMetac sZt||||}t|D]:}|drt||}|r@t|}nt|}t|||q|S)NZtest_)super__new__dir startswithgetattrrrsetattr) mclsnamebasesZdctsource_date_epochclsattrmethr __class__r r r&s    zSourceDateEpochTestMeta.__new__)__name__ __module__ __qualname__r __classcell__r r r#r r%src@seZdZddZddZddZddZee j e j  pHe j e j d d d Zd d ZddZddZeee doe dkdee jdkdddZddZddZeejjdkdddZd d!Zd"d#Zd$d%Zd&S)'PyCompileTestsBasecCstjtd|_tj|jd|_|jd|_t j |j|_ tj td|_tj |jd}|rvt|t|jd}|dWdn1s0YdS)N)r_test.pycrwx = 123 )tempfilemkdtemposgetcwd directorypathjoin source_pathpyc_path importlibutilcache_from_source cache_path splitdrive cwd_drivechdiropenwrite)selfdrivefiler r r setUp7s  zPyCompileTestsBase.setUpcCs"t|j|jrt|jdSN)shutilrmtreer2r<r0r=r@r r r tearDownGs zPyCompileTestsBase.tearDowncCs<t|j|j|tj|j|tj|j dSrD) py_compilecompiler5r6 assertTruer0r3exists assertFalser:rGr r r test_absolute_pathLsz%PyCompileTestsBase.test_absolute_pathc Csxzt|jd|jWn ttfy8|dYn<0|t t |j |jWdn1sj0YdS)Nz.actualz.need to be able to create a symlink for a file) r0symlinkr6NotImplementedErrorOSErrorZskipTest assertRaisesFileExistsErrorrIrJr5rGr r r test_do_not_overwrite_symlinksQs  z1PyCompileTestsBase.test_do_not_overwrite_symlinksz7requires os.devnull and for it to be a non-regular filecCs>|t t|jtjWdn1s00YdSrD)rRrSrIrJr5r0devnullrGr r r &test_do_not_overwrite_nonregular_files]s z9PyCompileTestsBase.test_do_not_overwrite_nonregular_filescCs$t|j|tj|jdSrD)rIrJr5rKr0r3rLr:rGr r r test_cache_pathes z"PyCompileTestsBase.test_cache_pathcCsxt|j0ttj|jtj|j Wdn1sB0Y| tj |j | tj |j dSrD)rZ change_cwdr2rIrJr0r3basenamer5r6rKrLrMr:rGr r r test_cwdis  "zPyCompileTestsBase.test_cwdcCsLttj|jtj|j|tj|j| tj|j dSrD) rIrJr0r3relpathr5r6rKrLrMr:rGr r r test_relative_pathps  z%PyCompileTestsBase.test_relative_pathgeteuidrznon-root user requiredntz/cannot control directory permissions on Windowsc Cst|j}t|jtjzN|t t|j |j Wdn1sN0YWt|j|j nt|j|j 0dSrD) r0statr2chmodS_IREADrRIOErrorrIrJr5r6st_mode)r@moder r r test_exceptions_propagatevs   0z,PyCompileTestsBase.test_exceptions_propagatecCsptjtjtd}t$|tj |ddWdn1sH0Y| tj t j |dS)Nbad_coding2.pyF)doraise)r0r3r4dirname__file__rcaptured_stderr assertIsNonerIrJrMrLr7r8r9)r@ bad_codingr r r test_bad_codings  2  z"PyCompileTestsBase.test_bad_codingcCst|j|j|tj|j|tj|j t |jd$}t j |di}Wdn1sn0Ytjdrd}nd}|||dS)Nrbtestrr)rIrJr5r6rKr0r3rLrMr:r>r7_bootstrap_external _classify_pycreadenvironget assertEqual)r@fpflagsZexpected_flagsr r r test_source_date_epochs " z)PyCompileTestsBase.test_source_date_epochztest does not work with -Oc Cstj|jd}tj|}|d}tj|\}}tj|}| tj||tjdd t j j t|d}|dWdn1s0Yt||tj||tj|dS)Nz foo.bar.pyr+ __pycache__zfoo.bar.{}.pycr,r-)r0r3r4r2r7r8r9splitrXruformatsysimplementation cache_tagr>r?rIrJrKrLrM)r@Z weird_pathr:r6headtailZpenultimate_tailrBr r r test_double_dot_no_clobbers"     ( z-PyCompileTestsBase.test_double_dot_no_clobbercCs|dtj|jdddS)Nzopt-2)optimize)assertInrIrJr5rGr r r test_optimization_pathsz)PyCompileTestsBase.test_optimization_pathcCstj|jtjjdt|jd$}tj | di}Wdn1sJ0Y| |dtj|jtjj dt|jd$}tj | di}Wdn1s0Y| |ddS)N)invalidation_modermrnro) rIrJr5PycInvalidationMode CHECKED_HASHr>r:r7rprqrrruUNCHECKED_HASH)r@rvrwr r r test_invalidation_modes$ "  "z)PyCompileTestsBase.test_invalidation_modec Cstjtjtd}t}|tj |ddd|tj |ddd| | d| tj  tj |dddWdn1s0YWdn1s0YdS)NreFr)rfquietTr)r0r3r4rgrhrrirjrIrJrugetvaluerRPyCompileError)r@rkstderrr r r test_quiets zPyCompileTestsBase.test_quietN)r%r&r'rCrHrNrTunittestZskipIfr0r3rLrUisfilerVrWrYr[hasattrr\rrdrlrxr|rwrrrrrr r r r r)5s2     r)c@s eZdZdS)PyCompileTestsWithSourceEpochNr%r&r'r r r r rsrT) metaclassrc@s eZdZdS) PyCompileTestsWithoutSourceEpochNrr r r r rsrFc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)PyCompileCLITestCasecCsft|_tj|jd|_tj |j|_ t |jd}| dWdn1sX0YdS)Nr*r,r-) r.r/r2r0r3r4r5r7r8r9r:r>r?)r@rBr r r rCs  zPyCompileCLITestCase.setUpcCst|jdSrD)rrFr2rGr r r rHszPyCompileCLITestCase.tearDowncOsT|r:|ddkr:d|vr:tjtjdddg|dddStjddg|Ri|S)Nr-input-mrIT)rcapture_output) subprocessrunr| executableencoderZassert_python_ok)r@rrr r r pycompilecmds  z!PyCompileCLITestCase.pycompilecmdcGstjddg|RS)NrrI)rZassert_python_failure)r@rr r r pycompilecmd_failuresz)PyCompileCLITestCase.pycompilecmd_failurecCsR|jd|jd}||jd||jd||jd|tj |j dS)Nr)rr) rr5ru returncodestdoutrrKr0r3rLr:)r@resultr r r test_stdins zPyCompileCLITestCase.test_stdincCsR||j|j\}}}||d||d||d|tj|jdS)Nrr)rr5rurKr0r3rLr:)r@rcrrr r r test_with_filess    z$PyCompileCLITestCase.test_with_filescCsNtjtjtd}||\}}}||d||d|d|dS)Nzbadsyntax_3131.pyrrs SyntaxError)r0r3r4rgrhrrur)r@Z bad_syntaxrrrr r r test_bad_syntaxs   z$PyCompileCLITestCase.test_bad_syntaxcCsRtjtjtd}||j|\}}}||d||d|d|dS)Nzshould_not_exists.pyrrsNo such file or directory) r0r3r4rgrhrr5rur)r@Zshould_not_existsrrrr r r test_file_not_exists s   z)PyCompileCLITestCase.test_file_not_existsN) r%r&r'rCrHrrrrrrr r r r rs r__main__)rimportlib.utilr7r0rIrEr^rr|r.rrnrZ test.supportrrrtypeZTestCaserr)rrrr%mainr r r r s:      6