Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_compileall.cpython-34.pyc

�
f f�B�@sddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZGdd�dej�ZGdd�dej�ZGdd�dej�Zed	kr
ej�ndS)
�N)�support�
script_helperc@s�eZdZdd�Zdd�Zdd�Zejee	d�d�d	d
��Z
dd�Zd
d�Zdd�Z
dd�Zdd�ZdS)�CompileallTestsc	Cstj�|_tjj|jd�|_tjj	|j�|_
t|jd��}|jd�WdQXtjj|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/python34/lib64/python3.4/test/test_compileall.py�setUpszCompileallTests.setUpcCstj|j�dS)N)r�rmtreer)rrrr�tearDown szCompileallTests.tearDownc
Csjt|jd��}|jd�}WdQXttj|j�j�}tj	dt
jj|�}||fS)N�rb�z<4sl)
rr�read�intr	�statr�st_mtime�struct�packr
r�MAGIC_NUMBER)rr�data�mtimeZcomparerrrr(#s
zCompileallTests.datar#ztest needs os.stat()cCs�tj|j�|j|j��t|jd��#}|j�t|�d�}WdQXt|jd��!}|j	|�|j	|�WdQX|j
|j��tj|j
dddd�|j|j��dS)zOCheck that compileall recreates bytecode when the new metadata is
        used.rN�wb�forceF�quietT)�
py_compile�compiler�assertEqualr(rrr!�lenr�assertNotEqual�
compileall�compile_dirr�
assertTrue)rZmetadatarZbcrrr�recreation_check*s"
z CompileallTests.recreation_checkcCs&|jtjdtjjd��dS)Nz<4sl�)r5r%r&r
rr')rrrr�
test_mtime9szCompileallTests.test_mtimecCs|jd�dS)Ns)r5)rrrr�test_magic_number>sz!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	�unlinkr2�compile_filerr4r
�isfiler3r)r�fnrrr�test_compile_filesBs	z"CompileallTests.test_compile_filescCs�tjj|jd�}tjj|d�}tj|�t|d��WdQXtj|�|jtjj	tjj|d���dS)Nr(rr�__pycache__)
r	r
rrrrr2r:�assertFalse�exists)rZdata_dirZ	data_filerrr�test_no_pycache_in_non_packageSs

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)Nr6rr,T�optimize�debug_override)�	__debug__r2r3rr
rrrr4r	r
r;rr)rrB�cachedZcached2Zcached3rrr�
test_optimize_s


zCompileallTests.test_optimizeN)�__name__�
__module__�__qualname__rrr(�unittestZ
skipUnless�hasattrr	r5r7r8r=rArFrrrrrs'rc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�EncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.c	Csitj�|_tjj|jd�|_t|jddd��!}|jd�|jd�WdQXdS)Nz_test.pyr�encodingzutf-8z# -*- coding: utf-8 -*-
u
print u"€"
)	rrrr	r
rrrr)rrrrrrss

zEncodingTest.setUpcCstj|j�dS)N)rrr)rrrrrzszEncodingTest.tearDowncCsLz;tj}tjtj�dd�t_tj|j�Wd|t_XdS)NrM�ascii)�sys�stdout�io�
TextIOWrapper�BytesIOr2r3r)rZorig_stdoutrrr�
test_error}s
	zEncodingTest.test_errorN)rGrHrI�__doc__rrrTrrrrrLosrLc@s�eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�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�Z d:d;�Z!d<d=�Z"d>d?�Z#d@S)A�CommandLineTestszTest compileall's CLI.cCs�x�ttjjtj�D]�}d}tj|�d}|d}zhyH|j�sg|j�d}n|j	d��}|j
d�WdQXWntk
r�d}PYnXWdtj
t|��|r�|j�nXqWd}||_dS)NFr>ztest.tryTrz# for test_compileall)�filterr	r
�isdirrO�pathlibZPathZis_dirrrr�OSErrorrr9�str�rmdir�_sys_path_writable)�clsr
Zdirectory_createdrrZsys_path_writablerrr�
setUpClass�s$

	

zCommandLineTests.setUpClasscCs|jstjd��ndS)Nz(not all entries on sys.path are writable)r]rJZSkipTest)rrrr�_skip_if_sys_path_not_writable�s	z/CommandLineTests._skip_if_sys_path_not_writablecCsUdg}tjjr=|jidd6dd6tjj�n|ddgt|�S)Nz-Sz-Or6z-OO�z-mr2)rO�flagsrB�append�list)r�argsZinterp_argsrrr�
_get_run_args�s	(zCommandLineTests._get_run_argscOs8tj|j|�|�\}}}|jd|�|S)N�)r�assert_python_okrfr/)rre�env_vars�rc�out�errrrr�assertRunOK�szCommandLineTests.assertRunOKcOs1tj|j|�|�\}}}|||fS)N)r�assert_python_failurerf)rrerirjrkrlrrr�assertRunNotOK�szCommandLineTests.assertRunNotOKcCs/tjj|�}|jtjj|��dS)N)r
rrr4r	r
r@)rr<r
rrr�assertCompiled�szCommandLineTests.assertCompiledcCs/tjj|�}|jtjj|��dS)N)r
rrr?r	r
r@)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)NZfoor>�__init__�Zbar)rrrZ
addCleanuprrr	r
r�pkgdirr�pkgdir_cachedirr�make_script�initfn�barfn)rrrrr�szCommandLineTests.setUpcCsf|j�tj|jdd�}|jd|j�|j|�|j|j�|j|j�dS)N�bazrs�
PYTHONPATH)	r`rrvrrmrprqrwrx)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)Nryrsrz�<raz-f)r`rrvrrmr
rrr	�utime�timer#r$r/r1)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)NryrsrzsListing z-q)r`rrvrrmZassertInZassertNotIn)r�noisyr,rrr� test_no_args_respects_quiet_flag�s
z1CommandLineTests.test_no_args_respects_quiet_flagZnormal�pycrBZpyoz-OZdoubleoptimizez-OOcs�tj|ddd|jg�|jtjj|j��t�fdd�d
D��}|j	ttj
|j��|�|j�fdd	�tj
|j�D��dS)Nz-mr2z-qc3s'|]}|jtjj��VqdS)N)�formatrO�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�)rrhrtr4r	r
r@ru�sortedr/�listdirr?)rr��switch�expectedr)r�r�f�s	
"zCommandLineTests.fZtest_pep3147_paths_cCs�|jdd|j�|jtjj|j��tr>dnd}tdd|dd|g�}|j	ttj
|j��|�dS)Nz-bz-q�c�oz__init__.pyzbar.py)rmrtr?r	r
r@rurDr�r/r�)rZoptr�rrr�test_legacy_paths�sz"CommandLineTests.test_legacy_pathscCs�|jd|j�|jtjj|j��tjj|jd�}|jtjj|��|jd|j�|jtjj|j��|jtjj|��dS)Nz-qr>)	rmrtr4r	r
r@rurr?)rZ
cachecachedirrrr�test_multiple_runssz#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}raz-f)
rmrtr
rrrxr	r~rr#r$r/r1)rr�r)r�rrr�
test_forces!zCommandLineTests.test_forcecCs�tjj|jd�}tj|�tj|dd�}tj|dd�}|jdd|j�|j|�|j	tjj
tjj|d���|jd|j�|j|�|j|�dS)NZspamrrrsZhamz-qz-lr>)r	r
rrtrrrvrmrqr?r@rp)rZ
subpackageZ	subinitfnZhamfnrrr�test_recursion_control$s

(
z'CommandLineTests.test_recursion_controlcCsK|j|j�}|jd|j�}|jd|�|jd|�dS)Nz-qrg)rmrtr1r/)rr�r,rrr�
test_quiet0szCommandLineTests.test_quietcCs=|jddd|j�|j|j�|j|j�dS)Nz-qz-xz
ba[^\\/]*$)rmrtrqrxrprw)rrrr�test_regexp6szCommandLineTests.test_regexpcCs�tjj|jd�}tj|�tj|dd�}tj|dd�}|jd|j|�|j	|j
�|j	|j�|j	|�|j	|�dS)NZfoo2rrrsZbar2z-q)r	r
rrrrrvrmrtrprwrx)rZpkgdir2Zinit2fnZbar2fnrrr�test_multiple_dirs;s

z#CommandLineTests.test_multiple_dirscCsNtj|jdd�|jddd|j�\}}}|j|d�dS)NZcrunchyfrogz
bad(syntaxz-qz-d�dinsdalesFile "dinsdale)rrvrtro�assertRegex)rrjrkrlrrr�test_d_compile_errorFs$z%CommandLineTests.test_d_compile_errorcCs�tj|jdd�}|jddd|j�tj|jdd�}tjj|�}tj|tj	j
|jd��tj|�tj|d	d
�\}}}|j
|d�dS)Nryzraise Exceptionz-qz-dr��bingz
import bazzbaz.pycZ
__isolatedFsFile "dinsdale)rrvrtrmr
rrr	�renamer
r�removernr�)rr{r<r�rjrkrlrrr�test_d_runtime_errorKs"
z%CommandLineTests.test_d_runtime_errorcCs|jdtjj|jd�|j�\}}}|j|d�|j|d�|jtjj	t
jj|j
���dS)Nz-i�
nosuchfilesrror.*nosuchfiles	Traceback)ror	r
rrrtr�ZassertNotRegexr?r@r
rrru)rrjrkrlrrr�test_include_bad_fileUs-z&CommandLineTests.test_include_bad_filecCs3tj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}ttjj|jd�d��S}|jtjj|jd�tj	�|jtjj|jd	�tj	�WdQX|j
d
tjj|jd�|�|j|�|j|�|j|�|j|�dS)N�f1rs�f2�f3�f4�l1rzf1.pyzf2.pyz-i)
rrvrtrr	r
rrr�lineseprmrprq)rr�r�r�r�r�rrr�test_include_file_with_arg]s$&,%


z+CommandLineTests.test_include_file_with_argcCs
tj|jdd�}tj|jdd�}tj|jdd�}tj|jdd�}ttjj|jd�d��-}|jtjj|jd�tj	�WdQX|j
d	tjj|jd��|j|�|j|�|j|�|j|�dS)
Nr�rsr�r�r�r�rzf2.pyz-i)
rrvrtrr	r
rrrr�rmrqrp)rr�r�r�r�r�rrr�test_include_file_no_argks$,"


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�rsr�r�r�z-i�-rN)
rrvrtZspawn_pythonrf�stdinrr	r��encodeZkill_pythonrqrp)rr�r�r�r��prrr�test_include_on_stdinxs" 



z&CommandLineTests.test_include_on_stdincCs�tj|jdd�}|jd|j||j�\}}}|j|d�|j|�|j|j�|j|j�dS)Nr�zsyntax(errorr�srror)	rrvrtrorwrxr�rqrp)rZbingfnrjrkrlrrr�!test_compiles_as_much_as_possible�s
z2CommandLineTests.test_compiles_as_much_as_possiblecCs#|jd�}|j|d�dS)NZbadfilenamesCan't list 'badfilename')rmr�)rrkrrr�!test_invalid_arg_produces_message�sz2CommandLineTests.test_invalid_arg_produces_messageN)$rGrHrIrU�classmethodr_r`rfrmrorprqrr|r�r��namer�r�r��localsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrV�sB
	
"



	rV�__main__)rOr2�importlib.utilr
r	rYr-rr%rrrJrQZtestrrZTestCaserrLrVrG�mainrrrr�<module>s$_�