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-1.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)z8Returns True if two files have the same inode (hardlink))�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�dS�N�r3�rmtreer*�r8rrr�tearDownE�zCompileallTestsBase.tearDowncCsRtj�|jd�|_t|jddd��}|�d�Wd�dS1s"wYdS)Nz_test_bad.pyr$r%r&zx (
)rr+r,r*�bad_source_pathr/r0r7rrr�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���)
r/r.�read�intrrr-�st_mtime�struct�packrr�MAGIC_NUMBER)r8r9�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�rt�d��t�|j�|j|�	��t
|jd��}|��t
|�d�}Wd�n1s3wYt
|jd��}|�|�|�|�Wd�n1sSwY|j|�	��tj|jddd�|j|�	��dS)	zOCheck that compileall recreates bytecode when the new metadata is
        used.�SOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setrDN�wbFT��force�quiet)r�environ�get�unittestZSkipTest�
py_compile�compiler-�assertEqualrPr/r.rH�lenr0�assertNotEqualr[�compile_dirr*rZ)r8Zmetadatar9�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~�z%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.r2r�unlinkrZr[r\r-r+�isfilernr*rC�assertFalserB)r8�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].*))rvrr+rur.r�captured_stdoutrZr[r\�pathlib�Pathr-�assertRegex�getvalue)r8�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�rvrr+rur.rZr[r\rzr{r-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_pathrCrvr?rrr�test_compile_path�s�

�"�z%CompileallTestsBase.test_compile_pathcCs|tj�|jd�}tj�|d�}t�|�t|d��Wd�n1s$wYt�|�|�tj�	tj�|d���dS)NrNr9rb�__pycache__)
rr+r,r*r5r/r[r\rv�exists)r8Zdata_dirZ	data_filerrr�test_no_pycache_in_non_package�s
�
 z2CompileallTestsBase.test_no_pycache_in_non_packagecCsN|��t�t����|�t�|j��Wd�dS1s wYdSr<)	rCrVrWrXrYrvr[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+rur1r6)r8r�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].*))rvrr+rur.rryr[rnrzr{r*r}�
splitlinesr|rZ)r8r~�linerrr�test_compile_dir_pathlike�s
�z-CompileallTestsBase.test_compile_dir_pathlikecCr�r��rvrr+rur.rZr[rnrzr{r*r?rrr�"test_compile_dir_pathlike_stripdir�r�z6CompileallTestsBase.test_compile_dir_pathlike_stripdircCr�r�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�r8�	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*rvr�rZ)r8�compile_file_mockr�rrr�test_compile_one_workersz+CompileallTestsBase.test_compile_one_workerN��newcCr�r�r�)r8r�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,r5r3r4r-rrrr[rnrvrurZ)r8�depthr+�i�sourceZpyc_filenamerrr�test_compile_dir_maxlevelss
z.CompileallTestsBase.test_compile_dir_maxlevelsT)�parallelcCsddg}|j}g}|D]}tj�||�}t�|�t�|dd�|�t�|dd��qtj	|jd||r5dnd	d
�|�
|�|D]H}|�
|�|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��foo�__init__r�modzdef fn(): 1/0
fn()
Trr)rer�r�N�")r*rr+r,r5r�make_script�appendr[rnrZ�
startswithrrrrl�sep�assert_python_failurer�r�Zget_code_from_pycrk�co_filename�assertIn�fsdecode)r8r�r��fullpathr+ZmodsZsubdirr�Zmodcode�modpath�_�err�expected_inZmod_code_objrrr�_test_ddir_only*s2
�
�
�z#CompileallTestsBase._test_ddir_onlycC�|jddd�S)�=Recursive compile_dir ddir= contains package paths; bpo39769.�
<a prefix>F�r�r��r�r?rrr�test_ddir_only_one_workerCrsz-CompileallTestsBase.test_ddir_only_one_workercCr�)r�r�Tr�r�r?rrr�test_ddir_multiple_workersGrsz.CompileallTestsBase.test_ddir_multiple_workerscCr�)�?Recursive compile_dir ddir='' contains package paths; bpo39769.rFr�r�r?rrr�test_ddir_empty_only_one_workerKrsz3CompileallTestsBase.test_ddir_empty_only_one_workercCr�)r�rTr�r�r?rrr� test_ddir_empty_multiple_workersOrsz4CompileallTestsBase.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)
r8r�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�)
r8r�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��r8r�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)r8r�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+rurt�	Exception)r8rro�	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[rnrZrurv�
r8Z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`rprqrrrxrr�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_symlinkrrrrrr"5sb

	
	r"c@�eZdZdS)�CompileallTestsWithSourceEpochN�rrrrrrrr	��r	)�	metaclassZsource_date_epochc@r)�!CompileallTestsWithoutSourceEpochNr
rrrrr
�rr
c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.cCsft��|_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-r/r0r7rrrr:�s

"�zEncodingTest.setUpcCr;r<r=r?rrrr@�rAzEncodingTest.tearDowncCs<ztj}tjt��dd�t_t�|j�W|t_dS|t_w)N�asciir&)r�r~rX�
TextIOWrapper�BytesIOr[rnr*)r8Zorig_stdoutrrr�
test_error�s
zEncodingTest.test_errorN)rrr�__doc__r:r@rrrrrr�s
rc@s�eZdZdZdd�Zejdd��Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
edd��Zdd�ZddgfdddgfdddgffD]\ZZZeefdd�Zee�d e<qCd!d"�Zd#d$�Zed%d&��Zd'd(�Zd)d*�Zejd+d,��Zd-d.�Zd/d0�Zd1d2�Z d3d4�Z!d5d6�Z"d7d8�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��Z0dMdN�Z1dOdP�Z2ejdQdR��Z3dSdT�Z4dUdV�Z5dWS)X�CommandLineTestsBasezTest compileall's CLI.cCsrt��|_|�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,�pkgdirr5�pkgdir_cachedirrr��initfn�barfnr?rrrr:�s
zCommandLineTestsBase.setUpccsB�tj}tj�|jd�}z|t_|j|d�VW|t_dS|t_w)z&Adjust and restore sys.pycache_prefix.Z
__testcache__)�
PYTHONPATHZPYTHONPYCACHEPREFIXN)r��pycache_prefixrr+r,r*)r8Z
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)r8�argsrrr�
_get_run_argss
����z"CommandLineTestsBase._get_run_argscOs4tj|�|�i|�ddi��\}}}|�d|�|S)N�PYTHONIOENCODINGr%�)r�assert_python_okrrk�r8rZenv_varsr�r�r�rrr�assertRunOKs���z CommandLineTestsBase.assertRunOKcOs.tj|�|�i|�ddi��\}}}|||fS)Nrr%)rr�rr"rrr�assertRunNotOKs���
z#CommandLineTestsBase.assertRunNotOKcC�"tj�|�}|�tj�|��dSr<)rrrrZrr+r��r8rwr+rrr�assertCompiled�z#CommandLineTestsBase.assertCompiledcCr%r<)rrrrvrr+r�r&rrr�assertNotCompiledr(z&CommandLineTestsBase.assertNotCompiledcCspt�|jdd�}|���"}|jdi|��|�|�|�|j�|�|j�Wd�dS1s1wYdS)N�bazrr)	rr�r*rr#r'r)rr)r8�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)r8r+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)r4)rr�r*rr#r�r�)r8r,�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[r4c3s �|]}|�tjj��VqdSr<)�formatr��implementation�	cache_tag)r�base��extrr�	<genexpr>Is��z)CommandLineTestsBase.f.<locals>.<genexpr>)z__init__.{}.{}z	bar.{}.{}csg|]	}|���r|�qSr)�endswith)rrwr=rrrMs
�z*CommandLineTestsBase.f.<locals>.<listcomp>)rr!rrZrr+r�r�sortedrk�listdirrv)r8r>�switch�expectedrr=r�fDs��$zCommandLineTestsBase.fZtest_pep3147_paths_cCsL|�dd|j�|�tj�|j��tgd��}|�tt�	|j��|�dS)Nz-br4)�__init__.pyz__init__.pyczbar.pyzbar.pyc)
r#rrvrr+r�rrArkrB)r8rDrrr�test_legacy_pathsQsz&CommandLineTestsBase.test_legacy_pathscCs||�d|j�|�tj�|j��tj�|jd�}|�tj�|��|�d|j�|�tj�|j��|�tj�|��dS)Nr4r�)	r#rrZrr+r�rr,rv)r8Z
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)Nr4r.rr/)
r#rrrrrrrSr0rrJrkrm)r8r1rOr2rrr�
test_forcehszCommandLineTestsBase.test_forcecCs�tj�|jd�}t�|�t�|dd�}t�|dd�}|�dd|j�|�|�|�	tj�
tj�|d���|�d|j�|�|�|�|�dS)N�spamr�r�hamr4z-lr�)rr+r,rr5rr�r#r)rvr�r')r8�
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)
NrJrKZeggsrFrZeggr4z-r 0r�z-r 1z-r 2z-r 5)rr+r,rr�make_pkgr�r#r)rvr�r')	r8rLZsubpackage2Zsubpackage3�pkgrMrNZspamfnZeggfnrrr�test_recursion_limit�s8
�









z)CommandLineTestsBase.test_recursion_limitc	Csttj�|jd�}t�|�t�dtj�|d��t�dtj�|d��|�d|j�|�tj�|jdddd��dS)NrJ�.ZevilZevil2r4rF)	rr+r,rrrPr�r#r')r8rQrrr�test_symlink_loop�s


�z&CommandLineTestsBase.test_symlink_loopcCs6|�|j�}|�d|j�}|�d|�|�d|�dS)Nr4r )r#rrmrk)r8r5rerrr�
test_quiet�szCommandLineTestsBase.test_quietcCsTt�|jdd�|�d|j�\}}}|�d|j�\}}}|�d|�|�d|�dS)N�crunchyfrog�
bad(syntaxr4z-qqr )rr�rr$rmrk)r8r�reZsilentrrr�test_silent�s
z CommandLineTestsBase.test_silentcCs.|�ddd|j�|�|j�|�|j�dS)Nr4z-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�bar2r4)rr+r,r*r5rr�r#rr'rr)r8Zpkgdir2Zinit2fn�bar2fnrrr�test_multiple_dirs�s

z'CommandLineTestsBase.test_multiple_dirscCs8t�|jdd�|�ddd|j�\}}}|�|d�dS)NrVrWr4�-d�dinsdale�File "dinsdale)rr�rr$r|�r8r�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 Exceptionr4r]r^�bingz
import bazzbaz.pycF)�
__isolatedr_)rr�rr#rrrr�renamer+r,�remover�r|)r8r+rwr7r�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|ZassertNotRegexrvr�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.pyrg)
rr�rr/rr+r,r*r0�linesepr#r'r)�r8rjrkrlrmrnrrr�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)Nrjrrkrlrmrnr$r%r&rprg)
rr�rr/rr+r,r*r0rqr#r)r'rrrrr�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)
Nrjrrkrlrmrrg�-r)
rr�rZspawn_pythonr�stdinr0rrq�encodeZkill_pythonr)r')r8rjrkrlrm�prrr�test_include_on_stdins



z*CommandLineTestsBase.test_include_on_stdincCs\t�|jdd�}|�d|j||j�\}}}|�|d�|�|�|�|j�|�|j�dS)Nrbzsyntax(errorrhsrror)	rr�rr$rrr|r)r')r8Zbingfnr�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|)r8r�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)Nrjrroz --invalidation-mode=checked-hashrD���littler�z"--invalidation-mode=unchecked-hashr)rr�rrrrrr+r,r#r/rHrkrI�
from_bytes)r8r7�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)NrZrr�zfoo{}r�z-j�0)rr�r*r�rr+r,r9r5r�r#r')r8r[�files�suffixrrwr9rrr�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�)r8rnrrr�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)r�r�r�css�|]	}dt|�VqdS)z-oN)r�)r�nrrrr?ds�zICommandLineTestsBase.test_multiple_optimization_levels.<locals>.<genexpr>)rr+r,r*r�rr�r�rrrr#rZrurIrtr�)r8r+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#rZrurvrrrrrls"


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�)r4z-o 0r�z-o 2r�rrr)
r(�TemporaryDirectory�subTestrr�rr�r#rkr!)r8r�r+r�pycsrrrr�
test_hardlink�s"

�����z"CommandLineTestsBase.test_hardlinkN)6rrrrr:rV�contextmanagerrrr#r$r'r)r-r	r3r6�namer>rCrE�localsrGrHrIrOrRrrrTrUrXrYr\rarfrirsrtryrzr{r�rrr�rrr�r�r�rr�r�rrrrr�sf


	


�

"




	


rc@r)�CommandLineTestsWithSourceEpochNr
rrrrr��rr�c@r)�CommandLineTestsNoSourceEpochNr
rrrrr��rr�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|_dSr<r�r?rrrr:�s
zHardlinkDedupTestsBase.setUpccsB�t���}||_|Vd|_Wd�dS1swYdSr<)r(r�r+)r8r+rrr�temporary_directory�s�
"�z*HardlinkDedupTestsBase.temporary_directoryrcCst�|j||�Sr<)rr�r+)r8�coder�rrrr��rAz"HardlinkDedupTestsBase.make_scriptTrF)r�r�rdcCstj|jd|||d�dS)NT)rer��hardlink_dupesrd)r[rnr+)r8r�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,)r8�	docstring�	assertion�linesrrr�create_code�s



z"HardlinkDedupTestsBase.create_codeccs4�dD]}dD]}|j||d�}|||fVqqdS)N)FT�r�r�)r�)r8r�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�rrnrvr!)r8r�r�r�rr�rrr�
test_disabled�s

�����z$HardlinkDedupTestsBase.test_disabledcCsft|�}|�t|d|d�|�|�t|d|d�|o!|�|�t|d|d�|�dS)Nrrr)rrkr!)r8rr�r�r�rrr�check_hardlinks�s�
��z&HardlinkDedupTestsBase.check_hardlinksc
Cs�|��D]@\}}}|j||d��,|���|�|�}|��|�|||�Wd�n1s0wYWd�n1s?wYqdS)Nr�)r�r�r�r�rnr�)r8r�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!)r8r�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!)r8rr�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�rrrrrkrZr!rmrv�filecmp�cmp�r8rr��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�r8z-cz
import moduleF)rcrrrTr�)r�r�r�rnr�rrrrrr!r+rkrvr!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)�!HardlinkDedupTestsWithSourceEpochNr
rrrrr�Lrr�c@r)�HardlinkDedupTestsNoSourceEpochNr
rrrrr�Srr��__main__)0r[rVr��importlib.utilrrXrrzrir3rKr�r(Ztest.test_importlib.utilr�r0rhrr�concurrent.futuresr�concurrent.futures.processrr�NotImplementedErrorrZtest.supportrrZtest.test_py_compiler	r
rrr!r"ZTestCaser	r
rrr�r�r�r�r�rr�rrrr�<module>s����>����
�