a zed@sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZmZzddlmZdZWneydZYn0ddlmZddlmZdd lmZdd lmZd d Zd dZddZ GdddZ!Gddde!ej"eddZ#Gddde!ej"eddZ$Gdddej"Z%GdddZ&Gddde&ej"eddZ'Gddde&ej"eddZ(Gd d!d!Z)Gd"d#d#e)ej"eddZ*Gd$d%d%e)ej"eddZ+e,d&kre-dS)'N)mock skipUnless)ProcessPoolExecutorTF)support) script_helper)without_source_date_epoch)SourceDateEpochTestMetacCs|sd}tjj||dS)N optimization) importlibutilcache_from_source)scriptoptrH/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_compileall.pyget_pyc srcsfdddDS)Ncsg|]}t|qSr)r).0rrrr (zget_pycs..rrrrrrrget_pycs'srcCs t|j}t|j}||kS)z8Returns True if two files have the same inode (hardlink))osstatst_ino)Z filename1 filename2Zinode1Zinode2rrr is_hardlink+s  r c@sheZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zed#d$d%Zd&d'Zed#d(d)Zed#ed*d+d,Zejd#d-d.ed*d/d0Zd1d2Zd3d4d5d6Zd7d8Zd9d:Zd;d<Zd=d>Z d?d@Z!dAdBZ"dCdDZ#dEdFZ$dGdHZ%e&j'dIdJZ(d-S)KCompileallTestsBasecCst|_tj|jd|_tj |j|_ t |jd}| dWdn1sX0Ytj|jd|_ tj |j |_t|j|j tj|jd|_t|jtj|jd|_t|j|jdS)N_test.pywzx = 123 z _test2.pyZ_subdirz _test3.py)tempfilemkdtemp directoryrpathjoin source_pathr rrbc_pathopenwrite source_path2bc_path2shutilcopyfileZ subdirectorymkdir source_path3selffilerrrsetUp4s ( zCompileallTestsBase.setUpcCst|jdSNr/rmtreer&r4rrrtearDownBszCompileallTestsBase.tearDowncCsLtj|jd|_t|jd}|dWdn1s>0YdS)Nz _test_bad.pyr#zx ( )rr'r(r&bad_source_pathr+r,r3rrradd_bad_source_fileEsz'CompileallTestsBase.add_bad_source_filecCsht|jd}|d}Wdn1s,0Ytt|jj}t dt j j d|d@}||fS)Nrb <4sLLr) r+r*readintrrr)st_mtimestructpackr r MAGIC_NUMBER)r4r5datamtimeZcomparerrrtimestamp_metadataJs(z&CompileallTestsBase.timestamp_metadatac Csxzt|jdWn ttfy2|dYn0tt "| t |jWdn1sj0YdS)N)rArAz0filesystem doesn't support timestamps near 2**32 rutimer) OverflowErrorOSErrorZskipTest contextlibredirect_stdoutioStringIO assertTrue compileall compile_filer:rrr test_year_2038_mtime_compilationRs z4CompileallTestsBase.test_year_2038_mtime_compilationc Csxzt|jdWn ttfy2|dYn0tt "| t |jWdn1sj0YdS)N) rWz+filesystem doesn't support large timestampsrKr:rrrtest_larger_than_32_bit_times\s z1CompileallTestsBase.test_larger_than_32_bit_timescCstjdrtdt|j|j| t |j d$}| t |d}Wdn1sf0Yt |j d$}||||Wdn1s0Y|j| tj|jddd|j| dS) zOCheck that compileall recreates bytecode when the new metadata is used.SOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setr>NwbFTforcequiet)renvirongetunittestSkipTest py_compilecompiler) assertEqualrJr+r*rBlenr,assertNotEqualrT compile_dirr&rS)r4metadatar5bcrrrrecreation_checkfs   2 (z$CompileallTestsBase.recreation_checkcCs|tdtjjdddS)Nr@rr)rjrErFr rrGr:rrr test_mtimevszCompileallTestsBase.test_mtimecCs|ddS)Ns)rjr:rrrtest_magic_number{sz%CompileallTestsBase.test_magic_numbercCs|j|jfD] }zt|Wq Yq 0q |tj|jddd|tj |joftj |j t|j|tj |j ddd|tj |jotj |jt|jt|j| | tj|jddd| tj |j ddddS)NFTr[r)r*r.runlinkrSrTrUr)r'isfilergr&r= assertFalser<)r4fnrrrtest_compile_filess6       z&CompileallTestsBase.test_compile_filescCs||tj|jt(}|t t |j Wdn1sJ0Y| |d|tj|jdS)Nz&Compiling ([^WindowsPath|PosixPath].*))rorr'rnr*rcaptured_stdoutrSrTrUpathlibPathr) assertRegexgetvalue)r4stdoutrrrtest_compile_file_pathlikes  6z.CompileallTestsBase.test_compile_file_pathlikecCsP|tj|j|tjt |j t ddd|tj|jdS)NZ ddir_pathr)ddirr]) rorr'rnr*rSrTrUrsrtr)r:rrrtest_compile_file_pathlike_ddirs z3CompileallTestsBase.test_compile_file_pathlike_ddircCstjjj|jgd"|tjddWdn1s<0Ytjjj|jgd.|| tjddddWdn1s0YdS)Nr'rr]FT) skip_curdirr\r]) testtest_importlibrZ import_stater&rSrT compile_pathr=ror:rrrtest_compile_paths0 z%CompileallTestsBase.test_compile_pathcCs|tj|jd}tj|d}t|t|dWdn1sH0Yt||tj tj|ddS)NrHr5r# __pycache__) rr'r(r&r1r+rTrUroexists)r4Zdata_dirZ data_filerrrtest_no_pycache_in_non_packages   z2CompileallTestsBase.test_no_pycache_in_non_packagecCsL|tt"|t|jWdn1s>0YdSr7) r=rOrPrQrRrorTrUr<r:rrr#test_compile_file_encoding_fallbacksz7CompileallTestsBase.test_compile_file_encoding_fallbackcCsdrdnd\}}tj|jd|dtjj|j|d}|tj |tjj|j |d}|tj |tjj|j |d}|tj |dS)NF)rr)rr Tr]optimizer ) rTrgr&r rrr)rSrr'rnr-r2)r4rrcachedZcached2Zcached3rrr test_optimizes   z!CompileallTestsBase.test_optimizecCs|tj|jt"}tt |j Wdn1sD0Y| d}||d|tj|jdS)Nrz$Listing ([^WindowsPath|PosixPath].*))rorr'rnr*rrrrTrgrsrtr&rv splitlinesrurS)r4rwlinerrrtest_compile_dir_pathlikes  0 z-CompileallTestsBase.test_compile_dir_pathlikez&concurrent.futures.ProcessPoolExecutorcCs"tj|jddd||jdSNTr]workersrTrgr&rScalledr4 pool_mockrrrtest_compile_pool_calledsz,CompileallTestsBase.test_compile_pool_calledcCs@|td tj|jddWdn1s20YdS)Nz%workers must be greater or equal to 0)r)ZassertRaisesRegex ValueErrorrTrgr&r:rrr!test_compile_workers_non_positivesz5CompileallTestsBase.test_compile_workers_non_positivecCs,tj|jddd||jddddS)NTrrr max_workers)rTrgr&rd call_argsrrrrtest_compile_workers_cpu_countsz2CompileallTestsBase.test_compile_workers_cpu_countzcompileall.compile_filecCs,tj|jdd||j||jdS)NTr|)rTrgr&rorrS)r4compile_file_mockrrrrtest_compile_one_workers z+CompileallTestsBase.test_compile_one_workerNnewcCs"tj|jddd||jdSrr)r4rrrr$test_compile_missing_multiprocessingsz8CompileallTestsBase.test_compile_missing_multiprocessingcCsd}|j}td|dD]>}tj|d|}tj|d}t|t|j|qt j |}t j |jd|dd|tj|t j |jd|d|tj|dS)NrZdir_z script.pyT)r] maxlevels)r&rangerr'r(r1r/r0r)r rrrTrgrornrS)r4depthr'isourceZ pyc_filenamerrrtest_compile_dir_maxlevelss  z.CompileallTestsBase.test_compile_dir_maxlevelsT)parallelcCsddg}|j}g}|D]>}tj||}t|t|dd|t|ddqtj |jd||rjdnd d | ||D]}| | |j|t j |}|t|jtjd } t|\} } } tj|| } tjj |} || j| |d | d t| qd S) z@Recursive compile_dir ddir must contain package paths; bpo39769.r~foo__init__r modzdef fn(): 1/0 fn() Trr)r]ryrN")r&rr'r(r1r make_scriptappendrTrgrS startswithr rrresepassert_python_failurer~rZget_code_from_pycrd co_filenameassertInfsdecode)r4ryrfullpathr'ZmodsZsubdirrZmodcodemodpath_err expected_inZ mod_code_objrrr_test_ddir_onlys0     z#CompileallTestsBase._test_ddir_onlycCs|jdddS)=Recursive compile_dir ddir= contains package paths; bpo39769. Fryrrr:rrrtest_ddir_only_one_worker!sz-CompileallTestsBase.test_ddir_only_one_workercCs|jdddS)rrTrrr:rrrtest_ddir_multiple_workers%sz.CompileallTestsBase.test_ddir_multiple_workerscCs|jdddS)?Recursive compile_dir ddir='' contains package paths; bpo39769.r Frrr:rrrtest_ddir_empty_only_one_worker)sz3CompileallTestsBase.test_ddir_empty_only_one_workercCs|jdddS)rr Trrr:rrr test_ddir_empty_multiple_workers-sz4CompileallTestsBase.test_ddir_empty_multiple_workersc Csgd}tjj|jg|R}t|t|dd}tj |}tjj|jg|ddR}t j |d|dt |\}}}tjj|dd} | | t|td||t|tddS)Nr~buildrealr'r~1 / 0rT)r]stripdirencodingrr'r(r&makedirsrrr rrrTrgrrstrsysgetdefaultencoding assertNotIn) r4rr'rrirrcoutrrrrrtest_strip_only1s"  z#CompileallTestsBase.test_strip_onlyc Csgd}tjj|jg|R}t|t|dd}tj |}d}t j |d|dt |\}}}tjj||jg|R} | | t|tddS)Nrr~r/fooT)r] prependdirr)rr'r(r&rrrr rrrTrgrrrrr) r4rr'rrirrrrrrrrtest_prepend_onlyDs  z%CompileallTestsBase.test_prepend_onlyc Csgd}tjj|jg|R}t|t|dd}tj |}tjj|jg|ddR}d}t j |d||dt |\}}} tjj|g|ddR} | | t| td||t| tddS) Nrr~rrrT)r]rrrr r4rr'rrirrrrrrrrrtest_strip_and_prependSs(  z*CompileallTestsBase.test_strip_and_prependcCsxgd}tjj|jg|R}t|t|dd|t$t j |dddddWdn1sj0YdS)N)r~rrr'ryr~rTz/barr)r]ryrr) rr'r(r&rrr assertRaisesrrTrg)r4rr'rrrtest_strip_prepend_and_ddirhs   z/CompileallTestsBase.test_strip_prepend_and_ddirc Cst|jdd}g}dD]}|tjj||dqddgddgddggdg}|D]Z}tj|d |d |D]@}| t j ||zt ||WqltyYql0qlqTdS) Ntest_optimizationa = 0r rrrr rrrrTr)rrr&rr rrrTrUrSrr'rnrm Exception)r4rri opt_leveltest_combinationsopt_combinationrrr!test_multiple_optimization_levelsqs(   z5CompileallTestsBase.test_multiple_optimization_levelsc Cstj|jddd}tj|jddd}tj|jddd}t|t|t|t|dd}t|dd}tj|d }tj|d }t||t||tj |}tj |} t j |d |d | tj||tj| dS) Nr~dirallowedsymlinks prohibited test_allowedrtest_prohibitedtest_allowed.pytest_prohibited.pyT)r] limit_sl_dest)rr'r(r&rrrsymlinkr rrrTrgrSrnro r4Z allowed_pathZ symlinks_pathZprohibited_pathZallowed_scriptZprohibited_scriptZallowed_symlinkZprohibited_symlinkZ allowed_bcZ prohibited_bcrrrtest_ignore_symlink_destinations"       z3CompileallTestsBase.test_ignore_symlink_destination))__name__ __module__ __qualname__r6r;r=rJrVrXrjrkrlrqrxrzrrrrrrpatchrrrrrrrrrrrrrrrrrskip_unless_symlinkrrrrrr!2sR          r!c@s eZdZdS)CompileallTestsWithSourceEpochNrrrrrrrrsr) metaclassZsource_date_epochc@s eZdZdS)!CompileallTestsWithoutSourceEpochNrrrrrrsrc@s(eZdZdZddZddZddZdS) EncodingTestzTIssue 6716: compileall should escape source code when printing errors to stdout.cCsdt|_tj|jd|_t|jddd$}|d|dWdn1sV0YdS)Nr"r#utf-8rz# -*- coding: utf-8 -*- u print u"€" ) r$r%r&rr'r(r)r+r,r3rrrr6s   zEncodingTest.setUpcCst|jdSr7r8r:rrrr;szEncodingTest.tearDowncCs>z0tj}tjtddt_t|jW|t_n|t_0dS)Nasciir)rrwrQ TextIOWrapperBytesIOrTrgr&)r4Z orig_stdoutrrr test_errors zEncodingTest.test_errorN)rrr__doc__r6r;rrrrrrsrc@seZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ eddZddZddgfdddgfdddgffD]&\ZZZeefd d!Zeed"e<qd#d$Zd%d&Zed'd(Zd)d*Zd+d,Zejd-d.Zd/d0Zd1d2Zd3d4Z d5d6Z!d7d8Z"d9d:Z#d;d<Z$d=d>Z%d?d@Z&dAdBZ'dCdDZ(dEdFZ)dGdHZ*e+e,dIdJdKZ-e./dLdMdNZ0dOdPZ1dQdRZ2ejdSdTZ3dUdVZ4dWdXZ5dYS)ZCommandLineTestsBasezTest compileall's CLI.c CsttjjtjD]}d}t|d}|d}zzL|sF|d}| d}| dWdn1sp0YWn8t yd}YWt t||r|qYn0Wt t||r|qt t||r|0qd}||_dS)NFrztest.tryTr#z# for test_compileall)filterrr'isdirrrsrtis_dirr1r+r,rNrrmrrmdir_sys_path_writable)clsr'Zdirectory_createdr&r5Zsys_path_writablerrr setUpClasss2 ,    zCommandLineTestsBase.setUpClasscCs|jstddS)Nz(not all entries on sys.path are writable)rr`rar:rrr_skip_if_sys_path_not_writablesz3CommandLineTestsBase._skip_if_sys_path_not_writablecCsgtddd|S)Nz-S-mrT)rZ!optim_args_from_interpreter_flags)r4argsrrr _get_run_argss z"CommandLineTestsBase._get_run_argscOs4tj||i|ddi\}}}|d||S)NPYTHONIOENCODINGrr)rassert_python_okr rdr4r Zenv_varsrrrrrr assertRunOKs z CommandLineTestsBase.assertRunOKcOs.tj||i|ddi\}}}|||fS)Nr r)rrr r rrrassertRunNotOKsz#CommandLineTestsBase.assertRunNotOKcCs"tj|}|tj|dSr7)r rrrSrr'rr4rpr'rrrassertCompileds z#CommandLineTestsBase.assertCompiledcCs"tj|}|tj|dSr7)r rrrorr'rrrrrassertNotCompileds z&CommandLineTestsBase.assertNotCompiledcCsrt|_|tj|jtj|jd|_ t |j tj|j d|_ t |j dd|_t |j dd|_dS)Nrrrr Zbar)r$r%r&Z addCleanuprr9rr'r(pkgdirr1pkgdir_cachedirrrinitfnbarfnr:rrrr6s  zCommandLineTestsBase.setUpcCsL|t|jdd}|j|jd||||j||jdS)Nbazr  PYTHONPATH) rrrr&rrrrr)r4bazfnrrrtest_no_args_compiles_paths   z/CommandLineTestsBase.test_no_args_compiles_pathcCs|t|jdd}|j|jdtj|}t |t dfdt |j }|j|jdt |j }| |||jd|jdt |j }|||dS)Nrr r<r-f)rrrr&rr rrrrLtimerrDrdrf)r4rpycpathrImtime2rrr test_no_args_respects_force_flags     z5CommandLineTestsBase.test_no_args_respects_force_flagcCsR|t|jdd|j|jd}|d||jd|jd}|d|dS)Nrr rsListing -q)rrrr&rrrr4Znoisyr]rrr test_no_args_respects_quiet_flag s  z5CommandLineTestsBase.test_no_args_respects_quiet_flagZnormalpycrz opt-1.pyc-OZdoubleoptimizez opt-2.pycz-OOcs~tj|ddd|jg|tj|jtfdddD}| tt |j|| fddt |jDdS) NrrTr"c3s|]}|tjjVqdSr7)formatrimplementation cache_tag)rbaseextrr 4sz)CommandLineTestsBase.f..)z__init__.{}.{}z bar.{}.{}csg|]}|r|qSr)endswith)rrpr+rrr8s z*CommandLineTestsBase.f..) rr rrSrr'rrsortedrdlistdirro)r4r,switchexpectedrr+rf/s  zCommandLineTestsBase.fZtest_pep3147_paths_cCsL|dd|j|tj|jtgd}|tt |j|dS)Nz-br") __init__.pyz __init__.pyczbar.pyzbar.pyc) rrrorr'rrr/rdr0)r4r2rrrtest_legacy_paths<s z&CommandLineTestsBase.test_legacy_pathscCs||d|j|tj|jtj|jd}|tj||d|j|tj|j|tj|dS)Nr"r) rrrSrr'rrr(ro)r4Z cachecachedirrrrtest_multiple_runsFsz'CommandLineTestsBase.test_multiple_runscCs|d|jtj|j}t|tdfdt |j }|d|jt |j }| |||dd|jt |j }| ||dS)Nr"rrr) rrr rrrrrLrrrDrdrf)r4rrIr rrr test_forceSs    zCommandLineTestsBase.test_forcecCstj|jd}t|t|dd}t|dd}|dd|j||| tj tj|d|d|j| || |dS)Nspamrr hamr"z-lr) rr'r(rr1rrrrrorr)r4 subpackage subinitfnhamfnrrrtest_recursion_controlcs   z+CommandLineTestsBase.test_recursion_controlc CsVtj|jd}tj|d}tj|d}|||fD]}t|q6tj|d}t|dd}t|dd}t|dd}|dd|j||| tj tj|d |dd |j| || ||||dd |j| || || ||||dd |j| || || || |dS) Nr8r9Zeggsr4r Zeggr"z-r 0rz-r 1z-r 2z-r 5) rr'r(rrmake_pkgrrrrorr) r4r:Z subpackage2Z subpackage3pkgr;r<ZspamfnZeggfnrrrtest_recursion_limitos8            z)CommandLineTestsBase.test_recursion_limitc Csttj|jd}t|tdtj|dtdtj|d|d|j|tj|jdddddS)Nr8.ZevilZevil2r"r4) rr'r(rrr>rrr)r4r?rrrtest_symlink_loops   z&CommandLineTestsBase.test_symlink_loopcCs6||j}|d|j}|d||d|dS)Nr"r)rrrfrdr#rrr test_quiets  zCommandLineTestsBase.test_quietcCsTt|jdd|d|j\}}}|d|j\}}}|d||d|dS)N crunchyfrog bad(syntaxr"z-qqr)rrrrrfrd)r4rr]Zsilentrrr test_silents  z CommandLineTestsBase.test_silentcCs.|ddd|j||j||jdS)Nr"z-xz ba[^\\/]*$)rrrrrrr:rrr test_regexps z CommandLineTestsBase.test_regexpcCsvtj|jd}t|t|dd}t|dd}|d|j|| |j | |j | || |dS)NZfoo2rr bar2r") rr'r(r&r1rrrrrrr)r4Zpkgdir2Zinit2fnbar2fnrrrtest_multiple_dirss    z'CommandLineTestsBase.test_multiple_dirscCs8t|jdd|ddd|j\}}}||ddS)NrDrEr"-ddinsdaleFile "dinsdale)rrrrrur4rrrrrrtest_d_compile_errorsz)CommandLineTestsBase.test_d_compile_errorcCst|jdd}|ddd|jt|jdd}tj|}t|tj |jdt |tj |d d \}}}| |d dS) Nrzraise Exceptionr"rKrLbingz import bazzbaz.pycF) __isolatedrM)rrrrr rrrrenamer'r(removerru)r4rrpr%rrrrrrtest_d_runtime_errors  z)CommandLineTestsBase.test_d_runtime_errorcCsZ|dtj|jd|j\}}}||d||d|tj t j |j dS)N-i nosuchfilesrror.*nosuchfiles Traceback)rrr'r(r&rruZassertNotRegexrorr rrrrNrrrtest_include_bad_files   z*CommandLineTestsBase.test_include_bad_filecCst|jdd}t|jdd}t|jdd}t|jdd}ttj|jddH}|tj|jdtj |tj|jd tj Wdn1s0Y| d tj|jd|| || || || |dS) Nf1r f2f3f4l1r#f1.pyf2.pyrU) rrrr+rr'r(r&r,lineseprrrr4rXrYrZr[r\rrrtest_include_file_with_args:   z/CommandLineTestsBase.test_include_file_with_argcCst|jdd}t|jdd}t|jdd}t|jdd}ttj|jdd,}|tj|jdtj Wdn1s0Y| d tj|jd| || || || |dS) NrXr rYrZr[r\r#r^rU) rrrr+rr'r(r&r,r_rrrr`rrrtest_include_file_no_args:   z-CommandLineTestsBase.test_include_file_no_argcCst|jdd}t|jdd}t|jdd}t|jdd}tj|dddg}|j|tj d t || || || || |dS) NrXr rYrZr[rrU-r) rrrZ spawn_pythonr stdinr,rr_encodeZ kill_pythonrr)r4rXrYrZr[prrrtest_include_on_stdins    z*CommandLineTestsBase.test_include_on_stdincCs\t|jdd}|d|j||j\}}}||d||||j||jdS)NrPz syntax(errorrVsrror) rrrrrrrurr)r4Zbingfnrrrrrr!test_compiles_as_much_as_possibles     z6CommandLineTestsBase.test_compiles_as_much_as_possiblecCs|d}||ddS)NZ badfilenamesCan't list 'badfilename')rru)r4rrrr!test_invalid_arg_produces_messages z6CommandLineTestsBase.test_invalid_arg_produces_messagecCst|jddtjtj|jd}| d|jt |d}| }Wdn1s^0Y| t |dddd | d |jt |d}| }Wdn1s0Y| t |dddd dS) NrXr r]z --invalidation-mode=checked-hashr>littlerz"--invalidation-mode=unchecked-hashr)rrrr rrrr'r(rr+rBrdrC from_bytes)r4r%fprHrrrtest_pyc_invalidation_modes & &z/CommandLineTestsBase.test_pyc_invalidation_modezrequires multiprocessingcCst|jdd}g}tdD]F}tj|jd|}t|t|dd}| t|ddq| |jdd| ||D]}| |qdS)NrHr rzfoo{}rz-j0) rrr&rrr'r(r'r1rrr)r4rIfilessuffixrrpr5rrr test_workerss   z!CommandLineTestsBase.test_workerszcompileall.compile_dircCsftjdtj|jdgd:t||j| |j dddWdn1sX0YdS)Nzsys.argvz-j0rrrr) rrr executabler&rTmainrSrrdr)r4rgrrrtest_workers_available_cores$s   z1CommandLineTestsBase.test_workers_available_coresc Csgd}tjj|jg|R}t|t|dd}tj |}tjj|jg|ddR}d}| d|d||t |\}}} tjj|g|ddR} | | t | td||t | tddS) Nrr~rrrz-sz-pr)rr'r(r&rrrr rrrrrrrrrrrrrr,s$  z+CommandLineTestsBase.test_strip_and_prependc Cstj|jd}t|t|dd}g}dD]}|tj j ||dq0ddgddgddggd g}|D]j}|j |gd d |DR|D]D}| tj |t|zt||WqtyYq0qqldS) NZ optimizationsrrrr rp12)rprwrxcss|]}dt|VqdS)z-oN)r)rnrrrr-OrzICommandLineTestsBase.test_multiple_optimization_levels..)rr'r(r&rrrrr rrrrSrnrCrmr)r4r'rrirrrrrrr@s0    z6CommandLineTestsBase.test_multiple_optimization_levelsc Cstj|jddd}tj|jddd}tj|jddd}t|t|t|t|dd}t|dd}tj|d }tj|d }t||t||tj |}tj |} | |d || tj ||tj | dS) Nr~rrrrrrrrrz-e)rr'r(r&rrrrr rrrrSrnrorrrrrWs"       z4CommandLineTestsBase.test_ignore_symlink_destinationcCs||jdddS)N-o 1--hardlink-dupes)rr&r:rrrtest_hardlink_bad_argspsz+CommandLineTestsBase.test_hardlink_bad_argsc CsdD]}t}|j|dt|dd}t|}gd}|rL|d|j|g|R|t |d|d||t |d|d ||t |d|d |Wdn1s0YWdq1s0YqdS) N)TFdeduprr)r"z-o 0rzz-o 2r{rrr) r$TemporaryDirectorysubTestrrrrrrdr )r4r~r'rpycsr rrr test_hardlinkus  z"CommandLineTestsBase.test_hardlinkN)6rrrr classmethodrrr rrrrr6rrr!r$namer,r1r3localsr5r6r7r=r@rrrBrCrFrGrJrOrTrWrarbrgrhriror_have_multiprocessingrsrrrvrrrr|rrrrrrsf            "          rc@s eZdZdS)CommandLineTestsWithSourceEpochNrrrrrrsrc@s eZdZdS)CommandLineTestsNoSourceEpochNrrrrrrsrc@seZdZddZejddZd#ddZdd d d d d ZddZ d$ddZ ddZ ddZ d%ddZ ddZddZddZddZd d!Zd"S)&HardlinkDedupTestsBasecCs d|_dSr7r{r:rrrr6szHardlinkDedupTestsBase.setUpccs>t"}||_|Vd|_Wdn1s00YdSr7)r$rr')r4r'rrrtemporary_directorys z*HardlinkDedupTestsBase.temporary_directoryrcCst|j||Sr7)rrr')r4coderrrrrsz"HardlinkDedupTestsBase.make_scriptTrF)r~rr\cCstj|jd|||ddS)NT)r]rhardlink_dupesr\)rTrgr')r4r~rr\rrrrgs z"HardlinkDedupTestsBase.compile_dirc Cs||d|t$tj|jddddWdn1sH0Y|t(tj|jdddgddWdn1s0YWdn1s0YdS)NpassTr)r]rr)rrrrrTrgr'r:rrr test_bad_argss    $ z$HardlinkDedupTestsBase.test_bad_argscCs4g}|r|d|d|r*|dd|S)Nz'module docstring'zx = 1z assert x == 1 )rr()r4 docstring assertionlinesrrr create_codes   z"HardlinkDedupTestsBase.create_codeccs2dD](}dD]}|j||d}|||fVq qdS)N)FTrr)r)r4rrrrrr iter_codessz!HardlinkDedupTestsBase.iter_codesc Cs|D]\}}}|j||d|v||}t|}|jdd|t|d|d|t|d|d|t|d|dWdn1s0YWdq1s0YqdS)NrFr}rrr)rrrrrrgror )r4rrrrrrrr test_disableds   z$HardlinkDedupTestsBase.test_disabledcCsft|}|t|d|d| |t|d|d| oB| |t|d|d| dS)Nrrr)rrdr )r4rrrrrrrcheck_hardlinkss z&HardlinkDedupTestsBase.check_hardlinksc Cs|D]\}}}|j||dX|0||}|||||Wdn1s`0YWdq1s~0YqdS)Nr)rrrrrgr)r4rrrrrrrrs   z$HardlinkDedupTestsBase.test_hardlinkc CsdD]}|j|d~|V||}|j|dt||d}t||d}|t||Wdn1sz0YWdq1s0YqdS)N))rr)rr)rr)optsrrr)rrrrrgrrSr )r4rrpyc1pyc2rrrtest_only_two_levelss  z+HardlinkDedupTestsBase.test_only_two_levelscCsn|R||}|jgddt|d}t|d}|t||Wdn1s`0YdS)N)rrrrrrr)rrrrgrrSr )r4rrrrrrtest_duplicated_levelss    z-HardlinkDedupTestsBase.test_duplicated_levelscCs||d}|||t|}t|dj}|d}|jddgdd||t|dj| t |d|d| |t|dj| t j|d|dddWdn1s0YdS) Nrrprint(0)rT)rr\rshallow)rrrgrrrrrrdrSr rfrofilecmpcmpr4rrinoderrrtest_recompilations    z)HardlinkDedupTestsBase.test_recompilationcCs||j|dd}|||t|}t|dj}|jddd}t j dddd|j d | |t|dj| |t|d j| t|d |d | tj|d |d d d Wdn1s0YdS)Nmodule)rrrr&z-cz import moduleF)rQrrrTr)rrrrgrrrrrrr r'rdror rrrrrr test_imports   z"HardlinkDedupTestsBase.test_importN)r)FF)FF)rrrr6rOcontextmanagerrrrgrrrrrrrrrrrrrrrs       rc@s eZdZdS)!HardlinkDedupTestsWithSourceEpochNrrrrrr7src@s eZdZdS)HardlinkDedupTestsNoSourceEpochNrrrrrr>sr__main__).rTrOrimportlib.utilr rQ itertoolsrrsrbr/rErr$Ztest.test_importlib.utilr~rr`rrconcurrent.futuresrr ImportErrorrZ test.supportrZtest_py_compilerr rrr r!ZTestCaserrrrrrrrrrrurrrrs       n  K