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.opt-2.pyc



���]uR�@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�shutil�copyfileZsubdirectory�mkdir�source_path3)�self�file�r�4/opt/alt/python35/lib64/python3.5/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)Nr#�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�)r9r)r*rrr+)rrrr�
test_mtimeAszCompileallTests.test_mtimecCs|jd�dS)Ns)r9)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/Fr0T)rrr�unlinkr6�compile_filerr8r
�isfiler7r)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
rrrrr6r>�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)
Nr:r�r0T�optimize�optimization)r:r:)rrF)�	__debug__r6r7rrrrrr8rr
r?rr)rrG�opt�cachedZcached2Zcached3rrr�
test_optimizegs			zCompileallTests.test_optimizezcompileall.ProcessPoolExecutorcCs0tj|jdddd�|j|j�dS)Nr0T�workers�)r6r7rr8�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 0rMr:���)ZassertRaisesRegex�
ValueErrorr6r7r)rrrr�!test_compile_workers_non_positive{s	
z1CompileallTests.test_compile_workers_non_positivecCs;tj|jdddd�|j|jddd�dS)Nr0TrMrr:�max_workers)r6r7rr3�	call_args)rrPrrr�test_compile_workers_cpu_count�sz.CompileallTests.test_compile_workers_cpu_countzcompileall.compile_filecCs:tj|jdd�|j|j�|j|j�dS)Nr0T)r6r7rrCrOr8)r�compile_file_mockrPrrr�test_compile_one_worker�sz'CompileallTests.test_compile_one_worker�newNcCs0tj|jdddd�|j|j�dS)Nr0TrMrN)r6r7rr8rO)rrXrrr�$test_compile_missing_multiprocessing�sz4CompileallTests.test_compile_missing_multiprocessing)�__name__�
__module__�__qualname__r r"r,�unittestr�hasattrrr9r;r<rArErLr�patchrQrTrWrYr[rrrrrs 'rc@s4eZdZdd�Zdd�Zdd�ZdS)�EncodingTestc	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)Nrc�ascii)�sys�stdout�io�
TextIOWrapper�BytesIOr6r7r)rZorig_stdoutrrr�
test_error�s
	zEncodingTest.test_errorN)r\r]r^r r"rjrrrrrb�srbc@seZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZxdddgfdddgfdddgfgD]2\ZZZeedd �Zee�d!e<q�Wd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$e%e&dD�dEdF��Z'e(j)dG�dHdI��Z*dJS)K�CommandLineTestscCs�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)NFrBztest.tryTrz# for test_compileall)�filterrr
�isdirre�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)rsr_ZSkipTest)rrrr�_skip_if_sys_path_not_writable�s	z/CommandLineTests._skip_if_sys_path_not_writablecCsPdg}tjjr8|jdddditjj�|ddgt|�S)Nz-Sr:z-O�z-OOz-mr6)re�flagsrG�append�list)r�argsZinterp_argsrrr�
_get_run_args�s	#zCommandLineTests._get_run_argscOs8tj|j|�|�\}}}|jd|�|S)N�)r�assert_python_okr|r3)rr{�env_vars�rc�out�errrrr�assertRunOK�szCommandLineTests.assertRunOKcOs1tj|j|�|�\}}}|||fS)N)r�assert_python_failurer|)rr{rr�r�r�rrr�assertRunNotOK�szCommandLineTests.assertRunNotOKcCs/tjj|�}|jtjj|��dS)N)rrrr8rr
rD)rr@r
rrr�assertCompiled�szCommandLineTests.assertCompiledcCs/tjj|�}|jtjj|��dS)N)rrrrCrr
rD)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)NZfoorB�__init__rFZbar)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�bazrF�
PYTHONPATH)	rvrr�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�rFr��<rwz-f)rvrr�rr�rrrr�utime�timer'r(r3r5)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�rFr�sListing z-q)rvrr�rr�ZassertInZassertNotIn)r�noisyr0rrr� test_no_args_respects_quiet_flags
z1CommandLineTests.test_no_args_respects_quiet_flagZnormal�pycrGz	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-mr6z-qc3s'|]}|jtjj��VqdS)N)�formatre�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�r8rr
rDr��sortedr3�listdirrC)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�rCrr
rDr�r�r3r�)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-qrB)	r�r�r8rr
rDr�rrC)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�rwz-f)
r�r�rrrr�rr�r�r'r(r3r5)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�rF�hamz-qz-lrB)rr
rr�rrr�r�r�rCrDr�)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__.pyrFZeggz-qz-r 0rBz-r 1z-r 2z-r 5)rr
rr�rZmake_pkgr�r�r�rCrDr�)	rr�Zsubpackage2Zsubpackage3Zpkgr�r�ZspamfnZeggfnrrr�test_recursion_limitRs6
"









z%CommandLineTests.test_recursion_limitcCsK|j|j�}|jd|j�}|jd|�|jd|�dS)Nz-qr})r�r�r5r3)rr�r0rrr�
test_quiettszCommandLineTests.test_quietcCsvtj|jdd�|jd|j�\}}}|jd|j�\}}}|jd|�|jd|�dS)N�crunchyfrogz
bad(syntaxz-qz-qqr})rr�r�r�r5r3)r�_r0Zsilentrrr�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�rF�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�r�r�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�r�r�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�ZassertNotRegexrCrDrrrr�)rr�r�r�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�f1rF�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�rFr�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�rFr�r�r�z-i�-rd)
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�r�r�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�r�)rr�rrr�!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�rFrNzfoo{}r�z-j�0)rr�r�rangerr
rr�rryr�r�)rr��files�suffixr�r@rrrr�test_workers�s!
 

zCommandLineTests.test_workerszcompileall.compile_dirc
Csetjddtj|jdg��:tj�|j|j�|j	|j
ddd�WdQRXdS)Nzsys.argvrZz-j0r:rMrR)rrare�
executablerr6�mainr8rOr3rV)rr7rrr�test_workers_available_cores�s

z-CommandLineTests.test_workers_available_coresN)+r\r]r^�classmethodrurvr|r�r�r�r�r r�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�rrar�rrrrrk�sH
	
"

"


	rk�__main__)rer6�importlib.utilrrrnr1rr)r	r�r_rgrr�concurrent.futuresrr��ImportErrorZtestrZtest.supportrZTestCaserrbrkr\r�rrrr�<module>s2

z�M