Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_compileall.cpython-38.pyc
U

>��g�j�@s�ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddl
mZmZzddlmZdZWnek
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�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Ze�d�dd��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�W5QRXtj�|jd�|_
tj�	|j
�|_t�|j|j
�tj�|jd�|_t�|j�tj�|jd�|_t�|j|j�dS)N�_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�shutil�copyfileZsubdirectory�mkdir�source_path3��self�file�r#�3/opt/cppython/lib/python3.8/test/test_compileall.py�setUps
zCompileallTestsBase.setUpcCst�|j�dS�N�r�rmtreer�r!r#r#r$�tearDown-szCompileallTestsBase.tearDownc	Cs8tj�|jd�|_t|jd��}|�d�W5QRXdS)Nz_test_bad.pyrzx (
)rrrr�bad_source_pathrrr r#r#r$�add_bad_source_file0sz'CompileallTestsBase.add_bad_source_filec	CsPt|jd��}|�d�}W5QRXtt�|j�j�}t�	dt
jjd|�}||fS)N�rb��<4sllr)
rr�read�intr�statr�st_mtime�struct�packrr�MAGIC_NUMBER)r!r"�data�mtimeZcomparer#r#r$�timestamp_metadata5s
z&CompileallTestsBase.timestamp_metadatac	Cs�tj�d�rt�d��t�|j�|j|�	��t
|jd��}|��t
|�d�}W5QRXt
|jd��}|�|�|�|�W5QRX|j|�	��tj|jddd�|j|�	��dS)	zOCheck that compileall recreates bytecode when the new metadata is
        used.�SOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setr-N�wbFT��force�quiet)r�environ�get�unittest�SkipTest�
py_compile�compiler�assertEqualr9rrr0�lenr�assertNotEqual�
compileall�compile_dirr�
assertTrue)r!Zmetadatar"Zbcr#r#r$�recreation_check<s

z$CompileallTestsBase.recreation_checkcCs|�t�dtjjdd��dS)Nr/rr)rKr4r5rrr6r)r#r#r$�
test_mtimeLs�zCompileallTestsBase.test_mtimecCs|�d�dS)Ns)rKr)r#r#r$�test_magic_numberQsz%CompileallTestsBase.test_magic_numbercCs|j|jfD] }zt�|�WqYqXq|�tj|jddd��|�tj�	|j�oftj�	|j��t�|j�|�tj
|jddd��|�tj�	|j�o�tj�	|j��t�|j�t�|j�|��|�
tj|jddd��|�
tj
|jddd��dS)NFTr<�)rrr�unlinkrJrH�compile_filerr�isfilerIrr,�assertFalser+)r!�fnr#r#r$�test_compile_filesUs<������z&CompileallTestsBase.test_compile_filesc	Csh|�tj�|j��t���}|�t�	t
�|j���W5QRX|�
|��d�|�tj�|j��dS)Nz&Compiling ([^WindowsPath|PosixPath].*))rRrrrQrr�captured_stdoutrJrHrP�pathlib�Pathr�assertRegex�getvalue)r!�stdoutr#r#r$�test_compile_file_pathlikens

"z.CompileallTestsBase.test_compile_file_pathlikecCsP|�tj�|j��|�tjt�	|j
�t�	d�dd��|�tj�|j��dS)NZ	ddir_pathrN)�ddirr>)rRrrrQrrJrHrPrVrWrr)r#r#r$�test_compile_file_pathlike_ddirvs�z3CompileallTestsBase.test_compile_file_pathlike_ddirc	Csttjjj|jgd��|�tjdd��W5QRXtjjj|jgd��$|��|�	tjdddd��W5QRXdS)N)rrN�r>FT)�skip_curdirr=r>)
�test�test_importlibrZimport_staterrJrH�compile_pathr,rRr)r#r#r$�test_compile_path}s
�z%CompileallTestsBase.test_compile_pathc	Cshtj�|jd�}tj�|d�}t�|�t|d��W5QRXt�|�|�tj�	tj�|d���dS)Nr7r"r�__pycache__)
rrrrrrrHrPrR�exists)r!Zdata_dirZ	data_filer#r#r$�test_no_pycache_in_non_package�s


z2CompileallTestsBase.test_no_pycache_in_non_packagecCs�dnd\}}tj|jd|d�tjj|j|d�}|�tj	�
|��tjj|j|d�}|�tj	�
|��tjj|j|d�}|�tj	�
|��dS)NT)rr)r�)r>�optimize)�optimization)
rHrIrrrrrrJrrrQrr)r!rh�opt�cachedZcached2Zcached3r#r#r$�
test_optimize�s
�
�
�z!CompileallTestsBase.test_optimizec	Csn|�tj�|j��t���}t�t	�
|j��W5QRX|���
�d}|�|d�|�tj�|j��dS)Nrz$Listing ([^WindowsPath|PosixPath].*))rRrrrQrrrUrHrIrVrWrrY�
splitlinesrXrJ)r!rZ�liner#r#r$�test_compile_dir_pathlike�s
z-CompileallTestsBase.test_compile_dir_pathlikez&concurrent.futures.ProcessPoolExecutorcCs"tj|jddd�|�|j�dS�NT��r>�workers�rHrIrrJ�called�r!�	pool_mockr#r#r$�test_compile_pool_called�sz,CompileallTestsBase.test_compile_pool_calledc	Cs,|�td��tj|jdd�W5QRXdS)Nz%workers must be greater or equal to 0���)rs)ZassertRaisesRegex�
ValueErrorrHrIrr)r#r#r$�!test_compile_workers_non_positive�s�z5CompileallTestsBase.test_compile_workers_non_positivecCs,tj|jddd�|�|jddd�dS)NTrrrr�max_workers)rHrIrrE�	call_argsrvr#r#r$�test_compile_workers_cpu_count�sz2CompileallTestsBase.test_compile_workers_cpu_countzcompileall.compile_filecCs,tj|jdd�|�|j�|�|j�dS)NTr^)rHrIrrRrurJ)r!�compile_file_mockrwr#r#r$�test_compile_one_worker�sz+CompileallTestsBase.test_compile_one_workerN��newcCs"tj|jddd�|�|j�dSrprt)r!rr#r#r$�$test_compile_missing_multiprocessing�sz8CompileallTestsBase.test_compile_missing_multiprocessing)�__name__�
__module__�__qualname__r%r*r,r9rKrLrMrTr[r]rcrfrlror�patchrxr{r~r�r�r#r#r#r$r
s2	

r
c@seZdZdS)�CompileallTestsWithSourceEpochN�r�r�r�r#r#r#r$r��sr�)�	metaclassZsource_date_epochc@seZdZdS)�!CompileallTestsWithoutSourceEpochNr�r#r#r#r$r��sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.c	CsPt��|_tj�|jd�|_t|jddd��}|�d�|�d�W5QRXdS)Nrrzutf-8��encodingz# -*- coding: utf-8 -*-
u
print u"€"
)	r
rrrrrrrrr r#r#r$r%�s


zEncodingTest.setUpcCst�|j�dSr&r'r)r#r#r$r*�szEncodingTest.tearDowncCs8z*tj}tjt��dd�t_t�|j�W5|t_XdS)N�asciir�)�sysrZ�io�
TextIOWrapper�BytesIOrHrIr)r!Zorig_stdoutr#r#r$�
test_error�s
zEncodingTest.test_errorN)r�r�r��__doc__r%r*r�r#r#r#r$r��sr�c@s�eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
edd��Zdd�ZddgfdddgfdddgffD]&\ZZZeefd d!�Zee�d"e<q�d#d$�Zd%d&�Zed'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAdB�Z%dCdD�Z&dEdF�Z'e(e)dG�dHdI��Z*e+�,dJ�dKdL��Z-dMdN�dOdP�Z.dQdR�Z/dSdT�Z0dUdV�Z1dWdX�Z2dYS)Z�CommandLineTestsBasezTest compileall's CLI.cCs�ttjjtj�D]�}d}t�|�d}|d}z`z8|��sF|��d}|�
d��}|�d�W5QRXWn"tk
r�d}YW�q�YnXW5t�t	|��|r�|�
�Xqd}||_dS)NFrdztest.tryTrz# for test_compileall)�filterrr�isdirr�rVrWrrO�str�rmdir�is_dirrrr�OSError�_sys_path_writable)�clsrZdirectory_createdrr"Zsys_path_writabler#r#r$�
setUpClass�s$zCommandLineTestsBase.setUpClasscCs|jst�d��dS)Nz(not all entries on sys.path are writable)r�rArBr)r#r#r$�_skip_if_sys_path_not_writablesz3CommandLineTestsBase._skip_if_sys_path_not_writablecCst��d|�S)N�-S�-mrH)r�r�rH)rZ!optim_args_from_interpreter_flags)r!�argsr#r#r$�
_get_run_args	s��z"CommandLineTestsBase._get_run_argscOs(tj|�|�|�\}}}|�d|�|S)N�)r�assert_python_okr�rE�r!r�Zenv_vars�rc�out�errr#r#r$�assertRunOKs�
z CommandLineTestsBase.assertRunOKcOs"tj|�|�|�\}}}|||fSr&)r�assert_python_failurer�r�r#r#r$�assertRunNotOKs
�
z#CommandLineTestsBase.assertRunNotOKcCs"tj�|�}|�tj�|��dSr&)rrrrJrrre�r!rSrr#r#r$�assertCompiledsz#CommandLineTestsBase.assertCompiledcCs"tj�|�}|�tj�|��dSr&)rrrrRrrrer�r#r#r$�assertNotCompiledsz&CommandLineTestsBase.assertNotCompiledcCsrt��|_|�tj|j�tj�|jd�|_	t�
|j	�tj�|j	d�|_t�
|j	dd�|_t�
|j	dd�|_dS)N�foord�__init__rgZbar)r
rrZ
addCleanuprr(rrr�pkgdirr�pkgdir_cachedirr�make_script�initfn�barfnr)r#r#r$r%!s
zCommandLineTestsBase.setUpcCsL|��t�|jdd�}|j|jd�|�|�|�|j�|�|j�dS)N�bazrg�Z
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�rgr��<rN�-f)r�rr�rr�rrrr�utime�timer2r3rErG)r!r��pycpathr8�mtime2r#r#r$� test_no_args_respects_force_flag4sz5CommandLineTestsBase.test_no_args_respects_force_flagcCsR|��t�|jdd�|j|jd�}|�d|�|jd|jd�}|�d|�dS)Nr�rgr�sListing �-q)r�rr�rr��assertInZassertNotIn�r!Znoisyr>r#r#r$� test_no_args_respects_quiet_flagFsz5CommandLineTestsBase.test_no_args_respects_quiet_flagZnormal�pycrhz	opt-1.pycz-OZdoubleoptimizez	opt-2.pycz-OOcs~tj|ddd|jg�|�tj�|j��t�fdd�dD��}|�	tt�
|j��|�|��fdd�t�
|j�D��dS)	Nr�rHr�c3s|]}|�tjj��VqdSr&)�formatr��implementation�	cache_tag)�.0�base��extr#r$�	<genexpr>Zs�z)CommandLineTestsBase.f.<locals>.<genexpr>)z__init__.{}.{}z	bar.{}.{}csg|]}|���r|�qSr#)�endswith)r�rSr�r#r$�
<listcomp>^s
�z*CommandLineTestsBase.f.<locals>.<listcomp>)rr�r�rJrrrer��sortedrE�listdirrR)r!r��switch�expectedr#r�r$�fUs��zCommandLineTestsBase.fZtest_pep3147_paths_cCsP|�dd|j�|�tj�|j��tddddg�}|�tt�	|j��|�dS)Nz-br��__init__.pyz__init__.pyczbar.pyzbar.pyc)
r�r�rRrrrer�r�rEr�)r!r�r#r#r$�test_legacy_pathsbs�z&CommandLineTestsBase.test_legacy_pathscCs||�d|j�|�tj�|j��tj�|jd�}|�tj�|��|�d|j�|�tj�|j��|�tj�|��dS)Nr�rd)	r�r�rJrrrer�rrR)r!Z
cachecachedirr#r#r$�test_multiple_runslsz'CommandLineTestsBase.test_multiple_runscCs�|�d|j�tj�|j�}t�|t��dfd�t�	|�j
}|�d|j�t�	|�j
}|�||�|�dd|j�t�	|�j
}|�||�dS)Nr�r�rNr�)
r�r�rrrr�rr�r�r2r3rErG)r!r�r8r�r#r#r$�
test_forceyszCommandLineTestsBase.test_forcecCs�tj�|jd�}t�|�t�|dd�}t�|dd�}|�dd|j�|�|�|�	tj�
tj�|d���|�d|j�|�|�|�|�dS)N�spamr�rg�hamr�z-lrd)rrrr�rrr�r�r�rRrer�)r!�
subpackage�	subinitfn�hamfnr#r#r$�test_recursion_control�s


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)
Nr�r�Zeggsr�rgZeggr�z-r 0rdz-r 1z-r 2z-r 5)rrrr�rZmake_pkgr�r�r�rRrer�)	r!r�Zsubpackage2Zsubpackage3Zpkgr�r�ZspamfnZeggfnr#r#r$�test_recursion_limit�s8
�









z)CommandLineTestsBase.test_recursion_limitcCs6|�|j�}|�d|j�}|�d|�|�d|�dS)Nr�r�)r�r�rGrEr�r#r#r$�
test_quiet�szCommandLineTestsBase.test_quietcCsTt�|jdd�|�d|j�\}}}|�d|j�\}}}|�d|�|�d|�dS)N�crunchyfrog�
bad(syntaxr�z-qqr�)rr�r�r�rGrE)r!�_r>Zsilentr#r#r$�test_silent�s
z CommandLineTestsBase.test_silentcCs.|�ddd|j�|�|j�|�|j�dS)Nr�z-xz
ba[^\\/]*$)r�r�r�r�r�r�r)r#r#r$�test_regexp�sz CommandLineTestsBase.test_regexpcCsvtj�|jd�}t�|�t�|dd�}t�|dd�}|�d|j|�|�	|j
�|�	|j�|�	|�|�	|�dS)NZfoo2r�rg�bar2r�)rrrrrrr�r�r�r�r�r�)r!Zpkgdir2Zinit2fn�bar2fnr#r#r$�test_multiple_dirs�s

z'CommandLineTestsBase.test_multiple_dirscCs8t�|jdd�|�ddd|j�\}}}|�|d�dS)Nr�r�r��-d�dinsdale�File "dinsdale)rr�r�r�rX�r!r�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 Exceptionr�r�r��bingz
import bazzbaz.pycF)Z
__isolatedr�)rr�r�r�rrrr�renamerr�remover�rX)r!r�rSr�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)N�-i�
nosuchfilesrror.*nosuchfiles	Traceback)r�rrrrr�rXZassertNotRegexrRrerrrr�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	�W5QRX|�
d
tj�|jd�|�|�|�|�|�|�|�|�|�dS)N�f1rg�f2�f3�f4�l1r�f1.py�f2.pyr�)
rr�r�rrrrrr�linesepr�r�r��r!r�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	�W5QRX|�
d	tj�|jd��|�|�|�|�|�|�|�|�dS)
Nr�rgr�r�r�r�rr�r�)
rr�r�rrrrrrr�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�rgr�r�r�r#r��-r�)
rr�r�Zspawn_pythonr��stdinrrr��encodeZkill_pythonr�r�)r!r�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�rXr�r�)r!Zbingfnr�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�rX)r!r�r#r#r$�!test_invalid_arg_produces_messages
z6CommandLineTestsBase.test_invalid_arg_produces_messagec	Cs�t�|jdd�tj�tj�|jd��}|�	d|j�t
|d��}|��}W5QRX|�t
�|dd�d�d	�|�	d
|j�t
|d��}|��}W5QRX|�t
�|dd�d�d�dS)Nr�rgr�z --invalidation-mode=checked-hashr-���little�z"--invalidation-mode=unchecked-hashr)rr�r�rrrrrrr�rr0rEr1�
from_bytes)r!r��fpr7r#r#r$�test_pyc_invalidation_mode s�z/CommandLineTestsBase.test_pyc_invalidation_modezrequires multiprocessingcCs�t�|jdd�}g}td�D]F}tj�|jd�|��}t�|�t�|dd�}|�	t�|dd��q|�
|jdd�|�|�|D]}|�|�q�dS)Nr�rgrqzfoo{}r�z-j�0)rr�r�rangerrrr�r�appendr�r�)r!r��files�suffixr�rSr"r#r#r$�test_workers-s

z!CommandLineTestsBase.test_workerszcompileall.compile_dirc	CsRtjdtj|jdgd��0t��|�|j�|�	|j
ddd�W5QRXdS)Nzsys.argvz-j0r�ryrsr)rr�r��
executablerrH�mainrJrurEr})r!rIr#r#r$�test_workers_available_cores<s�z1CommandLineTestsBase.test_workers_available_coresT)�parallelcCsddg}|j}g}|D]>}tj�||�}t�|�t�|dd�|�t�|dd��qtj	|jd||rjdnd	d
�|�
|�|D]�}|�
|�|j�|�tj
�|�}|t|jtj�d�}	t�|�\}
}
}tj�||	�}tjj
�|�}
|�|
j|�|�d|�d�t�|��q�dS)
z@Recursive compile_dir ddir must contain package paths; bpo39769.r`r�r�rg�modzdef fn(): 1/0
fn()
TrNr)r>r\rsN�")rrrrrrr�rrHrIrJ�
startswithrrrrF�sepr�r`raZ_get_code_from_pycrE�co_filenamer��fsdecode)r!r\r�fullpathrZmodsZsubdirrZmodcode�modpathr�r�Zexpected_inZmod_code_objr#r#r$�_test_ddir_onlyDs4
�
�
z$CommandLineTestsBase._test_ddir_onlycCs|jddd�S)�=Recursive compile_dir ddir= contains package paths; bpo39769.�
<a prefix>F�r\r�r"r)r#r#r$�test_ddir_only_one_worker]sz.CommandLineTestsBase.test_ddir_only_one_workercCs|jddd�S)r#r$Tr%r&r)r#r#r$�test_ddir_multiple_workersasz/CommandLineTestsBase.test_ddir_multiple_workerscCs|jddd�S)�?Recursive compile_dir ddir='' contains package paths; bpo39769.rgFr%r&r)r#r#r$�test_ddir_empty_only_one_workeresz4CommandLineTestsBase.test_ddir_empty_only_one_workercCs|jddd�S)r)rgTr%r&r)r#r#r$� test_ddir_empty_multiple_workersisz5CommandLineTestsBase.test_ddir_empty_multiple_workersN)3r�r�r�r��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�rrrrrrr�_have_multiprocessingrrr�rr"r'r(r*r+r#r#r#r$r��s`

	


�


"


	


r�c@seZdZdS)� CommmandLineTestsWithSourceEpochNr�r#r#r#r$r0nsr0c@seZdZdS)�CommmandLineTestsNoSourceEpochNr�r#r#r#r$r1usr1�__main__)%r�rH�importlib.utilrZtest.test_importlib.utilr`rrVrCrr4r
r�rAr�rr�concurrent.futuresrr/�ImportErrorrZtest.supportrZtest_py_compilerr	r
ZTestCaser�r�r�r�r0r1r�rr#r#r#r$�<module>sf
*����


F1le Man4ger