HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/test/__pycache__/test_compileall.cpython-36.pyc
3


 \Z[�@s
ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddl
mZmZyddlmZdZWnek
r�dZYnXddlmZddlmZGdd	�d	e
j�ZGd
d�de
j�ZGdd
�d
e
j�Zedk�re
j�dS)�N)�mock�
skipUnless)�ProcessPoolExecutorTF)�support)�
script_helperc@s�eZdZdd�Zdd�Zdd�Zdd�Zeje	e
d	�d
�dd��Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zejd�d d!��Zd"d#�Zejd�d$d%��Zejd�ejd&�d'd(���Zejdd)d*�ejd&�d+d,���Zd)S)-�CompileallTestsc
Cs�tj�|_tjj|jd�|_tjj	|j�|_
t|jd��}|jd�WdQRXtjj|jd�|_
tjj	|j
�|_tj|j|j
�tjj|jd�|_tj|j�tjj|jd�|_tj|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�'/usr/lib64/python3.6/test_compileall.py�setUps
zCompileallTests.setUpcCstj|j�dS)N)r�rmtreer)rrrr�tearDown)szCompileallTests.tearDownc	Cs8tjj|jd�|_t|jd��}|jd�WdQRXdS)Nz_test_bad.pyrzx (
)rr
rr�bad_source_pathrr)rrrrr�add_bad_source_file,sz#CompileallTests.add_bad_source_filecCsNt|jd��}|jd�}WdQRXttj|j�j�}tj	dt
jj|�}||fS)N�rb�z<4sl)
rr�read�intr�statr�st_mtime�struct�packrr�MAGIC_NUMBER)rr�data�mtimeZcomparerrrr-1s
zCompileallTests.datar(ztest needs os.stat()cCs�tj|j�|j|j��t|jd��}|j�t|�d�}WdQRXt|jd��}|j	|�|j	|�WdQRX|j
|j��tj|j
ddd�|j|j��dS)zOCheck that compileall recreates bytecode when the new metadata is
        used.r$N�wbFT)�force�quiet)�
py_compile�compiler�assertEqualr-rrr&�lenr�assertNotEqual�
compileall�compile_dirr�
assertTrue)rZmetadatarZbcrrr�recreation_check8s
z CompileallTests.recreation_checkcCs|jtjdtjjd��dS)Nz<4sl�)r:r*r+rrr,)rrrr�
test_mtimeGszCompileallTests.test_mtimecCs|jd�dS)Ns)r:)rrrr�test_magic_numberLsz!CompileallTests.test_magic_numberc
Csx0|j|jfD] }ytj|�WqYqXqW|jtj|jddd��|jtjj	|j�ojtjj	|j��tj|j�|jtj
|jddd��|jtjj	|j�o�tjj	|j��tj|j�tj|j�|j�|j
tj|jddd��|j
tj
|jddd��dS)NFT)r0r1�)rrr�unlinkr9r7�compile_filerr
�isfiler8rr#�assertFalser")r�fnrrr�test_compile_filesPs*

z"CompileallTests.test_compile_filescCsh|jtjj|j��tj��}|jtj	t
j|j���WdQRX|j
|j�d�|jtjj|j��dS)Nz&Compiling ([^WindowsPath|PosixPath].*))rBrr
rArr�captured_stdoutr9r7r@�pathlib�Pathr�assertRegex�getvalue)r�stdoutrrr�test_compile_file_pathlikeis

"z*CompileallTests.test_compile_file_pathlikecCsP|jtjj|j��|jtjtj	|j
�tj	d�dd��|jtjj|j��dS)NZ	ddir_pathr>)�ddirr1)rBrr
rArr9r7r@rFrGr)rrrr�test_compile_file_pathlike_ddirqs

z/CompileallTests.test_compile_file_pathlike_ddircCsttjjj|jgd��|jtjdd��WdQRXtjjj|jgd��$|j�|j	tjdddd��WdQRXdS)N)r
r>)r1FT)�skip_curdirr0r1)
�testZtest_importlibrZimport_staterr9r7�compile_pathr#rB)rrrr�test_compile_pathxs
z!CompileallTests.test_compile_pathcCshtjj|jd�}tjj|d�}tj|�t|d��WdQRXtj|�|jtjj	tjj|d���dS)Nr-rr�__pycache__)
rr
rrrrr7r@rB�exists)rZdata_dirZ	data_filerrr�test_no_pycache_in_non_package�s


z.CompileallTests.test_no_pycache_in_non_packagecCs�dnd\}}tj|jd|d�tjj|j|d�}|jtj	j
|��tjj|j|d�}|jtj	j
|��tjj|j|d�}|jtj	j
|��dS)	NTr;r�)r1�optimize)�optimization)r;r;)rrU)
r7r8rrrrrr9rr
rArr)rrV�opt�cachedZcached2Zcached3rrr�
test_optimize�s


zCompileallTests.test_optimizec
Csn|jtjj|j��tj��}tjt	j
|j��WdQRX|j�j
�d}|j|d�|jtjj|j��dS)Nrz$Listing ([^WindowsPath|PosixPath].*))rBrr
rArrrEr7r8rFrGrrI�
splitlinesrHr9)rrJ�linerrr�test_compile_dir_pathlike�s
z)CompileallTests.test_compile_dir_pathlikez&concurrent.futures.ProcessPoolExecutorcCs"tj|jddd�|j|j�dS)NT�)r1�workers)r7r8rr9�called)r�	pool_mockrrr�test_compile_pool_called�sz(CompileallTests.test_compile_pool_calledcCs,|jtd��tj|jdd�WdQRXdS)Nz%workers must be greater or equal to 0r;)r_���)ZassertRaisesRegex�
ValueErrorr7r8r)rrrr�!test_compile_workers_non_positive�sz1CompileallTests.test_compile_workers_non_positivecCs,tj|jddd�|j|jddd�dS)NTr)r1r_r;�max_workers)r7r8rr4�	call_args)rrarrr�test_compile_workers_cpu_count�sz.CompileallTests.test_compile_workers_cpu_countzcompileall.compile_filecCs,tj|jdd�|j|j�|j|j�dS)NT)r1)r7r8rrBr`r9)r�compile_file_mockrarrr�test_compile_one_worker�sz'CompileallTests.test_compile_one_workerN)�newcCs"tj|jddd�|j|j�dS)NTr^)r1r_)r7r8rr9r`)rrirrr�$test_compile_missing_multiprocessing�sz4CompileallTests.test_compile_missing_multiprocessing)�__name__�
__module__�__qualname__rr!r#r-�unittestr�hasattrrr:r<r=rDrKrMrQrTrZr]r�patchrbrerhrjrlrrrrrs*	rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.c	CsPtj�|_tjj|jd�|_t|jddd��}|jd�|jd�WdQRXdS)Nz_test.pyrzutf-8)�encodingz# -*- coding: utf-8 -*-
u
print u"€"
)	r	r
rrr
rrrr)rrrrrr�s


zEncodingTest.setUpcCstj|j�dS)N)rr r)rrrrr!�szEncodingTest.tearDowncCs8z*tj}tjtj�dd�t_tj|j�Wd|t_XdS)N�ascii)rt)�sysrJ�io�
TextIOWrapper�BytesIOr7r8r)rZorig_stdoutrrr�
test_error�s
zEncodingTest.test_errorN)rmrnro�__doc__rr!rzrrrrrs�srsc@sdeZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZxJddgfdddgfdddgfgD]&\ZZZeefd d!�Zee�d"e<q�Wd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%e&e'dE�dFdG��Z(e)j*dH�dIdJ��Z+dKS)L�CommandLineTestszTest compileall's CLI.cCs�x�ttjjtj�D]�}d}tj|�d}|d}zXy8|j�sH|j�d}|j	d��}|j
d�WdQRXWntk
r�d}PYnXWdtj
t|��|r�|j�XqWd}||_dS)NFrRztest.tryTrz# for test_compileall)�filterrr
�isdirrvrFrG�is_dirrrr�OSErrorrr?�str�rmdir�_sys_path_writable)�clsr
Zdirectory_createdrrZsys_path_writablerrr�
setUpClass�s$zCommandLineTests.setUpClasscCs|jstjd��dS)Nz(not all entries on sys.path are writable)r�rpZSkipTest)rrrr�_skip_if_sys_path_not_writable�sz/CommandLineTests._skip_if_sys_path_not_writablecCstj�d|�S)N�-S�-mr7)r�r�r7)rZ!optim_args_from_interpreter_flags)r�argsrrr�
_get_run_args�szCommandLineTests._get_run_argscOs(tj|j|�|�\}}}|jd|�|S)N�)r�assert_python_okr�r4)rr��env_vars�rc�out�errrrr�assertRunOK�szCommandLineTests.assertRunOKcOs"tj|j|�|�\}}}|||fS)N)r�assert_python_failurer�)rr�r�r�r�r�rrr�assertRunNotOKszCommandLineTests.assertRunNotOKcCs"tjj|�}|jtjj|��dS)N)rrrr9rr
rS)rrCr
rrr�assertCompiledszCommandLineTests.assertCompiledcCs"tjj|�}|jtjj|��dS)N)rrrrBrr
rS)rrCr
rrr�assertNotCompiled	sz"CommandLineTests.assertNotCompiledcCsrtj�|_|jtj|j�tjj|jd�|_	tj
|j	�tjj|j	d�|_tj
|j	dd�|_tj
|j	dd�|_dS)NZfoorR�__init__rUZbar)r	r
rZ
addCleanuprr rr
r�pkgdirr�pkgdir_cachedirr�make_script�initfn�barfn)rrrrr
s
zCommandLineTests.setUpcCsL|j�tj|jdd�}|j|jd�|j|�|j|j�|j|j�dS)N�bazrU)�
PYTHONPATH)	r�rr�rr�r�r�r�r�)r�bazfnrrr�test_no_args_compiles_paths
z+CommandLineTests.test_no_args_compiles_pathcCs�|j�tj|jdd�}|j|jd�tjj|�}tj	|t
j
�dfd�tj|�j}|j|jd�tj|�j}|j
||�|jd|jd�tj|�j}|j||�dS)Nr�rU)r��<r>z-f)r�rr�rr�rrrr�utime�timer(r)r4r6)rr��pycpathr.�mtime2rrr� test_no_args_respects_force_flag sz1CommandLineTests.test_no_args_respects_force_flagcCsR|j�tj|jdd�|j|jd�}|jd|�|jd|jd�}|jd|�dS)Nr�rU)r�sListing z-q)r�rr�rr�ZassertInZassertNotIn)r�noisyr1rrr� test_no_args_respects_quiet_flag1sz1CommandLineTests.test_no_args_respects_quiet_flagZnormal�pycrVz	opt-1.pycz-OZdoubleoptimizez	opt-2.pycz-OOcs~tj|ddd|jg�|jtjj|j��t�fdd�d
D��}|j	ttj
|j��|�|j�fdd	�tj
|j�D��dS)Nz-mr7z-qc3s|]}|jtjj��VqdS)N)�formatrv�implementation�	cache_tag)�.0�base)�extrr�	<genexpr>Esz%CommandLineTests.f.<locals>.<genexpr>�__init__.{}.{}�	bar.{}.{}csg|]}|j��r|�qSr)�endswith)r�rC)r�rr�
<listcomp>Isz&CommandLineTests.f.<locals>.<listcomp>)r�r�)rr�r�r9rr
rSr��sortedr4�listdirrB)rr��switch�expectedr)r�r�f@s
zCommandLineTests.fZtest_pep3147_paths_cCsP|jdd|j�|jtjj|j��tddddg�}|jttj	|j��|�dS)Nz-bz-qz__init__.pyz__init__.pyczbar.pyzbar.pyc)
r�r�rBrr
rSr�r�r4r�)rr�rrr�test_legacy_pathsMs
z"CommandLineTests.test_legacy_pathscCs||jd|j�|jtjj|j��tjj|jd�}|jtjj|��|jd|j�|jtjj|j��|jtjj|��dS)Nz-qrR)	r�r�r9rr
rSr�rrB)rZ
cachecachedirrrr�test_multiple_runsWsz#CommandLineTests.test_multiple_runscCs�|jd|j�tjj|j�}tj|tj�dfd�tj	|�j
}|jd|j�tj	|�j
}|j||�|jdd|j�tj	|�j
}|j||�dS)Nz-qr�r>z-f)
r�r�rrrr�rr�r�r(r)r4r6)rr�r.r�rrr�
test_forcedszCommandLineTests.test_forcecCs�tjj|jd�}tj|�tj|dd�}tj|dd�}|jdd|j�|j|�|j	tjj
tjj|d���|jd|j�|j|�|j|�dS)N�spamr�rU�hamz-qz-lrR)rr
rr�rrr�r�r�rBrSr�)r�
subpackage�	subinitfn�hamfnrrr�test_recursion_controlss


z'CommandLineTests.test_recursion_controlc	CsZtjj|jd�}tjj|d�}tjj|d�}x|||fD]}tj|�q8Wtjj|d�}tj|dd�}tj|dd�}tj|dd�}|jdd|j�|j|�|j	tjj
tjj|d	���|jdd
|j�|j|�|j|�|j|�|jdd|j�|j|�|j|�|j|�|j|�|jdd|j�|j|�|j|�|j|�|j|�dS)
Nr�r�Zeggsz__init__.pyrUZeggz-qz-r 0rRz-r 1z-r 2z-r 5)rr
rr�rZmake_pkgr�r�r�rBrSr�)	rr�Zsubpackage2Zsubpackage3Zpkgr�r�ZspamfnZeggfnrrr�test_recursion_limits6










z%CommandLineTests.test_recursion_limitcCs6|j|j�}|jd|j�}|jd|�|jd|�dS)Nz-qr�)r�r�r6r4)rr�r1rrr�
test_quiet�szCommandLineTests.test_quietcCsTtj|jdd�|jd|j�\}}}|jd|j�\}}}|jd|�|jd|�dS)N�crunchyfrogz
bad(syntaxz-qz-qqr�)rr�r�r�r6r4)r�_r1Zsilentrrr�test_silent�s
zCommandLineTests.test_silentcCs.|jddd|j�|j|j�|j|j�dS)Nz-qz-xz
ba[^\\/]*$)r�r�r�r�r�r�)rrrr�test_regexp�szCommandLineTests.test_regexpcCsvtjj|jd�}tj|�tj|dd�}tj|dd�}|jd|j|�|j	|j
�|j	|j�|j	|�|j	|�dS)NZfoo2r�rU�bar2z-q)rr
rrrrr�r�r�r�r�r�)rZpkgdir2Zinit2fn�bar2fnrrr�test_multiple_dirs�s

z#CommandLineTests.test_multiple_dirscCs8tj|jdd�|jddd|j�\}}}|j|d�dS)Nr�z
bad(syntaxz-qz-d�dinsdalesFile "dinsdale)rr�r�r�rH)rr�r�r�rrr�test_d_compile_error�sz%CommandLineTests.test_d_compile_errorcCs�tj|jdd�}|jddd|j�tj|jdd�}tjj|�}tj|tj	j
|jd��tj|�tj|d	d
�\}}}|j
|d�dS)Nr�zraise Exceptionz-qz-dr��bingz
import bazzbaz.pycF)Z
__isolatedsFile "dinsdale)rr�r�r�rrrr�renamer
r�remover�rH)rr�rCr�r�r�r�rrr�test_d_runtime_error�s
z%CommandLineTests.test_d_runtime_errorcCsZ|jdtjj|jd�|j�\}}}|j|d�|j|d�|jtjj	t
jj|j
���dS)Nz-i�
nosuchfilesrror.*nosuchfiles	Traceback)r�rr
rrr�rHZassertNotRegexrBrSrrrr�)rr�r�r�rrr�test_include_bad_file�sz&CommandLineTests.test_include_bad_filecCs�tj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}ttjj|jd�d��>}|jtjj|jd�tj	�|jtjj|jd	�tj	�WdQRX|j
d
tjj|jd�|�|j|�|j|�|j|�|j|�dS)N�f1rU�f2�f3�f4�l1rzf1.pyzf2.pyz-i)
rr�r�rrr
rrr�linesepr�r�r�)rr�r�r�r�r�rrr�test_include_file_with_arg�s&


z+CommandLineTests.test_include_file_with_argcCs�tj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}ttjj|jd�d��"}|jtjj|jd�tj	�WdQRX|j
d	tjj|jd��|j|�|j|�|j|�|j|�dS)
Nr�rUr�r�r�r�rzf2.pyz-i)
rr�r�rrr
rrrr�r�r�r�)rr�r�r�r�r�rrr�test_include_file_no_arg�s&


z)CommandLineTests.test_include_file_no_argcCs�tj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}tj|jf�ddg�}|jj|tjj	d��tj
|�|j|�|j|�|j|�|j|�dS)	Nr�rUr�r�r�z-i�-ru)
rr�r�Zspawn_pythonr��stdinrrr��encodeZkill_pythonr�r�)rr�r�r�r��prrr�test_include_on_stdin�s



z&CommandLineTests.test_include_on_stdincCs\tj|jdd�}|jd|j||j�\}}}|j|d�|j|�|j|j�|j|j�dS)Nr�zsyntax(errorr�srror)	rr�r�r�r�r�rHr�r�)rZbingfnr�r�r�rrr�!test_compiles_as_much_as_possible�s

z2CommandLineTests.test_compiles_as_much_as_possiblecCs|jd�}|j|d�dS)NZbadfilenamesCan't list 'badfilename')r�rH)rr�rrr�!test_invalid_arg_produces_messages
z2CommandLineTests.test_invalid_arg_produces_messagezrequires multiprocessingcCs�tj|jdd�}g}xRtd�D]F}tjj|jdj|��}tj|�tj|dd�}|j	tj|dd��qW|j
|jdd�|j|�x|D]}|j|�q�WdS)Nr�rUr^zfoo{}r�z-j�0)rr�r�rangerr
rr�r�appendr�r�)rr��files�suffixr�rCrrrr�test_workers
s


zCommandLineTests.test_workerszcompileall.compile_dirc
CsRtjdtj|jdgd��0tj�|j|j�|j	|j
ddd�WdQRXdS)Nzsys.argvz-j0)rkr;r_rc)rrrrv�
executablerr7�mainr9r`r4rg)rr8rrr�test_workers_available_coress
z-CommandLineTests.test_workers_available_coresN),rmrnror{�classmethodr�r�r�r�r�r�r�rr�r�r��namer�r�r��localsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�_have_multiprocessingr�rrrr�rrrrr|�sJ
	



"


	r|�__main__)rvr7�importlib.utilrZtest.test_importlib.utilrOrrFr2rr*r	r�rprwrr�concurrent.futuresrr��ImportErrorrZtest.supportrZTestCaserrsr|rmr�rrrr�<module>s8
(M