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_compile.cpython-34.pyo

�
g fZ�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	Gdd�dej
�ZGdd�dej
�Ze
dkr�ej�ndS)�N)�support�
script_helperc@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$�Zejd%krd&d'�Znd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!e"j#d<d=��Z$d>d?�Z%d@dA�Z&dBdC�Z'dDdE�Z(e"j#dFdG��Z)dHdI�Z*dJS)K�
TestSpecificscCst|dd�dS)Nz<single>�single)�compile)�self�source�r	�6/opt/alt/python34/lib64/python3.4/test/test_compile.py�compile_singleszTestSpecifics.compile_singlecCs|jt|j|�dS)N)�assertRaises�SyntaxErrorr)rrr	r	r
�assertInvalidSinglesz!TestSpecifics.assertInvalidSinglecCs$tddd�tddd�dS)N�hiz<test>�execzhi
)r)rr	r	r
�test_no_ending_newlinesz$TestSpecifics.test_no_ending_newlinecCstddd�dS)N�z<test>r)r)rr	r	r
�
test_emptyszTestSpecifics.test_emptycCsDtddd�tddd�tddd�tddd�dS)Nz
z<test>r�
zhi
stuff
def f():
    pass
z(this_is
really_old_mac
def f():
    pass)r)rr	r	r
�test_other_newlinessz!TestSpecifics.test_other_newlinescCsR|jttddd�ddl}|j}t|dd�t|d|�dS)Nz
__debug__ = 1�?rr�	__debug__Zsure)rr
r�builtinsr�setattr)rr�prevr	r	r
�test_debug_assignments
	z#TestSpecifics.test_debug_assignmentcCsv|jttd�|jttd�|jttd�|jttd�|jttd�|jttd�dS)Nzlambda a,a:0zlambda a,a=1:0zlambda a=1,a=1:0zdef f(a, a): passzdef f(a = 0, a = 1): passzdef f(a): global a; a = 1)rr
�evalr)rr	r	r
�test_argument_handling'sz$TestSpecifics.test_argument_handlingcCs|jttddd�dS)Nz1+*3�filenamer)rr
r)rr	r	r
�test_syntax_error0szTestSpecifics.test_syntax_errorcCs|jttddd�dS)Nz	f(None=1)z<string>r)rr
r)rr	r	r
�test_none_keyword_arg3sz#TestSpecifics.test_none_keyword_argcCs|jttd�dS)Nzdef f(a): global a; a = 1)rr
r)rr	r	r
�test_duplicate_global_local6sz)TestSpecifics.test_duplicate_global_localcCs�Gdd�d�}|�}t�}td||�|j|jd�ytd||�Wntk
rpYnX|jd�td||�|j|jdtd	�f�td
||�|j|jd|f�td||�|j|jd|f�|jttd|�Gdd
�d
�}|�}|jttd||�Gdd�dt	�}|�}td||�|j|dd�dS)Nc@s:eZdZdZdd�Zdd�Zdd�ZdS)	zBTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.Mz9Test mapping interface versus possible calls from eval().cSs|dkrdSt�dS)N�a�)�KeyError)r�keyr	r	r
�__getitem__=szNTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.M.__getitem__cSs||f|_dS)N)�results)rr%�valuer	r	r
�__setitem__AszNTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.M.__setitem__cSs
td�S)N�xyz)�list)rr	r	r
�keysCszGTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.M.keysN)�__name__�
__module__�__qualname__�__doc__r&r)r,r	r	r	r
�M;sr1zz = a�zr#zz = bzDid not detect a KeyErrorz	z = dir()r*z
z = globals()zz = locals()c@seZdZdZdS)zBTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.AzNon-mappingN)r-r.r/r0r	r	r	r
�AXsr3c@seZdZdd�ZdS)zBTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.DcSs |dkrdStj||�S)Nr"r#)�dictr&)rr%r	r	r
r&`szNTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.D.__getitem__N)r-r.r/r&r	r	r	r
�D_sr5)r2r#)
�globalsr�assertEqualr'�	NameError�failr+r�	TypeErrorr4)rr1�m�gr3r5�dr	r	r
�)test_exec_with_general_mapping_for_locals9s0		

		z7TestSpecifics.test_exec_with_general_mapping_for_localscCsPddd}i}d|fd}t||�|j|dd�d�dS)	Nz	x = x or z-xi�	z�
def f(x):
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    # the expressions above have no effect, x == argument
    while x:
        x -= 1
        # EXTENDED_ARG/JUMP_ABSOLUTE here
    return x
�
�f�r)rr7)rZlongexprr<�coder	r	r
�test_extended_arghs

zTestSpecifics.test_extended_argcCs|jttd�dS)Nzdef f(a=1, b): pass)rr
r)rr	r	r
�test_argument_order�sz!TestSpecifics.test_argument_ordercCsP|jttd�|jttd�|jttd�|jttd�dS)NZ2ez2.0e+z1e-z3-4e/21)rr
r)rr	r	r
�test_float_literals�sz!TestSpecifics.test_float_literalscCsd}t|dd�dS)Nz
if 1:
    if 2:
        passz<string>r)r)r�sr	r	r
�test_indentation�szTestSpecifics.test_indentationcCs\djdgddg�}t|dd�}|j|jd�|j|jt��dS)Nr�
�Zspam�fnri)�joinrr7�co_firstlineno�	co_lnotab�bytes)rZs256�cor	r	r
�test_leading_newlines�sz#TestSpecifics.test_leading_newlinescCstx]ddddddddd	d
ddd
dddddddgD]}|jtt|�qCW|jtd�d�|jtd�d�|jtd�d�|jtd�d�|jtd�d�|jtd�d�|jtd�d�|jtd �d!�|jtd"�d#�|jtd$�d�|jtd%�d&�|jtd'�d�|jtd(�d�|jtd)�d*�|jtd+�d*�|jtd,�d*�|jtd-�d*�|jtd.�d/�|jtd0�d1�|jtd2�d3�|jtd4�d5�|jtd6�d<�|jtd8�d9�|jtd:�d=�dS)>NZ077787Z0xjz0x.Z0eZ090000000000000Z080000000000000Z000000000000009Z000000000000008Z0b42Z0BADCAFEZ0o123456789z0b1.1z0o4.2Z0b101j2Z0o153j2Z0b100e1Z0o777e1Z0777Z000777Z000000000000007Z0xff�z0777.i	z0777.0Z8000000000000000000000000000000000000000000000000000777e0Z0777e1iZZ0e0rz	0000e-012z09.5g#@Z0777jyH�@Z000Z00jyz00.0Z0e3z090000000000000.g聰v�Bz&090000000000000.0000000000000000000000Z090000000000000e0z090000000000000e-0Z090000000000000jy聰v�Bz000000000000008.g @z000000000000009.g"@Z0b101010�*z-0b000000000010�Z0o777i�z
-0o0000010����i����)rr
rr7)r�argr	r	r
�!test_literals_with_leading_zeroes�s<	z/TestSpecifics.test_literals_with_leading_zeroescCs�tjdkrHd}|jt|�d�|jtd|�d�nUtjdkr�d}|jt|�d�|jtd|�d
�n
|jd�|jtd	tjd
�t�|jtd	tjd�t�dS)Ni���Z
0xffffffffl���-l����Z0xffffffffffffffffl����z)How many bits *does* this machine have???z%s�rSl������l��������)�sys�maxsizer7rr9�assertIsInstance�int)rZall_one_bitsr	r	r
�test_unary_minus�s
"zTestSpecifics.test_unary_minusl����c
Csmd}d}d}d}d	}d
}d}d}x6|jjjD]%}	|	dk	r@|j|	t�q@q@WdS)
N��������r_l����r`l����ral����rbl��������)�test_32_63_bit_values�__code__�	co_constsr\r])
rr"�b�cr=�er@r<�hZvariabler	r	r
rc�sz#TestSpecifics.test_32_63_bit_valuescCs6dp	d\}}|j|d�|j|d�dS)NrY���)rYrjrj)rjrYrj)r7)r�i�jr	r	r
�test_sequence_unpacking_error�sz+TestSpecifics.test_sequence_unpacking_errorcCs{ddddddddd	d
ddg}xJ|D]B}|d
7}|jtt|dd�|jtt|dd�q1WdS)NzNone = 0z	None += 0z__builtins__.None = 0zdef None(): passzclass None: passz(a, None) = 0, 0zfor None in range(10): passzdef f(None): passzimport Nonezimport x as Nonezfrom x import Nonezfrom x import y as NonerH�tmprr)rr
r)rZstmts�stmtr	r	r
�test_none_assignment�s 	

z"TestSpecifics.test_none_assignmentcCs�ddddddddd	d
ddd
ddg}ddddddddddddddddd d!d"d#d$g}x|D]}t|d%d&�qWx'|D]}|jtt|d%d&�q�WdS)'Nz
import syszimport os, syszimport os as barzimport os.path as barz0from __future__ import nested_scopes, generatorsz2from __future__ import (nested_scopes,
generators)z3from __future__ import (nested_scopes,
generators,)z%from sys import stdin, stderr, stdoutz'from sys import (stdin, stderr,
stdout)z(from sys import (stdin, stderr,
stdout,)z(from sys import (stdin
, stderr, stdout)z)from sys import (stdin
, stderr, stdout,)z7from sys import stdin as si, stdout as so, stderr as sez9from sys import (stdin as si, stdout as so, stderr as se)z:from sys import (stdin as si, stdout as so, stderr as se,)zimport (os, sys)zimport (os), (sys)zimport ((os), (sys))zimport (syszimport sys)zimport (os,)zimport os As barzimport os.path a barzfrom sys import stdin As stdoutzfrom sys import stdin a stdoutzfrom (sys) import stdinz%from __future__ import (nested_scopesz%from __future__ import nested_scopes)z0from __future__ import nested_scopes,
generatorszfrom sys import (stdinzfrom sys import stdin)z%from sys import stdin, stdout,
stderrzfrom sys import stdin siz)from sys import stdin,from sys import (*)z(from sys import (stdin,, stdout, stderr)z from sys import (stdin, stdout),rnr)rrr
)rZsucceedr9ror	r	r
�test_import�sP		

zTestSpecifics.test_importcCsAdd�}|�\}}|jt|j�t|j��dS)NcSs(ddd�}ddd�}||fS)NrYcSs|S)Nr	)�xr	r	r
�<lambda>+szITestSpecifics.test_for_distinct_code_objects.<locals>.f.<locals>.<lambda>rScSs|S)Nr	)rrr	r	r
rs,sr	)�f1�f2r	r	r
r@*sz7TestSpecifics.test_for_distinct_code_objects.<locals>.f)ZassertNotEqual�idrd)rr@rtrur	r	r
�test_for_distinct_code_objects(sz,TestSpecifics.test_for_distinct_code_objectscCs dd�}|j|j�dS)NcSsdS)NZfoor	r	r	r	r
rs2sz/TestSpecifics.test_lambda_doc.<locals>.<lambda>)ZassertIsNoner0)r�lr	r	r
�test_lambda_doc1szTestSpecifics.test_lambda_doccCsd}|jtt|dd�d}t|dd�|jt|�d�d}|jt|�d�d}|jt|�d�d	}|jt|�d�d
}|jt|�d�d}|jt|�d�d
}|jt|�d�d}|jt|�d�dS)Ns## -*- coding: badencoding -*-
pass
rnru%# -*- coding: badencoding -*-
"¤"
u¤u"¤"
s"¤"
�¤s# -*- coding: latin1 -*-
"¤"
s# -*- coding: utf-8 -*-
"¤"
s"# -*- coding: iso8859-15 -*-
"¤"
u€u*"""\
# -*- coding: iso8859-15 -*-
¤"""
u!# -*- coding: iso8859-15 -*-
¤s("""\
# -*- coding: iso8859-15 -*-
¤"""
u# -*- coding: iso8859-15 -*-
¤)rr
rr7r)rrBr	r	r
�
test_encoding5s&zTestSpecifics.test_encodingcCsIGdd�dt�}|�}d|d<|j|dd�|dd7<|j|dd�|d=|jd|�d|d<|j|dd�|d	d7<|j|d
d�|d=|jd|�d|dd�<|j|dd�d�|dd�d7<|j|dd�d�|dd�=|jtdd�|�d|dd�dd�f<|j|dd�dd�fd�|dd�dd�fd7<|j|dd�dd�fd�|dd�dd�f=|jtdd�tdd�f|�d|ddd�<|j|ddd�d�|ddd�d7<|j|ddd�d�|ddd�=|jtddd�|�d|ddd�ddd�f<|j|ddd�ddd�fd�|ddd�ddd�fd7<|j|ddd�ddd�fd�|ddd�ddd�f=|jtddd�tddd�f|�d|d<|j|dd�|dd7<|j|dd�|d=|jt|�d|d
<|j|dd�|dd7<|j|dd�|d=|jttf|�dS)Nc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)z.TestSpecifics.test_subscripts.<locals>.str_mapcSs
i|_dS)N)�data)rr	r	r
�__init__Nsz7TestSpecifics.test_subscripts.<locals>.str_map.__init__cSs|jt|�S)N)r|�str)rr%r	r	r
r&Psz:TestSpecifics.test_subscripts.<locals>.str_map.__getitem__cSs||jt|�<dS)N)r|r~)rr%r(r	r	r
r)Rsz:TestSpecifics.test_subscripts.<locals>.str_map.__setitem__cSs|jt|�=dS)N)r|r~)rr%r	r	r
�__delitem__Tsz:TestSpecifics.test_subscripts.<locals>.str_map.__delitem__cSst|�|jkS)N)r~r|)rr%r	r	r
�__contains__Vsz;TestSpecifics.test_subscripts.<locals>.str_map.__contains__N)r-r.r/r}r&r)rr�r	r	r	r
�str_mapMs
r�rYrS�.)rYrY)rYrY)rYrY)rYrY)rYrY)rYrY)..)..)..)..)..)�objectr7ZassertNotIn�slice�Ellipsis)rr�r=r	r	r
�test_subscriptsJsd	


& &(",&,.

zTestSpecifics.test_subscriptscCs�d}|djdd�td�D��;}|jtt|dd�d}|djdd�td	�D��;}t|dd�dS)
Nzdef f(%s): passz, css|]}d||fVqdS)za%d:%dNr	)�.0rkr	r	r
�	<genexpr>�sz6TestSpecifics.test_annotation_limit.<locals>.<genexpr>rIrrcss|]}d||fVqdS)za%d:%dNr	)r�rkr	r	r
r��srQ)rK�rangerr
r)rrFr	r	r
�test_annotation_limit�s&&z#TestSpecifics.test_annotation_limitcCs{Gdd�d�}|jd|jjj�|jd|jjj�|jd|jjj�|jd|jjj�dS)Nc@seZdZdd�ZdS)z&TestSpecifics.test_mangling.<locals>.AcSs(d}d}ddl}ddl}dS)NrYrSr)�_A__mangled_modZ__package__.module)�_A__mangled�__not_mangled__r��__package__r	r	r
r@�sz(TestSpecifics.test_mangling.<locals>.A.fN)r-r.r/r@r	r	r	r
r3�sr3r�r�r�r�)�assertInr@rd�co_varnames)rr3r	r	r
�
test_mangling�s
zTestSpecifics.test_manglingc	Cs�t}|j�jd�r.|dd�}nt|d��}|j�}WdQXddgddgd	d
gddg||gg}x�|D]�\}}t|d
|d�}t|d|dtj�}|jt	|�tj
k�t|d|d�}|j||�|j|jd|�q�Wtdddtj�}|j
tt|dd�|j
tttj�dd�tj
�}tj�g|_|j
tt|dd�dS)N�pyc�pyorY�rz<assign>zx = 5z	<ifblock>zif True:
    pass
z
<forblock>z!for n in [1, 2, 3]:
    print(n)
z	<deffunc>zdef foo():
    pass
foo()
z%s1rz%s2z%s3zprint(1)z<string>z<ast>r)r�r�rj)�__file__�lower�endswith�open�readr�_astZ
PyCF_ONLY_ASTZ
assertTrue�typeZModuler7�co_filenamerr:ZIfZBoolOpZbody)	rZfnamer@Z	fcontentsZsample_coderBZco1ZastZco2r	r	r
�test_compile_ast�s.				zTestSpecifics.test_compile_astcCs[d}t|dd�}x<|jD]1}t|tj�r"|j|j|j�q"q"WdS)Nzdef f(): pass
def g(): passZmyfiler)rre�
isinstance�types�CodeTypeZassertIsr�)rrFrg�objr	r	r
�test_same_filename_used�s
z%TestSpecifics.test_same_filename_usedcCs�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�|jd�|jd�|jd
�|jd�dS)Nz1 + 2z
1 + 2z1 + 2
z1 + 2

z1 + 2		
z1 + 2		
        z1 + 2 # one plus twoz1; 2zimport sys; syszdef f():
   passzwhile False:
   passz
if x:
   f(x)zif x:
   f(x)
else:
   g(x)zclass T:
   pass)r)rr	r	r
�test_single_statement�s












z#TestSpecifics.test_single_statementcCsl|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�dS)	Nz1
2z
def f(): passza = 13
b = 187zdel x
del yzf()
g()zf()
# blah
blah()zf()
xy # blah
blah()zx = 5 # comment
x = 6
)r)rr	r	r
�test_bad_single_statement�s






z'TestSpecifics.test_bad_single_statementcCsd}tj��T}tjj|d�}t|d��}|j|�WdQXtj|�d}WdQX|j	d|j
�dS)Ns0000
00000000000

�
zbad.py�wbrs	Non-UTF-8)�tempfile�TemporaryDirectory�os�pathrKr��writer�run_python_until_endr��err)r�src�tmpdrJ�fp�resr	r	r
�"test_particularly_evil_undecodable�sz0TestSpecifics.test_particularly_evil_undecodablecCsd}tj��T}tjj|d�}t|d��}|j|�WdQXtj|�d}WdQX|j	d|j
�dS)Ns#
#�
zbad.pyr�rs	Non-UTF-8)r�r�r�r�rKr�r�rr�r�r�)rr�r�rJr�r�r	r	r
�$test_yet_more_evil_still_undecodable�sz2TestSpecifics.test_yet_more_evil_still_undecodablecsptj�d�t�d�����fdd�}|dd�|dd�|dd�|dd	�dS)
Nr�g�?c	sk||�}�j|�||�}dj||��}�jtd|���j|�WdQXdS)NzCompiling ({!r} + {!r} * {})�msg)r�formatr�RuntimeError)�prefixZrepeatedZ	expect_okZbrokenZdetails)�
fail_depthr�
success_depthr	r
�check_limits
z@TestSpecifics.test_compiler_recursion_limit.<locals>.check_limitr"z()z.bz[0]z*a)rZ�getrecursionlimitr])rr�r	)r�rr�r
�test_compiler_recursion_limits		


z+TestSpecifics.test_compiler_recursion_limitcCsd|jtd��tddd�WdQX|jtd��ttd�dd�WdQXttd�dd
�dd�}|jt|�d�ttd�dd�dd�}|jt|�d�ttd	�dd�dd�}|jt|�d�|jttd�dd��d�t�}ttd
�dd�|�|j|dd�dS)Nzcannot contain nullZ123z<dummy>rs123rY�s1234s$23$sax = 123rrr#rjrjrjrjrj)ZassertRaisesRegex�	Exceptionr�
memoryviewr7rr4r)rrB�	namespacer	r	r
�test_null_terminateds"""&	z"TestSpecifics.test_null_terminatedN)+r-r.r/rrrrrrrrr r!r>rCrDrErGrPrWr^rZr[rcrmrprqrwryr{r�r�r�r�rZcpython_onlyr�r�r�r�r�r�r�r	r	r	r
r
sJ	/!/	H

#


rc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�
TestStackSize�dcCs\t|t�r$t|dd�}ntjtjt|j���}|j|j	|�dS)Nz<foo>r)
r�r~r�mathZceil�log�len�co_codeZassertLessEqual�co_stacksize)rrBZmax_sizer	r	r
�check_stack_size;s!zTestStackSize.check_stack_sizecCs|jd|jd�dS)Nzx and rr)r��N)rr	r	r
�test_andCszTestStackSize.test_andcCs|jd|jd�dS)Nzx or rr)r�r�)rr	r	r
�test_orFszTestStackSize.test_orcCs|jd|jd�dS)Nzx and x or rr)r�r�)rr	r	r
�test_and_orIszTestStackSize.test_and_orcCs|jd|jd�dS)Nzx < rr)r�r�)rr	r	r
�test_chained_comparisonLsz%TestStackSize.test_chained_comparisoncCs|jd|jd�dS)Nzx if x else rr)r�r�)rr	r	r
�test_if_elseOszTestStackSize.test_if_elsecCs|jd|jd�dS)Nzx + rr)r�r�)rr	r	r
�
test_binopRszTestStackSize.test_binopcCs(d}|d|j7}|j|�dS)Nz
def f(x):
z   x and x
)r�r�)rrBr	r	r
�
test_func_andUszTestStackSize.test_func_andN)r-r.r/r�r�r�r�r�r�r�r�r�r	r	r	r
r�5sr��__main__)r�r�ZunittestrZr�r�r�ZtestrrZTestCaserr�r-�mainr	r	r	r
�<module>s��-&