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.10/test/__pycache__/test_compileall.cpython-310.opt-2.pyc
o

�i1��@sddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlZddlZddlmZmZddlmZz
ddlmZe�dZWneybdZYnwddlmZddlmZdd	lmZdd
lmZddlmZdd
�Z dd�Z!dd�Z"Gdd�d�Z#Gdd�de#ej$edd�Z%Gdd�de#ej$edd�Z&Gdd�dej$�Z'Gdd�d�Z(Gdd�de(ej$edd�Z)Gdd �d e(ej$edd�Z*Gd!d"�d"�Z+Gd#d$�d$e+ej$edd�Z,Gd%d&�d&e+ej$edd�Z-e.d'k�re�/�dSdS)(�N)�mock�
skipUnless)�ProcessPoolExecutor)�_check_system_limitsTF)�support)�	os_helper)�
script_helper)�without_source_date_epoch)�SourceDateEpochTestMetacCs|sd}tjj||d�S)N���optimization)�	importlib�util�cache_from_source)�script�opt�r�1/usr/local/lib/python3.10/test/test_compileall.py�get_pyc#srcs�fdd�dD�S)Ncsg|]}t�|��qSr)r)�.0r�rrr�
<listcomp>+szget_pycs.<locals>.<listcomp>�r��rrrrr�get_pycs*srcCs"	t�|�j}t�|�j}||kS�N)�os�stat�st_ino)Z	filename1�	filename2Zinode1Zinode2rrr�is_hardlink.sr"c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zeed+�e�d,�d-d.���Zd/d0�Zeed+�e�d,�d1d2���Zeed+�e�d,�e�d3�d4d5����Zejd,d6d7�e�d3�d8d9���Z d:d;�Z!d<d=�d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+e,j-dRdS��Z.d6S)T�CompileallTestsBasecCs�t��|_tj�|jd�|_tj�	|j�|_
t|jddd��
}|�d�Wd�n1s.wYtj�|jd�|_
tj�	|j
�|_t�|j|j
�tj�|jd�|_t�|j�tj�|jd�|_t�|j|j�dS)	N�_test.py�w�utf-8��encodingzx = 123
z	_test2.pyZ_subdirz	_test3.py)�tempfile�mkdtemp�	directoryr�path�join�source_pathrrr�bc_path�open�write�source_path2�bc_path2�shutil�copyfileZsubdirectory�mkdir�source_path3��self�filerrr�setUp7s
�zCompileallTestsBase.setUpcC�t�|j�dSr�r4�rmtreer+�r9rrr�tearDownE�zCompileallTestsBase.tearDowncCsRtj�|jd�|_t|jddd��}|�d�Wd�dS1s"wYdS)Nz_test_bad.pyr%r&r'zx (
)rr,r-r+�bad_source_pathr0r1r8rrr�add_bad_source_fileHs"�z'CompileallTestsBase.add_bad_source_filecCsht|jd��
}|�d�}Wd�n1swYtt�|j�j�}t�	dt
jjd|d@�}||fS)N�rb��<4sLLr���)
r0r/�read�intrrr.�st_mtime�struct�packrr�MAGIC_NUMBER)r9r:�data�mtimeZcomparerrr�timestamp_metadataMs��z&CompileallTestsBase.timestamp_metadatac	C�zz	t�|jd�Wnttfy|�d�Ynwt�t�	���|�
t�|j��Wd�dS1s6wYdS)N)rGrGz0filesystem doesn't support timestamps near 2**32�
r�utimer.�
OverflowError�OSErrorZskipTest�
contextlib�redirect_stdout�io�StringIO�
assertTrue�
compileall�compile_filer?rrr� test_year_2038_mtime_compilationU��"�z4CompileallTestsBase.test_year_2038_mtime_compilationc	CrQ)N)� r_z+filesystem doesn't support large timestampsrRr?rrr�test_larger_than_32_bit_times_r^z1CompileallTestsBase.test_larger_than_32_bit_timescCs�	tj�d�rt�d��t�|j�|j|�	��t
|jd��}|��t
|�d�}Wd�n1s4wYt
|jd��}|�|�|�|�Wd�n1sTwY|j|�	��tj|jddd�|j|�	��dS)N�SOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setrD�wbFT��force�quiet)r�environ�get�unittestZSkipTest�
py_compile�compiler.�assertEqualrPr0r/rH�lenr1�assertNotEqualr[�compile_dirr+rZ)r9Zmetadatar:�bcrrr�recreation_checkis
�
�z$CompileallTestsBase.recreation_checkcCs|�t�dtjjdd��dS)NrFrr)rprKrLrrrMr?rrr�
test_mtimeys
�zCompileallTestsBase.test_mtimecCs|�d�dS)Ns)rpr?rrr�test_magic_number~sz%CompileallTestsBase.test_magic_numbercCs|j|jfD]}zt�|�WqYq|�tj|jddd��|�tj�	|j�o1tj�	|j��t�|j�|�tj
|jddd��|�tj�	|j�oTtj�	|j��t�|j�t�|j�|��|�
tj|jddd��|�
tj
|jddd��dS)NFTrcr)r/r3r�unlinkrZr[r\r.r,�isfilernr+rC�assertFalserB)r9�fnrrr�test_compile_files�s6������z&CompileallTestsBase.test_compile_filescCs||�tj�|j��t���}|�t�	t
�|j���Wd�n1s%wY|�
|��d�|�tj�|j��dS)Nz&Compiling ([^WindowsPath|PosixPath].*))rurr,rtr/r�captured_stdoutrZr[r\�pathlib�Pathr.�assertRegex�getvalue)r9�stdoutrrr�test_compile_file_pathlike�s
�z.CompileallTestsBase.test_compile_file_pathlikecC�P|�tj�|j��|�tjt�	|j
�t�	d�dd��|�tj�|j��dS)NZ	ddir_pathr)�ddirre�rurr,rtr/rZr[r\ryrzr.r?rrr�test_compile_file_pathlike_ddir���z3CompileallTestsBase.test_compile_file_pathlike_ddircCr�NZ
stripdir_pathr)�stripdirrer�r?rrr�#test_compile_file_pathlike_stripdir�r�z7CompileallTestsBase.test_compile_file_pathlike_stripdircCr�NZprependdir_pathr)�
prependdirrer�r?rrr�%test_compile_file_pathlike_prependdir�r�z9CompileallTestsBase.test_compile_file_pathlike_prependdircCs�tjjj|jgd��|�tjdd��Wd�n1swYtjjj|jgd��|��|�	tjdddd��Wd�dS1sHwYdS)N�r,r�reFT)�skip_curdirrdre)
�test�test_importlibrZimport_stater+rZr[�compile_pathrCrur?rrr�test_compile_path�s�

�"�z%CompileallTestsBase.test_compile_pathcCs|tj�|jd�}tj�|d�}t�|�t|d��Wd�n1s$wYt�|�|�tj�	tj�|d���dS)NrNr:rb�__pycache__)
rr,r-r+r6r0r[r\ru�exists)r9Zdata_dirZ	data_filerrr�test_no_pycache_in_non_package�s
�
 z2CompileallTestsBase.test_no_pycache_in_non_packagecCsN|��t�t����|�t�|j��Wd�dS1s wYdSr)	rCrVrWrXrYrur[r\rBr?rrr�#test_compile_file_encoding_fallback�s"�z7CompileallTestsBase.test_compile_file_encoding_fallbackcCs�d\}}tj|jd|d�tjj|j|d�}|�tj	�
|��tjj|j|d�}|�tj	�
|��tjj|j|d�}|�tj	�
|��dS)NF)rr)rrT�re�optimizer)
r[rnr+rrrr.rZrr,rtr2r7)r9r�r�cachedZcached2Zcached3rrr�
test_optimize�s
�
�
�z!CompileallTestsBase.test_optimizecCs�|�tj�|j��t���}t�t	�
|j��Wd�n1s"wY|���
�d}|�|d�|�tj�|j��dS)Nrz$Listing ([^WindowsPath|PosixPath].*))rurr,rtr/rrxr[rnryrzr+r|�
splitlinesr{rZ)r9r}�linerrr�test_compile_dir_pathlike�s
�z-CompileallTestsBase.test_compile_dir_pathlikecCrr��rurr,rtr/rZr[rnryrzr+r?rrr�"test_compile_dir_pathlike_stripdir�r�z6CompileallTestsBase.test_compile_dir_pathlike_stripdircCrr�r�r?rrr�$test_compile_dir_pathlike_prependdir�r�z8CompileallTestsBase.test_compile_dir_pathlike_prependdir�requires multiprocessingz&concurrent.futures.ProcessPoolExecutorcC�"tj|jddd�|�|j�dS�NT��re�workers�r[rnr+rZ�called�r9�	pool_mockrrr�test_compile_pool_called��z,CompileallTestsBase.test_compile_pool_calledcCsB|�td��tj|jdd�Wd�dS1swYdS)Nz%workers must be greater or equal to 0���)r�)ZassertRaisesRegex�
ValueErrorr[rnr+r?rrr�!test_compile_workers_non_positives
�"�z5CompileallTestsBase.test_compile_workers_non_positivecCs,tj|jddd�|�|jddd�dS)NTrr�r�max_workers)r[rnr+rk�	call_argsr�rrr�test_compile_workers_cpu_countsz2CompileallTestsBase.test_compile_workers_cpu_countzcompileall.compile_filecCs,tj|jdd�|�|j�|�|j�dS)NTr�)r[rnr+rur�rZ)r9�compile_file_mockr�rrr�test_compile_one_workersz+CompileallTestsBase.test_compile_one_workerN��newcCr�r�r�)r9r�rrr�$test_compile_missing_multiprocessingr�z8CompileallTestsBase.test_compile_missing_multiprocessingcCs�d}|j}td|d�D]}tj�|d|���}tj�|d�}t�|�t�|j|�qt	j
�|�}tj
|jd|dd�|�tj�|��tj
|jd|d�|�tj�|��dS)N�rZdir_z	script.pyT)re�	maxlevels)r+�rangerr,r-r6r4r5r.rrrr[rnrurtrZ)r9�depthr,�i�sourceZpyc_filenamerrr�test_compile_dir_maxlevelss
z.CompileallTestsBase.test_compile_dir_maxlevelsT)�parallelcCs	ddg}|j}g}|D]}tj�||�}t�|�t�|dd�|�t�|dd��qtj	|jd||r6dnd	d
�|�
|�|D]H}|�
|�|j�|�tj
�|�}|t|jtj�d�}	t�|�\}
}
}tj�||	�}tjj
�|�}
|�|
j|�|�d|�d�t�|��qAdS)Nr��foo�__init__r�modzdef fn(): 1/0
fn()
Trr)rer�r��")r+rr,r-r6r�make_script�appendr[rnrZ�
startswithrrrrl�sep�assert_python_failurer�r�Zget_code_from_pycrk�co_filename�assertIn�fsdecode)r9r�r��fullpathr,ZmodsZsubdirr�Zmodcode�modpath�_�err�expected_inZmod_code_objrrr�_test_ddir_only*s4
�
�
�z#CompileallTestsBase._test_ddir_onlycC�	|jddd�S)N�
<a prefix>F�r�r��r�r?rrr�test_ddir_only_one_workerC�z-CompileallTestsBase.test_ddir_only_one_workercCr�)Nr�Tr�r�r?rrr�test_ddir_multiple_workersGr�z.CompileallTestsBase.test_ddir_multiple_workerscCr�)NrFr�r�r?rrr�test_ddir_empty_only_one_workerKr�z3CompileallTestsBase.test_ddir_empty_only_one_workercCr�)NrTr�r�r?rrr� test_ddir_empty_multiple_workersOr�z4CompileallTestsBase.test_ddir_empty_multiple_workersc
Cs�gd�}tjj|jg|�R�}t�|�t�|dd�}tj�	|�}tjj|jg|dd��R�}t
j|d|d�t�|�\}}}tjj|dd��}	|�
|	t|t��d��|�|t|t��d��dS)N�r��build�realr,r��1 / 0rT)rer�r'�rr,r-r+�makedirsrr�rrrr[rnr�r��str�sys�getdefaultencoding�assertNotIn)
r9r�r,rror��rc�outr�r�rrr�test_strip_onlySs"
��z#CompileallTestsBase.test_strip_onlyc
Cs�gd�}tjj|jg|�R�}t�|�t�|dd�}tj�	|�}d}t
j|d|d�t�|�\}}}tjj||jg|�R�}	|�
|	t|t��d��dS)Nr�r�r��/fooT)rer�r')rr,r-r+r�rr�rrrr[rnr�r�r�r�r�)
r9r�r,rror�r�r�r�r�rrr�test_prepend_onlyfs
�z%CompileallTestsBase.test_prepend_onlycCs�gd�}tjj|jg|�R�}t�|�t�|dd�}tj�	|�}tjj|jg|dd��R�}d}t
j|d||d�t�|�\}}}	tjj|g|dd��R�}
|�
|
t|	t��d��|�|t|	t��d��dS)	Nr�r�r�rr�T)rer�r�r'r��r9r�r,rror�r�r�r�r�r�rrr�test_strip_and_prependus(
���z*CompileallTestsBase.test_strip_and_prependcCszgd�}tjj|jg|�R�}t�|�t�|dd�|�t��t	j
|ddddd�Wd�dS1s6wYdS)N)r�r�r�r,r�r�r�Tz/barr�)rer�r�r�)rr,r-r+r�rr��assertRaisesr�r[rn)r9r�r,rrr�test_strip_prepend_and_ddir�s

�"�z/CompileallTestsBase.test_strip_prepend_and_ddirc
Cs�t�|jdd�}g}dD]
}|�tjj||d��qddgddgddggd�g}|D],}tj|d	|d
�|D]}|�	t
j�||��z	t
�
||�Wq6tyUYq6wq*dS)N�test_optimization�a = 0�rrrr�rrrrrTr�)rr�r+r�rrrr[r\rZrr,rtrs�	Exception)r9rro�	opt_level�test_combinations�opt_combinationrrr�!test_multiple_optimization_levels�s.�
�����z5CompileallTestsBase.test_multiple_optimization_levelsc
Cs�tj�|jddd�}tj�|jddd�}tj�|jddd�}t�|�t�|�t�|�t�|dd�}t�|dd�}tj�|d	�}tj�|d
�}t�||�t�||�tj	�
|�}tj	�
|�}	tj|d|d�|�
tj�|��|�tj�|	��dS)
Nr��dir�allowed�symlinks�
prohibited�test_allowedr��test_prohibited�test_allowed.py�test_prohibited.pyT)re�
limit_sl_dest)rr,r-r+r�rr��symlinkrrrr[rnrZrtru�
r9Zallowed_pathZ
symlinks_pathZprohibited_pathZallowed_scriptZprohibited_scriptZallowed_symlinkZprohibited_symlinkZ
allowed_bcZ
prohibited_bcrrr�test_ignore_symlink_destination�s"


z3CompileallTestsBase.test_ignore_symlink_destination)/�__name__�
__module__�__qualname__r;r@rCrPr]r`rprqrrrwr~r�r�r�r�r�r�r�r�r�r�r�_have_multiprocessingr�patchr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�skip_unless_symlinkr�rrrrr#5sb

	
	r#c@�eZdZdS)�CompileallTestsWithSourceEpochN�rrrrrrrr��r)�	metaclassZsource_date_epochc@r)�!CompileallTestsWithoutSourceEpochNrrrrrr�r	rc@s&eZdZ	dd�Zdd�Zdd�ZdS)�EncodingTestcCsft��|_tj�|jd�|_t|jddd��}|�d�|�d�Wd�dS1s,wYdS)Nr$r%r&r'z# -*- coding: utf-8 -*-
u
print u"€"
)	r)r*r+rr,r-r.r0r1r8rrrr;�s

"�zEncodingTest.setUpcCr<rr=r?rrrr@�rAzEncodingTest.tearDowncCs<ztj}tjt��dd�t_t�|j�W|t_dS|t_w)N�asciir')r�r}rX�
TextIOWrapper�BytesIOr[rnr+)r9Zorig_stdoutrrr�
test_error�s
zEncodingTest.test_errorN)rrrr;r@rrrrrr�s
rc@s�eZdZ	dd�Zejdd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Ze
dd��Zdd�ZddgfdddgfdddgffD]\ZZZeefdd�Zee�de<qBd d!�Zd"d#�Ze
d$d%��Zd&d'�Zd(d)�Zejd*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Z d4d5�Z!d6d7�Z"d8d9�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�Z0dNdO�Z1ejdPdQ��Z2dRdS�Z3dTdU�Z4dVS)W�CommandLineTestsBasecCsrt��|_|�tj|j�tj�|jd�|_	t�
|j	�tj�|j	d�|_t�
|j	dd�|_t�
|j	dd�|_dS)Nr�r�r�rZbar)r)r*r+Z
addCleanuprr>rr,r-�pkgdirr6�pkgdir_cachedirrr��initfn�barfnr?rrrr;�s
zCommandLineTestsBase.setUpccsD�	tj}tj�|jd�}z|t_|j|d�VW|t_dS|t_w)NZ
__testcache__)�
PYTHONPATHZPYTHONPYCACHEPREFIX)r��pycache_prefixrr,r-r+)r9Z
old_prefixZ
new_prefixrrr�temporary_pycache_prefix�s�
�z-CommandLineTestsBase.temporary_pycache_prefixcCsgt���d�d�d�|�S)Nz-S�-mr[)rZ!optim_args_from_interpreter_flags)r9�argsrrr�
_get_run_argss
����z"CommandLineTestsBase._get_run_argscOs4tj|�|�i|�ddi��\}}}|�d|�|S)N�PYTHONIOENCODINGr&�)r�assert_python_okrrk�r9rZenv_varsr�r�r�rrr�assertRunOKs���z CommandLineTestsBase.assertRunOKcOs.tj|�|�i|�ddi��\}}}|||fS)Nrr&)rr�rrrrr�assertRunNotOKs���
z#CommandLineTestsBase.assertRunNotOKcC�"tj�|�}|�tj�|��dSr)rrrrZrr,r��r9rvr,rrr�assertCompiled�z#CommandLineTestsBase.assertCompiledcCr"r)rrrrurr,r�r#rrr�assertNotCompiledr%z&CommandLineTestsBase.assertNotCompiledcCspt�|jdd�}|���"}|jdi|��|�|�|�|j�|�|j�Wd�dS1s1wYdS)N�bazrr)	rr�r+rr r$r&rr)r9�bazfn�envrrr�test_no_args_compiles_paths

"�z/CommandLineTestsBase.test_no_args_compiles_pathcCs�t�|jdd�}|���}|jdi|��tj�|�}Wd�n1s%wYt�	|t
�
�dfd�t�|�j}|jdi|��t�|�j}|�
||�|jdi|��t�|�j}|�||�dS)Nr'r�<r�-fr)r,)rr�r+rr rrrrrS�timerrJrkrm)r9r(r)�pycpathrO�mtime2rrr� test_no_args_respects_force_flag#s
�z5CommandLineTestsBase.test_no_args_respects_force_flagcCstt�|jdd�|���}|jdi|��}Wd�n1swY|�d|�|jdi|��}|�d|�dS)Nr'rsListing �-qr)r1)rr�r+rr r�r�)r9r)�noisyrerrr� test_no_args_respects_quiet_flag5s
�z5CommandLineTestsBase.test_no_args_respects_quiet_flagZnormal�pycr�z	opt-1.pyc�-OZdoubleoptimizez	opt-2.pycz-OOcs~tj|ddd|jg�|�tj�|j��t�fdd�dD��}|�	tt�
|j��|�|��fdd�t�
|j�D��dS)	Nrr[r1c3s �|]}|�tjj��VqdSr)�formatr��implementation�	cache_tag)r�base��extrr�	<genexpr>Is��z)CommandLineTestsBase.f.<locals>.<genexpr>)z__init__.{}.{}z	bar.{}.{}csg|]	}|���r|�qSr)�endswith)rrvr:rrrMs
�z*CommandLineTestsBase.f.<locals>.<listcomp>)rrrrZrr,r�r�sortedrk�listdirru)r9r;�switch�expectedrr:r�fDs��$zCommandLineTestsBase.fZtest_pep3147_paths_cCsL|�dd|j�|�tj�|j��tgd��}|�tt�	|j��|�dS)Nz-br1)�__init__.pyz__init__.pyczbar.pyzbar.pyc)
r rrurr,r�rr>rkr?)r9rArrr�test_legacy_pathsQsz&CommandLineTestsBase.test_legacy_pathscCs||�d|j�|�tj�|j��tj�|jd�}|�tj�|��|�d|j�|�tj�|j��|�tj�|��dS)Nr1r�)	r rrZrr,r�rr-ru)r9Z
cachecachedirrrr�test_multiple_runs[sz'CommandLineTestsBase.test_multiple_runscCs�|�d|j�tj�|j�}t�|t��dfd�t�	|�j
}|�d|j�t�	|�j
}|�||�|�dd|j�t�	|�j
}|�||�dS)Nr1r+rr,)
r rrrrrrrSr-rrJrkrm)r9r.rOr/rrr�
test_forcehszCommandLineTestsBase.test_forcecCs�tj�|jd�}t�|�t�|dd�}t�|dd�}|�dd|j�|�|�|�	tj�
tj�|d���|�d|j�|�|�|�|�dS)N�spamr�r�hamr1z-lr�)rr,r-rr6rr�r r&rur�r$)r9�
subpackage�	subinitfn�hamfnrrr�test_recursion_controlxs


z+CommandLineTestsBase.test_recursion_controlc	CsVtj�|jd�}tj�|d�}tj�|d�}|||fD]}t�|�qtj�|d�}t�|dd�}t�|dd�}t�|dd�}|�dd|j�|�|�|�	tj�
tj�|d	���|�dd
|j�|�|�|�|�|�|�|�dd|j�|�|�|�|�|�|�|�|�|�dd|j�|�|�|�|�|�|�|�|�dS)
NrGrHZeggsrCrZeggr1z-r 0r�z-r 1z-r 2z-r 5)rr,r-rr�make_pkgr�r r&rur�r$)	r9rIZsubpackage2Zsubpackage3�pkgrJrKZspamfnZeggfnrrr�test_recursion_limit�s8
�









z)CommandLineTestsBase.test_recursion_limitc	Csttj�|jd�}t�|�t�dtj�|d��t�dtj�|d��|�d|j�|�tj�|jdddd��dS)NrG�.ZevilZevil2r1rC)	rr,r-rrrMr�r r$)r9rNrrr�test_symlink_loop�s


�z&CommandLineTestsBase.test_symlink_loopcCs6|�|j�}|�d|j�}|�d|�|�d|�dS)Nr1r)r rrmrk)r9r2rerrr�
test_quiet�szCommandLineTestsBase.test_quietcCsTt�|jdd�|�d|j�\}}}|�d|j�\}}}|�d|�|�d|�dS)N�crunchyfrog�
bad(syntaxr1z-qqr)rr�rr!rmrk)r9r�reZsilentrrr�test_silent�s
z CommandLineTestsBase.test_silentcCs.|�ddd|j�|�|j�|�|j�dS)Nr1z-xz
ba[^\\/]*$)r rr&rr$rr?rrr�test_regexp�sz CommandLineTestsBase.test_regexpcCsvtj�|jd�}t�|�t�|dd�}t�|dd�}|�d|j|�|�	|j
�|�	|j�|�	|�|�	|�dS)NZfoo2r�r�bar2r1)rr,r-r+r6rr�r rr$rr)r9Zpkgdir2Zinit2fn�bar2fnrrr�test_multiple_dirs�s

z'CommandLineTestsBase.test_multiple_dirscCs8t�|jdd�|�ddd|j�\}}}|�|d�dS)NrSrTr1�-d�dinsdale�File "dinsdale)rr�rr!r{�r9r�r�r�rrr�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 Exceptionr1rZr[�bingz
import bazzbaz.pycF)�
__isolatedr\)rr�rr rrrr�renamer,r-�remover�r{)r9r(rvr4r�r�r�rrr�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!rr,r-r+rr{ZassertNotRegexrur�rrrrr]rrr�test_include_bad_file�s
��z*CommandLineTestsBase.test_include_bad_filecCs�t�|jdd�}t�|jdd�}t�|jdd�}t�|jdd�}ttj�|jd�ddd	��$}|�tj�|jd
�tj	�|�tj�|jd�tj	�Wd�n1sTwY|�
dtj�|jd�|�|�|�|�|�|�|�|�|�dS)
N�f1r�f2�f3�f4�l1r%r&r'�f1.py�f2.pyrd)
rr�rr0rr,r-r+r1�linesepr r$r&�r9rgrhrirjrkrrr�test_include_file_with_arg�s�


z/CommandLineTestsBase.test_include_file_with_argcCs�t�|jdd�}t�|jdd�}t�|jdd�}t�|jdd�}ttj�|jd�ddd	��}|�tj�|jd
�tj	�Wd�n1sFwY|�
dtj�|jd��|�|�|�|�|�|�|�|�dS)Nrgrrhrirjrkr%r&r'rmrd)
rr�rr0rr,r-r+r1rnr r&r$rorrr�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)
Nrgrrhrirjrrd�-r
)
rr�rZspawn_pythonr�stdinr1rrn�encodeZkill_pythonr&r$)r9rgrhrirj�prrr�test_include_on_stdins



z*CommandLineTestsBase.test_include_on_stdincCs\t�|jdd�}|�d|j||j�\}}}|�|d�|�|�|�|j�|�|j�dS)Nr_zsyntax(errorresrror)	rr�rr!rrr{r&r$)r9Zbingfnr�r�r�rrr�!test_compiles_as_much_as_possibles

�
z6CommandLineTestsBase.test_compiles_as_much_as_possiblecCs|�d�}|�|d�dS)NZbadfilenamesCan't list 'badfilename')r r{)r9r�rrr�!test_invalid_arg_produces_messages
z6CommandLineTestsBase.test_invalid_arg_produces_messagecCs�t�|jdd�tj�tj�|jd��}|�	d|j�t
|d��}|��}Wd�n1s/wY|�t
�|dd�d�d	�|�	d
|j�t
|d��}|��}Wd�n1s]wY|�t
�|dd�d�d�dS)Nrgrrlz --invalidation-mode=checked-hashrD���littler�z"--invalidation-mode=unchecked-hashr)rr�rrrrrr,r-r r0rHrkrI�
from_bytes)r9r4�fprNrrr�test_pyc_invalidation_modes�
�
� z/CommandLineTestsBase.test_pyc_invalidation_moder�cCs�t�|jdd�}g}td�D]#}tj�|jd�|��}t�|�t�|dd�}|�	t�|dd��q|�
|jdd�|�|�|D]}|�|�qAdS)NrWrr�zfoo{}r�z-j�0)rr�r+r�rr,r-r6r6r�r r$)r9rX�files�suffixrrvr:rrr�test_workers*s

�z!CommandLineTestsBase.test_workerszcompileall.compile_dircCshtjdtj|jdgd��t��|�|j�|�	|j
ddd�Wd�dS1s-wYdS)Nzsys.argvz-j0r�r�r�r)rrr��
executabler+r[�mainrZr�rkr�)r9rnrrr�test_workers_available_cores9s�"�z1CommandLineTestsBase.test_workers_available_corescCs�gd�}tjj|jg|�R�}t�|�t�|dd�}tj�	|�}tjj|jg|dd��R�}d}|�
d|d||�t�|�\}}}	tjj|g|dd��R�}
|�|
t
|	t��d��|�|t
|	t��d��dS)	Nr�r�r�rr�z-sz-pr')rr,r-r+r�rr�rrrr r�r�r�r�r�r�r�rrrr�As$
��z+CommandLineTestsBase.test_strip_and_prependc
Cs�tj�|jd�}t�|�t�|dd�}g}dD]
}|�tj	j
||d��qddgddgddggd	�g}|D]4}|j|gd
d�|D��R�|D]!}|�tj�
|t|���z	t�||�WqHtyiYqHwq6dS)NZ
optimizationsr�r�r�rr�1�2)rr�r�css�|]	}dt|�VqdS)z-oN)r�)r�nrrrr<ds�zICommandLineTestsBase.test_multiple_optimization_levels.<locals>.<genexpr>)rr,r-r+r�rr�r�rrrr rZrtrIrsr�)r9r,rror�r�r�rrrr�Us6
�
�����z6CommandLineTestsBase.test_multiple_optimization_levelsc
Cs�tj�|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�r�r�r�r�r�r�r�r�r�z-e)rr,r-r+r�rr�r�rrrr rZrtrur�rrrr�ls"


z4CommandLineTestsBase.test_ignore_symlink_destinationcCs|�|jdd�dS)N�-o 1�--hardlink-dupes)r!r+r?rrr�test_hardlink_bad_args�sz+CommandLineTestsBase.test_hardlink_bad_argsc
Cs�dD]r}t���d}|j|d��Nt�|dd�}t|�}gd�}|r&|�d�|j|g|�R�|�t	|d|d�|�|�t	|d|d	�|�|�t	|d|d	�|�Wd�n1s`wYWd�n1sowYqdS)
N)TF��deduprr�)r1z-o 0r�z-o 2r�rrr)
r)�TemporaryDirectory�subTestrr�rr�r rkr")r9r�r,r�pycsrrrr�
test_hardlink�s"

�����z"CommandLineTestsBase.test_hardlinkN)5rrrr;rV�contextmanagerrrr r!r$r&r*r	r0r3�namer;r@rB�localsrDrErFrLrOrrrQrRrUrVrYr^rcrfrprqrvrwrxr~rrr�rrr�r�r�r�r�r�rrrrr�sf


	


�

"




	


rc@r)�CommandLineTestsWithSourceEpochNrrrrrr��r	r�c@r)�CommandLineTestsNoSourceEpochNrrrrrr��r	r�c@s�eZdZdd�Zejdd��Zd#dd�Zdd	d
d�dd
�Zdd�Z	d$dd�Z
dd�Zdd�Zd$dd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"S)%�HardlinkDedupTestsBasecCs
d|_dSrr�r?rrrr;�s
zHardlinkDedupTestsBase.setUpccsB�t���}||_|Vd|_Wd�dS1swYdSr)r)r�r,)r9r,rrr�temporary_directory�s�
"�z*HardlinkDedupTestsBase.temporary_directoryrcCst�|j||�Sr)rr�r,)r9�coder�rrrr��rAz"HardlinkDedupTestsBase.make_scriptTrF)r�r�rdcCstj|jd|||d�dS)NT)rer��hardlink_dupesrd)r[rnr,)r9r�r�rdrrrrn�s
�z"HardlinkDedupTestsBase.compile_dirc	Cs�|���V|�d�|�t��tj|jdddd�Wd�n1s$wY|�t��tj|jdddgdd�Wd�n1sEwYWd�dSWd�dS1s]wYdS)N�passTr)rer�r�)r�r�r�r�r[rnr,r?rrr�
test_bad_args�s

�����"�z$HardlinkDedupTestsBase.test_bad_argscCs4g}|r	|�d�|�d�|r|�d�d�|�S)Nz'module docstring'zx = 1z
assert x == 1�
)r�r-)r9�	docstring�	assertion�linesrrr�create_code�s



z"HardlinkDedupTestsBase.create_codeccs4�dD]}dD]}|j||d�}|||fVqqdS)N)FT�r�r�)r�)r9r�r�r�rrr�
iter_codes�s���z!HardlinkDedupTestsBase.iter_codesc
Cs�|��D]c\}}}|j||d��O|���;|�|�}t|�}|jdd�|�t|d|d��|�t|d|d��|�t|d|d��Wd�n1sSwYWd�n1sbwYqdS)Nr�Fr�rrr)r�r�r�r�rrnrur")r9r�r�r�rr�rrr�
test_disabled�s

�����z$HardlinkDedupTestsBase.test_disabledcCsft|�}|�t|d|d�|�|�t|d|d�|o!|�|�t|d|d�|�dS)Nrrr)rrkr")r9rr�r�r�rrr�check_hardlinks�s�
��z&HardlinkDedupTestsBase.check_hardlinksc
Cs�|��D]@\}}}|j||d��,|���|�|�}|��|�|||�Wd�n1s0wYWd�n1s?wYqdS)Nr�)r�r�r�r�rnr�)r9r�r�r�rrrrr��s

�����z$HardlinkDedupTestsBase.test_hardlinkc
Cs�dD]O}|j|d��?|���+|�|���}|j|d�t||d�}t||d�}|�t||��Wd�n1s=wYWd�n1sLwYqdS)N))rr)rr)rr)�opts�r�rr)r�r�r�r�rnrrZr")r9r�r�pyc1�pyc2rrr�test_only_two_levels�s
�����z+HardlinkDedupTestsBase.test_only_two_levelscCsp|���*|�|���}|jgd�d�t|d�}t|d�}|�t||��Wd�dS1s1wYdS)N)rrrrr�rr)r�r�r�rnrrZr")r9rr�r�rrr�test_duplicated_levelss


"�z-HardlinkDedupTestsBase.test_duplicated_levelscCs�|���d|�d�}|��|�|�t|�}t�|d�j}|�d�}|jddgdd�|�|t�|d�j�|�	t
|d|d��|�|t�|d�j�|�t
j|d|ddd��Wd�dS1skwYdS)	Nr�r�print(0)rT)r�rdr��shallow)r�r�rnr�rrrr rkrZr"rmru�filecmp�cmp�r9rr��inoderrr�test_recompilations



 "�z)HardlinkDedupTestsBase.test_recompilationcCs�|���l|j|��dd�}|��|�|�t|�}t�|d�j}|jddd�}t	j
dddd|jd	�|�|t�|d�j�|�|t�|d
�j�|�
t|d|d
��|�
tj|d|d
dd
��Wd�dS1sswYdS)N�module)r�rr�r5z-cz
import moduleF)r`rrrTr�)r�r�r�rnr�rrrr rrr,rkrur"r�r�r�rrr�test_import0s

� "�z"HardlinkDedupTestsBase.test_importNr)FF)rrrr;rVr�r�r�rnr�r�r�r�r�r�r�r�r�r�rrrrr��s 


	
		
r�c@r)�!HardlinkDedupTestsWithSourceEpochNrrrrrr�Lr	r�c@r)�HardlinkDedupTestsNoSourceEpochNrrrrrr�Sr	r��__main__)0r[rVr��importlib.utilrrXrryrir4rKr�r)Ztest.test_importlib.utilr�r-rhrr�concurrent.futuresr�concurrent.futures.processrr�NotImplementedErrorrZtest.supportrrZtest.test_py_compiler	r
rrr"r#ZTestCaserrrrr�r�r�r�r�rr�rrrr�<module>s����>����
�