Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_compileall.cpython-35.pyc



��YfuR�@s`ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlm
Z
mZyddlmZdZWnek
r�dZYnXddlmZddlmZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�Zedkr\ej�dS)�N)�mock�
skipUnless)�ProcessPoolExecutorTF)�support)�
script_helperc@s3eZdZdd�Zdd�Zdd�Zejee	d�d�d	d
��Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zejd�dd��Zdd�Zejd�dd��Zejd�ejd�dd���Zejddd �ejd�d!d"���Zd S)#�CompileallTestsc
Cstj�|_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�9/opt/alt/python35/lib64/python3.5/test/test_compileall.py�setUpszCompileallTests.setUpcCstj|j�dS)N)r�rmtreer)rrrr�tearDown(szCompileallTests.tearDowncCskt|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++s
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
dddd�|j|j��dS)zOCheck that compileall recreates bytecode when the new metadata is
        used.r"N�wb�forceF�quietT)�
py_compile�compiler�assertEqualr+rrr$�lenr�assertNotEqual�
compileall�compile_dirr�
assertTrue)rZmetadatarZbcrrr�recreation_check2s#
z CompileallTests.recreation_checkcCs&|jtjdtjjd��dS)Nz<4sl�)r8r(r)rrr*)rrrr�
test_mtimeAszCompileallTests.test_mtimecCs|jd�dS)Ns)r8)rrrr�test_magic_numberFsz!CompileallTests.test_magic_numberc
Csx6|j|jfD]"}ytj|�WqYqXqWtj|jdddd�|jtjj	|j�o�tjj	|j��tj|j�tj
|jdddd�|jtjj	|j�o�tjj	|j��tj|j�tj|j�dS)Nr.Fr/T)rrr�unlinkr5�compile_filerr7r
�isfiler6r)r�fnrrr�test_compile_filesJs	z"CompileallTests.test_compile_filescCs�tjj|jd�}tjj|d�}tj|�t|d��WdQRXtj|�|jtjj	tjj|d���dS)Nr+rr�__pycache__)
rr
rrrrr5r=�assertFalse�exists)rZdata_dirZ	data_filerrr�test_no_pycache_in_non_package[s

z.CompileallTests.test_no_pycache_in_non_packagecCs�trdnd	\}}tj|jddd|�tjj|jd|�}|jt	j
j|��tjj|jd|�}|jt	j
j|��tjj|j
d|�}|jt	j
j|��dS)
Nr9r�r/T�optimize�optimization)r9r9)rrE)�	__debug__r5r6rrrrrr7rr
r>rr)rrFZopt�cachedZcached2Zcached3rrr�
test_optimizegs			zCompileallTests.test_optimizezcompileall.ProcessPoolExecutorcCs0tj|jdddd�|j|j�dS)Nr/T�workers�)r5r6rr7�called)r�	pool_mockrrr�test_compile_pool_calledvsz(CompileallTests.test_compile_pool_calledcCs4|jtd��tj|jdd�WdQRXdS)Nz%workers must be greater or equal to 0rKr9���)ZassertRaisesRegex�
ValueErrorr5r6r)rrrr�!test_compile_workers_non_positive{s	
z1CompileallTests.test_compile_workers_non_positivecCs;tj|jdddd�|j|jddd�dS)Nr/TrKrr9Zmax_workers)r5r6rr2�	call_args)rrNrrr�test_compile_workers_cpu_count�sz.CompileallTests.test_compile_workers_cpu_countzcompileall.compile_filecCs:tj|jdd�|j|j�|j|j�dS)Nr/T)r5r6rrBrMr7)r�compile_file_mockrNrrr�test_compile_one_worker�sz'CompileallTests.test_compile_one_worker�newNcCs0tj|jdddd�|j|j�dS)Nr/TrKrL)r5r6rr7rM)rrUrrr�$test_compile_missing_multiprocessing�sz4CompileallTests.test_compile_missing_multiprocessing)�__name__�
__module__�__qualname__rr!r+�unittestr�hasattrrr8r:r;r@rDrJr�patchrOrRrTrVrXrrrrrs 'rc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�EncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.c	Csjtj�|_tjj|jd�|_t|jddd��!}|jd�|jd�WdQRXdS)Nz_test.pyr�encodingzutf-8z# -*- coding: utf-8 -*-
u
print u"€"
)	r	r
rrr
rrrr)rrrrrr�s

zEncodingTest.setUpcCstj|j�dS)N)rr r)rrrrr!�szEncodingTest.tearDowncCsLz;tj}tjtj�dd�t_tj|j�Wd|t_XdS)Nr`�ascii)�sys�stdout�io�
TextIOWrapper�BytesIOr5r6r)rZorig_stdoutrrr�
test_error�s
	zEncodingTest.test_errorN)rYrZr[�__doc__rr!rgrrrrr_�sr_c@s	eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZxdddgfdddgfdddgfgD]2\ZZZeed 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}zfyF|j�sd|j�d}|j	d��}|j
d�WdQRXWntk
r�d}PYnXWdtj
t|��|r�|j�XqWd}||_dS)NFrAztest.tryTrz# for test_compileall)�filterrr
�isdirrb�pathlibZPath�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)rqr\ZSkipTest)rrrr�_skip_if_sys_path_not_writable�s	z/CommandLineTests._skip_if_sys_path_not_writablecCsPdg}tjjr8|jdddditjj�|ddgt|�S)Nz-Sr9z-O�z-OOz-mr5)rb�flagsrF�append�list)r�argsZinterp_argsrrr�
_get_run_args�s	#zCommandLineTests._get_run_argscOs8tj|j|�|�\}}}|jd|�|S)N�)r�assert_python_okrzr2)rry�env_vars�rc�out�errrrr�assertRunOK�szCommandLineTests.assertRunOKcOs1tj|j|�|�\}}}|||fS)N)r�assert_python_failurerz)rryr}r~rr�rrr�assertRunNotOK�szCommandLineTests.assertRunNotOKcCs/tjj|�}|jtjj|��dS)N)rrrr7rr
rC)rr?r
rrr�assertCompiled�szCommandLineTests.assertCompiledcCs/tjj|�}|jtjj|��dS)N)rrrrBrr
rC)rr?r
rrr�assertNotCompiled�sz"CommandLineTests.assertNotCompiledcCs�tj�|_|jtj|j�tjj|jd�|_	tj
|j	�tjj|j	d�|_tj
|j	dd�|_tj
|j	dd�|_dS)NZfoorA�__init__rEZbar)r	r
rZ
addCleanuprr rr
r�pkgdirr�pkgdir_cachedirr�make_script�initfn�barfn)rrrrr�szCommandLineTests.setUpcCsf|j�tj|jdd�}|jd|j�|j|�|j|j�|j|j�dS)N�bazrE�
PYTHONPATH)	rtrr�rr�r�r�r�r�)r�bazfnrrr�test_no_args_compiles_path�s

z+CommandLineTests.test_no_args_compiles_pathcCs�|j�tj|jdd�}|jd|j�tjj|�}tj	|t
j
�dfd�tj|�j}|jd|j�tj|�j}|j
||�|jdd|j�tj|�j}|j||�dS)Nr�rEr��<ruz-f)rtrr�rr�rrrr�utime�timer&r'r2r4)rr��pycpathr,�mtime2rrr� test_no_args_respects_force_flag�s
!z1CommandLineTests.test_no_args_respects_force_flagcCsq|j�tj|jdd�|jd|j�}|jd|�|jdd|j�}|jd|�dS)Nr�rEr�sListing z-q)rtrr�rr�ZassertInZassertNotIn)r�noisyr/rrr� test_no_args_respects_quiet_flags
z1CommandLineTests.test_no_args_respects_quiet_flagZnormal�pycrFz	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-mr5z-qc3s'|]}|jtjj��VqdS)N)�formatrb�implementation�	cache_tag)�.0�base)�extrr�	<genexpr>sz%CommandLineTests.f.<locals>.<genexpr>�__init__.{}.{}�	bar.{}.{}cs%g|]}|j��r|�qSr)�endswith)r�r?)r�rr�
<listcomp>s	z&CommandLineTests.f.<locals>.<listcomp>)r�r�)rr|r�r7rr
rCr��sortedr2�listdirrB)rr��switch�expectedr)r�r�fs	
"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
rCr�r�r2r�)rr�rrr�test_legacy_paths s
z"CommandLineTests.test_legacy_pathscCs�|jd|j�|jtjj|j��tjj|jd�}|jtjj|��|jd|j�|jtjj|j��|jtjj|��dS)Nz-qrA)	r�r�r7rr
rCr�rrB)rZ
cachecachedirrrr�test_multiple_runs*sz#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�ruz-f)
r�r�rrrr�rr�r�r&r'r2r4)rr�r,r�rrr�
test_force7s!zCommandLineTests.test_forcecCs�tjj|jd�}tj|�tj|dd�}tj|dd�}|jdd|j�|j|�|j	tjj
tjj|d���|jd|j�|j|�|j|�dS)N�spamr�rE�hamz-qz-lrA)rr
rr�rrr�r�r�rBrCr�)r�
subpackage�	subinitfn�hamfnrrr�test_recursion_controlFs

(
z'CommandLineTests.test_recursion_controlc	Cs�tjj|jd�}tjj|d�}tjj|d�}x$|||fD]}tj|�qRWtjj|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__.pyrEZeggz-qz-r 0rAz-r 1z-r 2z-r 5)rr
rr�rZmake_pkgr�r�r�rBrCr�)	rr�Zsubpackage2Zsubpackage3Zpkgr�r�ZspamfnZeggfnrrr�test_recursion_limitRs6
"









z%CommandLineTests.test_recursion_limitcCsK|j|j�}|jd|j�}|jd|�|jd|�dS)Nz-qr{)r�r�r4r2)rr�r/rrr�
test_quiettszCommandLineTests.test_quietcCsvtj|jdd�|jd|j�\}}}|jd|j�\}}}|jd|�|jd|�dS)N�crunchyfrogz
bad(syntaxz-qz-qqr{)rr�r�r�r4r2)r�_r/Zsilentrrr�test_silentzs
zCommandLineTests.test_silentcCs=|jddd|j�|j|j�|j|j�dS)Nz-qz-xz
ba[^\\/]*$)r�r�r�r�r�r�)rrrr�test_regexp�szCommandLineTests.test_regexpcCs�tjj|jd�}tj|�tj|dd�}tj|dd�}|jd|j|�|j	|j
�|j	|j�|j	|�|j	|�dS)NZfoo2r�rE�bar2z-q)rr
rrrrr�r�r�r�r�r�)rZpkgdir2Zinit2fn�bar2fnrrr�test_multiple_dirs�s

z#CommandLineTests.test_multiple_dirscCsNtj|jdd�|jddd|j�\}}}|j|d�dS)Nr�z
bad(syntaxz-qz-d�dinsdalesFile "dinsdale)rr�r�r��assertRegex)rr~rr�rrr�test_d_compile_error�s$z%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.pycZ
__isolatedFsFile "dinsdale)rr�r�r�rrrr�renamer
r�remover�r�)rr�r?r�r~rr�rrr�test_d_runtime_error�s"
z%CommandLineTests.test_d_runtime_errorcCs|jdtjj|jd�|j�\}}}|j|d�|j|d�|jtjj	t
jj|j
���dS)Nz-i�
nosuchfilesrror.*nosuchfiles	Traceback)r�rr
rrr�r�ZassertNotRegexrBrCrrrr�)rr~rr�rrr�test_include_bad_file�s-z&CommandLineTests.test_include_bad_filecCs4tj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}ttjj|jd�d��S}|jtjj|jd�tj	�|jtjj|jd	�tj	�WdQRX|j
d
tjj|jd�|�|j|�|j|�|j|�|j|�dS)N�f1rE�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Cstj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}ttjj|jd�d��-}|jtjj|jd�tj	�WdQRX|j
d	tjj|jd��|j|�|j|�|j|�|j|�dS)
Nr�rEr�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�rEr�r�r�z-i�-ra)
rr�r�Zspawn_pythonrz�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�r�r�r�)rZbingfnr~rr�rrr�!test_compiles_as_much_as_possible�s
z2CommandLineTests.test_compiles_as_much_as_possiblecCs#|jd�}|j|d�dS)NZbadfilenamesCan't list 'badfilename')r�r�)rrrrr�!test_invalid_arg_produces_message�sz2CommandLineTests.test_invalid_arg_produces_messagezrequires multiprocessingcCs�tj|jdd�}g}xstd�D]e}tjj|jdj|��}tj|�tj|dd�}|j	tj|dd��q+W|j
|jdd�|j|�x|D]}|j|�q�WdS)Nr�rErLzfoo{}r�z-j�0)rr�r�rangerr
rr�rrwr�r�)rr��files�suffixr�r?rrrr�test_workers�s!
 

zCommandLineTests.test_workerszcompileall.compile_dirc
Csetjddtj|jdg��:tj�|j|j�|j	|j
ddd�WdQRXdS)Nzsys.argvrWz-j0r9rKrP)rr^rb�
executablerr5�mainr7rMr2rS)rr6rrr�test_workers_available_cores�s

z-CommandLineTests.test_workers_available_coresN),rYrZr[rh�classmethodrsrtrzr�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�rr^r�rrrrri�sJ
	
"

"


	ri�__main__)rbr5�importlib.utilrrrlr0rr(r	r�r\rdrrZconcurrent.futuresrr��ImportErrorZtestrZtest.supportrZTestCaserr_rirYr�rrrr�<module>s2

z�M