HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_compileall.cpython-37.opt-2.pyc
B

��gk�@s�ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddl
mZmZyddlmZdZWnek
r�dZYnXddlmZddlmZdd	lmZdd
lmZGdd�d�ZGd
d�dee
jedd�ZGdd�dee
jedd�ZGdd�de
j�ZGdd�d�Z Gdd�de e
jedd�Z!Gdd�de e
jedd�Z"e#dk�r~e
�$�dS)�N)�mock�
skipUnless)�ProcessPoolExecutorTF)�support)�
script_helper�)�without_source_date_epoch)�SourceDateEpochTestMetac@s�eZdZdd�Zdd�Zdd�Zdd�Ze�e	e
d	�d
�dd��Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�d�d d!��Zd"d#�Ze�d�d$d%��Ze�d�e�d&�d'd(���Zejdd)d*�e�d&�d+d,���Zd)S)-�CompileallTestsBasec	Cs�t��|_tj�|jd�|_tj�	|j�|_
t|jd��}|�d�WdQRXtj�|jd�|_
tj�	|j
�|_t�|j|j
�tj�|jd�|_t�|j�tj�|jd�|_t�|j|j�dS)Nz_test.py�wzx = 123
z	_test2.pyZ_subdirz	_test3.py)�tempfile�mkdtemp�	directory�os�path�join�source_path�	importlib�util�cache_from_source�bc_path�open�write�source_path2�bc_path2�shutilZcopyfileZsubdirectory�mkdir�source_path3)�self�file�r �0/usr/local/lib/python3.7/test/test_compileall.py�setUps
zCompileallTestsBase.setUpcCst�|j�dS)N)r�rmtreer)rr r r!�tearDown-szCompileallTestsBase.tearDownc	Cs8tj�|jd�|_t|jd��}|�d�WdQRXdS)Nz_test_bad.pyrzx (
)rrrr�bad_source_pathrr)rrr r r!�add_bad_source_file0sz'CompileallTestsBase.add_bad_source_filec	CsPt|jd��}|�d�}WdQRXtt�|j�j�}t�	dt
jjd|�}||fS)N�rb�z<4sllr)
rr�read�intr�statr�st_mtime�struct�packrr�MAGIC_NUMBER)rr�data�mtimeZcomparer r r!�timestamp_metadata5s
z&CompileallTestsBase.timestamp_metadatar+ztest needs os.stat()c	Cs�tj�d�rt�d��t�|j�|j|�	��t
|jd��}|��t
|�d�}WdQRXt
|jd��}|�|�|�|�WdQRX|j|�	��tj|jddd�|j|�	��dS)N�SOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setr'�wbFT)�force�quiet)r�environ�get�unittest�SkipTest�
py_compile�compiler�assertEqualr2rrr)�lenr�assertNotEqual�
compileall�compile_dirr�
assertTrue)rZmetadatarZbcr r r!�recreation_check<s

z$CompileallTestsBase.recreation_checkcCs|�t�dtjjdd��dS)Nz<4sllrr)rCr-r.rrr/)rr r r!�
test_mtimeMszCompileallTestsBase.test_mtimecCs|�d�dS)Ns)rC)rr r r!�test_magic_numberRsz%CompileallTestsBase.test_magic_numbercCsx0|j|jfD] }yt�|�WqYqXqW|�tj|jddd��|�tj�	|j�ojtj�	|j��t�|j�|�tj
|jddd��|�tj�	|j�o�tj�	|j��t�|j�t�|j�|��|�
tj|jddd��|�
tj
|jddd��dS)NFT)r5r6�)rrr�unlinkrBr@�compile_filerr�isfilerArr&�assertFalser%)r�fnr r r!�test_compile_filesVs*

z&CompileallTestsBase.test_compile_filesc	Csh|�tj�|j��t���}|�t�	t
�|j���WdQRX|�
|��d�|�tj�|j��dS)Nz&Compiling ([^WindowsPath|PosixPath].*))rJrrrIrr�captured_stdoutrBr@rH�pathlib�Pathr�assertRegex�getvalue)r�stdoutr r r!�test_compile_file_pathlikeos

"z.CompileallTestsBase.test_compile_file_pathlikecCsP|�tj�|j��|�tjt�	|j
�t�	d�dd��|�tj�|j��dS)NZ	ddir_pathrF)�ddirr6)rJrrrIrrBr@rHrNrOr)rr r r!�test_compile_file_pathlike_ddirws

z3CompileallTestsBase.test_compile_file_pathlike_ddirc	Csttjjj|jgd��|�tjdd��WdQRXtjjj|jgd��$|��|�	tjdddd��WdQRXdS)N)rrF)r6FT)�skip_curdirr5r6)
�test�test_importlibrZimport_staterrBr@�compile_pathr&rJ)rr r r!�test_compile_path~s
z%CompileallTestsBase.test_compile_pathc	Cshtj�|jd�}tj�|d�}t�|�t|d��WdQRXt�|�|�tj�	tj�|d���dS)Nr0rr�__pycache__)
rrrrrrr@rHrJ�exists)rZdata_dirZ	data_filer r r!�test_no_pycache_in_non_package�s


z2CompileallTestsBase.test_no_pycache_in_non_packagecCs�drdnd\}}tj|jd|d�tjj|j|d�}|�tj	�
|��tjj|j|d�}|�tj	�
|��tjj|j|d�}|�tj	�
|��dS)NF)rr)r�T)r6�optimize)�optimization)
r@rArrrrrrBrrrIrr)rr_�opt�cachedZcached2Zcached3r r r!�
test_optimize�s


z!CompileallTestsBase.test_optimizec	Csn|�tj�|j��t���}t�t	�
|j��WdQRX|���
�d}|�|d�|�tj�|j��dS)Nrz$Listing ([^WindowsPath|PosixPath].*))rJrrrIrrrMr@rArNrOrrQ�
splitlinesrPrB)rrR�liner r r!�test_compile_dir_pathlike�s
z-CompileallTestsBase.test_compile_dir_pathlikez&concurrent.futures.ProcessPoolExecutorcCs"tj|jddd�|�|j�dS)NT�)r6�workers)r@rArrB�called)r�	pool_mockr r r!�test_compile_pool_called�sz,CompileallTestsBase.test_compile_pool_calledc	Cs,|�td��tj|jdd�WdQRXdS)Nz%workers must be greater or equal to 0���)rh)ZassertRaisesRegex�
ValueErrorr@rAr)rr r r!�!test_compile_workers_non_positive�sz5CompileallTestsBase.test_compile_workers_non_positivecCs,tj|jddd�|�|jddd�dS)NTr)r6rhr�max_workers)r@rArr=�	call_args)rrjr r r!�test_compile_workers_cpu_count�sz2CompileallTestsBase.test_compile_workers_cpu_countzcompileall.compile_filecCs,tj|jdd�|�|j�|�|j�dS)NT)r6)r@rArrJrirB)r�compile_file_mockrjr r r!�test_compile_one_worker�sz+CompileallTestsBase.test_compile_one_workerN)�newcCs"tj|jddd�|�|j�dS)NTrg)r6rh)r@rArrBri)rrrr r r!�$test_compile_missing_multiprocessing�sz8CompileallTestsBase.test_compile_missing_multiprocessing)�__name__�
__module__�__qualname__r"r$r&r2r9r�hasattrrrCrDrErLrSrUrZr]rcrfr�patchrkrnrqrsrur r r r!r
s*	r
c@seZdZdS)�CompileallTestsWithSourceEpochN)rvrwrxr r r r!r{�sr{)�	metaclassZsource_date_epochc@seZdZdS)�!CompileallTestsWithoutSourceEpochN)rvrwrxr r r r!r}�sr}c@s$eZdZdd�Zdd�Zdd�ZdS)�EncodingTestc	CsPt��|_tj�|jd�|_t|jddd��}|�d�|�d�WdQRXdS)Nz_test.pyrzutf-8)�encodingz# -*- coding: utf-8 -*-
u
print u"€"
)	rr
rrrrrrr)rrr r r!r"�s


zEncodingTest.setUpcCst�|j�dS)N)rr#r)rr r r!r$�szEncodingTest.tearDowncCs8z*tj}tjt��dd�t_t�|j�Wd|t_XdS)N�ascii)r)�sysrR�io�
TextIOWrapper�BytesIOr@rAr)rZorig_stdoutr r r!�
test_error�s
zEncodingTest.test_errorN)rvrwrxr"r$r�r r r r!r~�sr~c@s�eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Ze
dd��Zdd�ZxJddgfdddgfdddgfgD]&\ZZZeefdd �Zee�d!e<q�Wd"d#�Zd$d%�Ze
d&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&e'e(dF�dGdH��Z)e*�+dI�dJdK��Z,dLdM�dNdO�Z-dPdQ�Z.dRdS�Z/dTdU�Z0dVdW�Z1dXS)Y�CommandLineTestsBasecCs�x�ttjjtj�D]�}d}t�|�d}|d}zXy8|��sH|��d}|�	d��}|�
d�WdQRXWntk
r�d}PYnXWdt�
t|��|r�|��XqWd}||_dS)NFr[ztest.tryTrz# for test_compileall)�filterrr�isdirr�rNrO�is_dirrrr�OSErrorrrG�str�rmdir�_sys_path_writable)�clsrZdirectory_createdrrZsys_path_writabler r r!�
setUpClass�s$zCommandLineTestsBase.setUpClasscCs|jst�d��dS)Nz(not all entries on sys.path are writable)r�r9r:)rr r r!�_skip_if_sys_path_not_writablesz3CommandLineTestsBase._skip_if_sys_path_not_writablecCst��d|�S)N�-S�-mr@)r�r�r@)rZ!optim_args_from_interpreter_flags)r�argsr r r!�
_get_run_args
sz"CommandLineTestsBase._get_run_argscOs(tj|�|�|�\}}}|�d|�|S)N�)r�assert_python_okr�r=)rr��env_vars�rc�out�errr r r!�assertRunOKsz CommandLineTestsBase.assertRunOKcOs"tj|�|�|�\}}}|||fS)N)r�assert_python_failurer�)rr�r�r�r�r�r r r!�assertRunNotOKsz#CommandLineTestsBase.assertRunNotOKcCs"tj�|�}|�tj�|��dS)N)rrrrBrrr\)rrKrr r r!�assertCompiledsz#CommandLineTestsBase.assertCompiledcCs"tj�|�}|�tj�|��dS)N)rrrrJrrr\)rrKrr r r!�assertNotCompiledsz&CommandLineTestsBase.assertNotCompiledcCsrt��|_|�tj|j�tj�|jd�|_	t�
|j	�tj�|j	d�|_t�
|j	dd�|_t�
|j	dd�|_dS)N�foor[�__init__r^Zbar)rr
rZ
addCleanuprr#rrr�pkgdirr�pkgdir_cachedirr�make_script�initfn�barfn)rr r r!r""s
zCommandLineTestsBase.setUpcCsL|��t�|jdd�}|j|jd�|�|�|�|j�|�|j�dS)N�bazr^)�
PYTHONPATH)	r�rr�rr�r�r�r�r�)r�bazfnr r r!�test_no_args_compiles_path,s
z/CommandLineTestsBase.test_no_args_compiles_pathcCs�|��t�|jdd�}|j|jd�tj�|�}t�	|t
�
�dfd�t�|�j}|j|jd�t�|�j}|�
||�|jd|jd�t�|�j}|�||�dS)Nr�r^)r��<rFz-f)r�rr�rr�rrrr�utime�timer+r,r=r?)rr��pycpathr1�mtime2r r r!� test_no_args_respects_force_flag5sz5CommandLineTestsBase.test_no_args_respects_force_flagcCsR|��t�|jdd�|j|jd�}|�d|�|jd|jd�}|�d|�dS)Nr�r^)r�sListing z-q)r�rr�rr��assertInZassertNotIn)r�noisyr6r r r!� test_no_args_respects_quiet_flagGsz5CommandLineTestsBase.test_no_args_respects_quiet_flagZnormal�pycr_z	opt-1.pycz-OZdoubleoptimizez	opt-2.pycz-OOcs~tj|ddd|jg�|�tj�|j��t�fdd�dD��}|�	tt�
|j��|�|��fdd�t�
|j�D��dS)	Nz-mr@z-qc3s|]}|�tjj��VqdS)N)�formatr��implementation�	cache_tag)�.0�base)�extr r!�	<genexpr>[sz)CommandLineTestsBase.f.<locals>.<genexpr>)z__init__.{}.{}z	bar.{}.{}csg|]}|���r|�qSr )�endswith)r�rK)r�r r!�
<listcomp>_sz*CommandLineTestsBase.f.<locals>.<listcomp>)rr�r�rBrrr\r��sortedr=�listdirrJ)rr��switch�expectedr )r�r!�fVs
zCommandLineTestsBase.fZtest_pep3147_paths_cCsP|�dd|j�|�tj�|j��tddddg�}|�tt�	|j��|�dS)Nz-bz-qz__init__.pyz__init__.pyczbar.pyzbar.pyc)
r�r�rJrrr\r�r�r=r�)rr�r r r!�test_legacy_pathscs
z&CommandLineTestsBase.test_legacy_pathscCs||�d|j�|�tj�|j��tj�|jd�}|�tj�|��|�d|j�|�tj�|j��|�tj�|��dS)Nz-qr[)	r�r�rBrrr\r�rrJ)rZ
cachecachedirr r r!�test_multiple_runsmsz'CommandLineTestsBase.test_multiple_runscCs�|�d|j�tj�|j�}t�|t��dfd�t�	|�j
}|�d|j�t�	|�j
}|�||�|�dd|j�t�	|�j
}|�||�dS)Nz-qr�rFz-f)
r�r�rrrr�rr�r�r+r,r=r?)rr�r1r�r r r!�
test_forcezszCommandLineTestsBase.test_forcecCs�tj�|jd�}t�|�t�|dd�}t�|dd�}|�dd|j�|�|�|�	tj�
tj�|d���|�d|j�|�|�|�|�dS)N�spamr�r^�hamz-qz-lr[)rrrr�rrr�r�r�rJr\r�)r�
subpackage�	subinitfn�hamfnr r r!�test_recursion_control�s


z+CommandLineTestsBase.test_recursion_controlc	CsZtj�|jd�}tj�|d�}tj�|d�}x|||fD]}t�|�q8Wtj�|d�}t�|dd�}t�|dd�}t�|dd�}|�dd|j�|�|�|�	tj�
tj�|d	���|�dd
|j�|�|�|�|�|�|�|�dd|j�|�|�|�|�|�|�|�|�|�dd|j�|�|�|�|�|�|�|�|�dS)
Nr�r�Zeggsz__init__.pyr^Zeggz-qz-r 0r[z-r 1z-r 2z-r 5)rrrr�rZmake_pkgr�r�r�rJr\r�)	rr�Zsubpackage2Zsubpackage3Zpkgr�r�ZspamfnZeggfnr r r!�test_recursion_limit�s6










z)CommandLineTestsBase.test_recursion_limitcCs6|�|j�}|�d|j�}|�d|�|�d|�dS)Nz-qr�)r�r�r?r=)rr�r6r r r!�
test_quiet�szCommandLineTestsBase.test_quietcCsTt�|jdd�|�d|j�\}}}|�d|j�\}}}|�d|�|�d|�dS)N�crunchyfrogz
bad(syntaxz-qz-qqr�)rr�r�r�r?r=)r�_r6Zsilentr r r!�test_silent�s
z CommandLineTestsBase.test_silentcCs.|�ddd|j�|�|j�|�|j�dS)Nz-qz-xz
ba[^\\/]*$)r�r�r�r�r�r�)rr r r!�test_regexp�sz CommandLineTestsBase.test_regexpcCsvtj�|jd�}t�|�t�|dd�}t�|dd�}|�d|j|�|�	|j
�|�	|j�|�	|�|�	|�dS)NZfoo2r�r^�bar2z-q)rrrrrrr�r�r�r�r�r�)rZpkgdir2Zinit2fn�bar2fnr r r!�test_multiple_dirs�s

z'CommandLineTestsBase.test_multiple_dirscCs8t�|jdd�|�ddd|j�\}}}|�|d�dS)Nr�z
bad(syntaxz-qz-d�dinsdalesFile "dinsdale)rr�r�r�rP)rr�r�r�r r r!�test_d_compile_error�sz)CommandLineTestsBase.test_d_compile_errorcCs�t�|jdd�}|�ddd|j�t�|jdd�}tj�|�}t�|tj	�
|jd��t�|�tj|d	d
�\}}}|�
|d�dS)Nr�zraise Exceptionz-qz-dr��bingz
import bazzbaz.pycF)Z
__isolatedsFile "dinsdale)rr�r�r�rrrr�renamerr�remover�rP)rr�rKr�r�r�r�r r r!�test_d_runtime_error�s
z)CommandLineTestsBase.test_d_runtime_errorcCsZ|�dtj�|jd�|j�\}}}|�|d�|�|d�|�tj�	t
j�|j
���dS)Nz-i�
nosuchfilesrror.*nosuchfiles	Traceback)r�rrrrr�rPZassertNotRegexrJr\rrrr�)rr�r�r�r r r!�test_include_bad_file�sz*CommandLineTestsBase.test_include_bad_filec	Cs�t�|jdd�}t�|jdd�}t�|jdd�}t�|jdd�}ttj�|jd�d��>}|�tj�|jd�tj	�|�tj�|jd	�tj	�WdQRX|�
d
tj�|jd�|�|�|�|�|�|�|�|�|�dS)N�f1r^�f2�f3�f4�l1rzf1.pyzf2.pyz-i)
rr�r�rrrrrr�linesepr�r�r�)rr�r�r�r�r�r r r!�test_include_file_with_arg�s&


z/CommandLineTestsBase.test_include_file_with_argc	Cs�t�|jdd�}t�|jdd�}t�|jdd�}t�|jdd�}ttj�|jd�d��"}|�tj�|jd�tj	�WdQRX|�
d	tj�|jd��|�|�|�|�|�|�|�|�dS)
Nr�r^r�r�r�r�rzf2.pyz-i)
rr�r�rrrrrrr�r�r�r�)rr�r�r�r�r�r r r!�test_include_file_no_arg�s&


z-CommandLineTestsBase.test_include_file_no_argcCs�t�|jdd�}t�|jdd�}t�|jdd�}t�|jdd�}tj|�d�ddg�}|j�|tj�	d	��t�
|�|�|�|�|�|�|�|�|�dS)
Nr�r^r�r�r�r z-i�-r�)
rr�r�Zspawn_pythonr��stdinrrr��encodeZkill_pythonr�r�)rr�r�r�r��pr r r!�test_include_on_stdins



z*CommandLineTestsBase.test_include_on_stdincCs\t�|jdd�}|�d|j||j�\}}}|�|d�|�|�|�|j�|�|j�dS)Nr�zsyntax(errorr�srror)	rr�r�r�r�r�rPr�r�)rZbingfnr�r�r�r r r!�!test_compiles_as_much_as_possibles

z6CommandLineTestsBase.test_compiles_as_much_as_possiblecCs|�d�}|�|d�dS)NZbadfilenamesCan't list 'badfilename')r�rP)rr�r r r!�!test_invalid_arg_produces_messages
z6CommandLineTestsBase.test_invalid_arg_produces_messagec	Cs�t�|jdd�tj�tj�|jd��}|�	d|j�t
|d��}|��}WdQRX|�t
�|dd�d�d	�|�	d
|j�t
|d��}|��}WdQRX|�t
�|dd�d�d�dS)Nr�r^zf1.pyz --invalidation-mode=checked-hashr'���little�z"--invalidation-mode=unchecked-hashr)rr�r�rrrrrrr�rr)r=r*�
from_bytes)rr��fpr0r r r!�test_pyc_invalidation_mode!sz/CommandLineTestsBase.test_pyc_invalidation_modezrequires multiprocessingcCs�t�|jdd�}g}xRtd�D]F}tj�|jd�|��}t�|�t�|dd�}|�	t�|dd��qW|�
|jdd�|�|�x|D]}|�|�q�WdS)Nr�r^rgzfoo{}r�z-j�0)rr�r�rangerrrr�r�appendr�r�)rr��files�suffixr�rKrr r r!�test_workers.s


z!CommandLineTestsBase.test_workerszcompileall.compile_dirc	CsRtjdtj|jdgd��0t��|�|j�|�	|j
ddd�WdQRXdS)Nzsys.argvz-j0)rtrlrh)rrzr��
executablerr@�mainrBrir=rp)rrAr r r!�test_workers_available_cores=s
z1CommandLineTestsBase.test_workers_available_coresT)�parallelcCsddg}|j}g}xF|D]>}tj�||�}t�|�t�|dd�|�t�|dd��qWtj	|jd||rndnd	d
�|�
|�x�|D]�}|�
|�|j�|�tj
�|�}|t|jtj�d�}	t�|�\}
}
}tj�||	�}tjj
�|�}
|�|
j|�|�d|�d�t�|��q�WdS)NrWr�r�r^�modzdef fn(): 1/0
fn()
TrFr)r6rTrh�")rrrrrrr�r�r@rArB�
startswithrrrr>�sepr�rWrXZ_get_code_from_pycr=�co_filenamer��fsdecode)rrTr�ZfullpathrZmodsZsubdirr�ZmodcodeZmodpathr�r�Zexpected_inZmod_code_objr r r!�_test_ddir_onlyEs,



z$CommandLineTestsBase._test_ddir_onlycCs|jddd�S)Nz
<a prefix>F)rTr�)r)rr r r!�test_ddir_only_one_worker^sz.CommandLineTestsBase.test_ddir_only_one_workercCs|jddd�S)Nz
<a prefix>T)rTr�)r)rr r r!�test_ddir_multiple_workersbsz/CommandLineTestsBase.test_ddir_multiple_workerscCs|jddd�S)Nr^F)rTr�)r)rr r r!�test_ddir_empty_only_one_workerfsz4CommandLineTestsBase.test_ddir_empty_only_one_workercCs|jddd�S)Nr^T)rTr�)r)rr r r!� test_ddir_empty_multiple_workersjsz5CommandLineTestsBase.test_ddir_empty_multiple_workersN)2rvrwrx�classmethodr�r�r�r�r�r�r�r"r�rr�r��namer�r�r��localsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�_have_multiprocessingr�rrzr�rrrrrr r r r!r��sT
	



"


	
r�c@seZdZdS)� CommmandLineTestsWithSourceEpochN)rvrwrxr r r r!rosrc@seZdZdS)�CommmandLineTestsNoSourceEpochN)rvrwrxr r r r!r
vsr
�__main__)%r�r@�importlib.utilrZtest.test_importlib.utilrWrrNr;rr-rr�r9r�rr�concurrent.futuresrr�ImportErrorrZtest.supportrZtest_py_compilerr	r
ZTestCaser{r}r~r�rr
rvr�r r r r!�<module>s^
+