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_ast.cpython-35.pyc



��YfU��7@szddlZddlZddlZddlZddlZddlmZdd�Zddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/g+Zd0gZ	dd1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGgZ
GdHdI�dIej�ZGdJdK�dKej�Z
GdLdM�dMej�ZdNdO�ZdPdQdRdfdSdRdfdffgfdPdTdRdfdUdVgdggdgfdWdRdXffggdfgfdPdTdRdfdUdVdYdRdZfd[dfgdggdgfdWdRd\ffggdfgfdPdTdRdfdUdVdYdRdZfd[dfgdggdd]dRd^fdfgfdWdRd_ffggdfgfdPdTdRdfdUdVgdYdRd`fdadfggdgfdWdRdbffggdfgfdPdTdRdfdUdVgdggdYdRd^fdcdfgfdWdRddffggdfgfdPdTdRdfdUdVdYdRdZfd[dfdYdRdXfdedfdYdRdbfdfdfdYdRdgfdhdfdYdRdifdjdfgdYdRdkfdadfdYdRdlfdUdfgd]dRdmfdnfgdYdRdofdcdfd]dRdpfdRfdSdRdqfdfdrdRdsfgdtffdudRdvfggfgfdWdRdwffggdfgfdPdxdRdfdyggdWdRd^ffggfgfdPdxdRdfdydzdRd^fd{dtffggdWdRddffggfgfdPdTdRdfdUdVgdggdgfd|dRd^fd]dRd}fdRffggdfgfdPd~dRdfdzdRdfdAd�ffgfgfdPd�dRdfdzdRdfdAd�ffgd]dRdfdRffgfdPd�dRdfdzdRdfdAd�ffd�fd]dRd�fdRffgfdPd�dRdfdzdRdfdAd�ffdzdRdXfdAdtffdWdRdpffggfgfdPd�dRdfdzdRdZfdAdtffdWdRd^ffggfgfdPd�dRdfdzdRd�fdAdtffdWdRd�ffggfgfdPd�dRdfd�dzdRd�fd�dtffdzdRd\fd�d�fffgdWdRd�ffgfgfdPd�dRdfd�dzdRd�fd�dtffdzdRd\fd�d�fffd�dzdRd�fd�dtffdzdRd�fd�d�fffgdWdRd�ffgfgfdPd�dRdfd�dRdZfdzdRdZfd�dtffd�dRdqfd�fggfdfgfdPd�dRdfdWd�d�ffgd�d�dfdzd�d`fd�dtffddWdd�ffgfgggfgfdPd�dRdfdWd�d�ffgggdWdd�ffgfgfdPd�dRdfdzdRd`fdAdtffdfgfdPd�dRdfd�d�dfgfgfdPd�dRdfd�d�dAdfgdfgfdPd�dRdfdAgfgfdPdQdRdfd]dRdfdRffgfdPdWdRdffgfdPd�dRdfdzdRdfdAd�ffdzdRdXfdAdtffd�dRdpffggfgfdPd�dRdfdzdRdfdAd�ffdzdRdXfdAdtffd�dRdpffggfgfdPd�dRdfd�dRdfdzdRdfd[d�ffdzdRdZfded�ffgd�ffdzdRdpfdfdtffdWdRdbffggfgfdPdQdRdfd�dRdRfd�dRd�fdzdRd�fd[dtffdzdRdfdedtffgdtffd�d�dRdpfdzdRdpfd[d�ffdzdRd�fded�ffgd�ffdzdRd�fdfdtffgfgffgfdPdQdRdfd�dRdRfd�dRd�fdzdRd�fd[dtffdzdRdfdedtffgdtffd�d�dRdpfdzdRdpfd[d�ffdzdRd�fded�ffgd�ffdzdRd�fdfdtffgfgffgfdPdQdRdfd�dRdRfd�dRd�fdzdRd�fd[dtffdzdRdfdedtffgdtffd�d�dRd_fdzdRd_fd[d�ffdzdRdbfded�ffgd�ffdzdRd�fdfdtffgfgffgfdPdQdRdfd�d�dfd�d�dfdzd�dfd�dtffdzd�d`fd�dtffgdtffd�d�d^dfdzd^dfd�d�ffdzd\dfd�d�ffgd�ffdzd\d\fd�dtffgfgffgfdPdQdRdfd�dRdfdzdRdRfd[dtffdzdRd�fdedtffd�dzdRdpfd�d�ffdzdRdqfd�dtffgfd�dzdRdgfd�d�ffdzdRd�fd�dtffdzdRd�fd�dtffgfgffgfdPdQdRdfd�dRdfdzdRdRfd[dtffdzdRd�fdedtffd�d�dRdpfdzdRdpfdAd�ffdzdRd�fd�d�ffgd�ffdzdRd�fd�dtffgfgffgfdPdQdRdfd�dRdfdzdRdRfd�dtffd�dzdRd`fd�d�ffdzdRd_fd�dtffdzdRddfd�dtffgfgffgfdPdQdRdfd�dRdfdzdRdRfd�dtffd�d�dRd`fdzdRd`fd�d�ffdzdRdXfd�d�ffgd�ffdzdRdbfd�dtffgfgffgfdPd�dRdZfdUdVgdggdgfdQd�dRfd�d�dRfd�d�d`fdzd�d`fd�dtffggfffggdfgfdPd�dRdZfdUdVgdggdgfd�d�d`fdzd�dpfdjd�ffdzd�dqfd�dtffdQd�d�fd]d�d�fdRffgdQd�d`fd]d�d`fd�ffgfggdfgfdPd�dRdZfdUdVgdggdgfd�d�d`fd�dzd�d_fd[dtffdzd�ddfded�fffgdQd�d�fd]d�d�fdRffgfggdfgfdPdQdRdfdudRdfdd]dRd\fd�fgdudRd�fd]dRdfdRfgd]dRdZfd�fgfd]dRd_fd�fgffgfdPdQdRdfd�dRdfd�dRdRfd�dRd�fd]dRd�fdRfd]dRdZfd�fgfdtffd]dRd\fd�fgffgfg+Zd�dQdRdfd�dRdfd]dRdfdRfd�fd]dRd�fd�fffgfgZd�dSdRdfdffd�d�dRdfd�fdzdRdfd[dtffdzdRdZfdedtffgffd�d�dRdfdzdRdfd[dtffd�fdzdRdfdedtffffd�d�dRdfd�fdzdRdfdAdtffffd�d�dRdfdVgdggdgfdSdRd`fdfffd�dudRdfd]dRd�fdRfgd]dRdfd�fgffd�dudRdfggffd�d�dRdfdSdRdRfdfgffd�dudRdfd]d�dZfdRfgd]dd\fd�fgffd�d�dRdRfdzdRdRfd[dtffd�dzdRd`fded�ffdzdRd_fdfdtffdzdRddfdhdtffgfgffd�d�dRdRfdzdRdRfd[dtffd�dzdRd`fded�ffdzdRd_fdfdtffdzdRddfdhdtffgfgffd�d�dRdfd]dRdfdRfd�fd�fgd]dRdfd�fd]dRd^fd�fgffd�d�dRdfdzdRdfdUdtffd]dRd�fdRfd]dRdfd�fd�dRd\fdzdRdpfdhdtffdtffgd�dfd]dRd^fd�ffd�ddzdRd}fdjdtfffgffd�d]dRdfd\ffd�d�dRdfd�ffd�d�dRdfdzdRdfd[dtffdedtfffd�d�dRdfdzdRdfd[dtffd�dzdRd�fdedtffdzdRdfdfdtffdfdtfffd�dzdRdfdAdtfffd�drdRdfd]dRdRfdRfd]dRd�fd�fd]dRd�fd�fgdtfffd�drdRdfgdtfffd�d�dRdfd]dRdfdRfd]dRd�fd�fd]dRdfd�fgdtfffd�d�dRdRfd]dRdRfdRfd]dRd�fd�fd]dRd�fd�fgdtfffd�d�dRdfgdtfffd�d�dRdfd�dRdfd�dRdfd�dRdfdzdRdfd[dtffdedtffdfdtffdhdtffd�dRd^fd�dRd^fdzdRd^fd[dtffdedtffd�d]dRd_fdRfd]dRdbfd�fdfdtffggffgZe�dS)��N)�supportcCs�|dks$t|tttf�r(|St|t�rHdd�|D�S|jjg}t|d�r�t|d�r�|j|j	|j
f�|jdkr�t|�Sx-|jD]"}|jt
t||���q�Wt|�S)NcSsg|]}t|��qS�)�to_tuple)�.0�err�2/opt/alt/python35/lib64/python3.5/test/test_ast.py�
<listcomp>
s	zto_tuple.<locals>.<listcomp>�lineno�
col_offset)�
isinstance�str�int�complex�list�	__class__�__name__�hasattr�appendr	r
�_fields�tupler�getattr)�t�result�frrrr	s$
 r�Nonez
def f(): passzdef f(a): passzdef f(a=0): passzdef f(*args): passzdef f(**kwargs): passz>def f(a, b=1, c=None, d=[], e={}, *args, f=42, **kwargs): passzclass C:passzclass C(object): passzdef f():return 1zdel vzv = 1zv += 1zfor v in v:passzwhile v:passz	if v:passzwith x as y: passzwith x as y, z as q: passzraise Exception('string')z$try:
  pass
except Exception:
  passztry:
  pass
finally:
  passzassert vz
import syszfrom sys import vzglobal v�1�passzfor v in v:breakzfor v in v:continuezfor a,b in c: passz[(a,b) for a,b in c]z((a,b) for a,b in c)z((a,b) for (a,b) in c)zL(
    (
    Aa
    ,
       Bb
    )
    for
    Aa
    ,
    Bb in Cc
    )z"{a : b for w in x for m in p if g}z{a : b for v,w in x}z{r for l in x if g}z{r for l,m in x}z!async def f():
 await something()z,async def f():
 async for e in i: 1
 else: 2z$async def f():
 async with a as b: 1z{**{1:2}, 2:3}z{*{1, 2}, 3}z1+2za and bza + bznot vzlambda:Nonez{ 1:2 }z{}z{None,}z&{
      1
        :
          2
     }z[a for b in c if d]z(a for b in c if d)z	1 < 2 < 3zf(1,2,c=3,*d,**e)Z10z'string'za.bza[b:c]�vz[1,2,3]z[]z1,2,3z(1,2,3)z()za.b.c.d(a.b[1:2])c@seZdZdd�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$�Zd%d&�Zd'd(�Zd)S)*�	AST_TestscCs�t|tj�s"|jdkr&dSt|tjtjtjf�r~|j|jf}|j	||k�|j|jf}xo|jD]d}t
||�}t|t�r�x=|D]}|j||�q�Wq�|dk	r�|j||�q�WdS)N)
r�ast�ASTr�expr�stmtZ
excepthandlerr	r
�
assertTruerr�_assertTrueorder)�selfZast_nodeZ
parent_posZnode_pos�name�valueZchildrrrr$�s"!
zAST_Tests._assertTrueordercCs�tj�}|j|jf�d|_|j|jd�|j|jdd�|jt��|jWdQRX|jt	��tjd�WdQRXdS)N�*�foobar�)
rr �assertEqualrr)�__dict__�assertRaises�AttributeError�vararg�	TypeError)r%�xrrr�test_AST_objects�s	zAST_Tests.test_AST_objectscCsjGdd�d�}tj�}|�|_||j_tj|j�}~tj�|j|��dS)Nc@seZdZdS)z0AST_Tests.test_AST_garbage_collection.<locals>.XN)r�
__module__�__qualname__rrrr�X�sr5)	rr r1�a�weakref�refrZ
gc_collect�assertIsNone)r%r5r6r8rrr�test_AST_garbage_collection�s
z%AST_Tests.test_AST_garbage_collectioncCs�x�ttdfttdfttdffD]�\}}}x�t||�D]�\}}|jddd|��Ct|d|t	j
�}|jt|�|�|j
|d
�WdQRX|jdd	d|��t|d|�WdQRXqJWq+WdS)N�exec�single�eval�actionZparsing�input�?rZ	compiling)rr)�
exec_tests�exec_results�single_tests�single_results�
eval_tests�eval_results�zipZsubTest�compiler�
PyCF_ONLY_ASTr+rr$)r%r?�output�kind�i�oZast_treerrr�
test_snippets�szAST_Tests.test_snippetscCsPtjd�jdjj}|j|j�|j|j�|j|j�dS)Nzx[::]r)	r�parse�bodyr'�slicer9�upper�lower�step)r%Zslcrrr�
test_slice�szAST_Tests.test_slicecCs*tjd�jd}|j|j�dS)Nzfrom . import yr)rrOrPr9�module)r%Zimrrr�test_from_import�szAST_Tests.test_from_importcCsStjd�}|j|jdtj�dj�|jd_t|dd�dS)Nzfrom __future__ import divisionrz __future__ z<test>r;)rrOZassertIsInstancerP�
ImportFrom�striprVrH)r%�modrrr�!test_non_interned_future_from_ast�sz+AST_Tests.test_non_interned_future_from_astcCs�|jttjtj��|jttjtj��|jttjtj��|jttjtj��|jttjtj��|jttj	tj��dS)N)
r#�
issubclassr�Forr"�Namer!r �
comprehensionZGt)r%rrr�test_base_classesszAST_Tests.test_base_classescCs�x|tjj�D]k\}}t|t�r|dkr|dj�r|�}t|tj�r|jt|j�t	�qWdS)Nr r)
rr,�itemsr�type�isupperr r+rr)r%r&�itemr1rrr�test_field_attr_existences
+	z#AST_Tests.test_field_attr_existencecCsltj�}|j|jd
�|jt��|jWdQRXtjtdd��}|j|jd	�dS)N�argsr/�
kwonlyargs�kw_defaults�kwarg�defaults��r*)rfr/rgrhrirj)r�	argumentsr+rr-r.r/�range)r%r1rrr�test_argumentsszAST_Tests.test_argumentscCs,tj�}d|_|j|jd�dS)Ni�)r�Numrr+)r%r1rrr�test_field_attr_writables	z"AST_Tests.test_field_attr_writablecCsJtj�}|j|jd�|jt��|jWdQRXtjd�}|j|jd�|jt��|jWdQRX|jt��|jWdQRXtjdd�}|j|jd�tjddd�}|j|jd�|j|jd�|j|jd�|jt	tjdd�|jt	tjdddd�dS)	N�nr(r	r*rrk)rr)rr)
rrpr+rr-r.rrr	r)r0)r%r1rrr�test_classattrs$s$zAST_Tests.test_classattrscCs8tjd�g}tj|�}|j|j|�dS)Nr()rrp�Moduler+rP)r%rPr1rrr�test_module?szAST_Tests.test_modulec	Cs�tj�}|j|jd
�d|_|j|jd�tjd�}tjd�}tj�}tj|||�}|j|j|�|j|j|�|j|j	|�tjddd�}|j|jd�|j|jd�|j|j	d�tjddddd	�}|j|jd�|j|jd�|j|j	d�|j|j
d	�|jttjdd�|jttjdddd
�|jttjdddd	�|jttjdddd
dd	�tjdddddddd	�}|j|jd�|j|jd�|j|j	d�|j|j
d	�tjddddd�}|j|jd�dS)N�left�op�right�rk�r*r	r��	foobarbazr()rvrwrx)
r�BinOpr+rr|rp�Addrvrwrxr	r-r0)r%r1Zn1Zn3Zaddoprrr�test_nodeclassesDs>	%$zAST_Tests.test_nodeclassescCs#tj�}|j|jf�dS)N)rZSubr+r)r%r1rrr�test_no_fieldstszAST_Tests.test_no_fieldsc	Cs�ddl}|g}yddl}|j|�Wntk
rFYnXdddg}xt|D]l}xc|D][}xRdd�tD�D]=}|j|j||��}|jt|�t|��q�WqjWq]WdS)Nrrkr*css$|]}t|ddd�VqdS)r@r;iN)rH)rrLrrr�	<genexpr>�sz*AST_Tests.test_pickling.<locals>.<genexpr>)	�pickle�cPickler�ImportErrorrA�loads�dumpsr+r)	r%r�Zmodsr�Z	protocolsrZZprotocolrZast2rrr�
test_picklingys	


zAST_Tests.test_picklingcCs�tdddd�}tjtjtj|�|�g�}|jt��}t|dd�WdQRX|jdt	|j
��dS)Nr	r*r
rzz<test>r;zbut got <_ast.expr)�dictrrt�Exprr!r-r0rH�assertInr�	exception)r%�pos�m�cmrrr�test_invalid_sum�s
'zAST_Tests.test_invalid_sumcCs�tjtjtjdtj���g�}tj|�|jt��}t|dd�WdQRX|j	dt
|j��dS)Nr(z<test>r;zidentifier must be of type str)rrtr�r^�Load�fix_missing_locationsr-r0rHr�rr�)r%r�r�rrr�test_invalid_identitifer�s
-
z"AST_Tests.test_invalid_identitifercCswtjtjtjd��g�}tj|�|jt��}t|dd�WdQRX|jdt	|j
��dS)Nr(z<test>r;zstring must be of type str)rrtr��Strr�r-r0rHr�rr�)r%r�r�rrr�test_invalid_string�s
$
zAST_Tests.test_invalid_stringcCsotjd�}d|jdjdj_|jt��}t|dd�WdQRX|jdt|j	��dS)Nzdef f():
 yield from g()rz<test>r;zfield value is required)
rrOrPr'r-�
ValueErrorrHr�rr�)r%Zempty_yield_fromr�rrr�test_empty_yield_from�s
zAST_Tests.test_empty_yield_fromN)rr3r4r$r2r:rNrUrWr[r`rerorqrsrurr�r�r�r�r�r�rrrrr�s(0rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ASTHelpers_TestcCsMtjd�}tdddtj�}|jtj|�tj|��dS)Nz
foo(1 + 1)z	<unknown>r;)rrOrHrIr+�dump)r%r6�brrr�
test_parse�szASTHelpers_Test.test_parsecCs^yddWnKtk
rY|jt��}tjd�WdQRX|j|jj�YnXdS)Nrkrz'\U')�	Exceptionr-�SyntaxErrorr�literal_evalZassertIsNotNoner��__context__)r%rrrr�test_parse_in_error�s
z#ASTHelpers_Test.test_parse_in_errorcCsjtjd�}|jtj|�d�|jtj|dd�d�|jtj|dd�d�dS)	Nzspam(eggs, "and cheese")z�Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), args=[Name(id='eggs', ctx=Load()), Str(s='and cheese')], keywords=[]))])Zannotate_fieldsFzYModule([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), Str('and cheese')], []))])�include_attributesTaModule(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), lineno=1, col_offset=5), Str(s='and cheese', lineno=1, col_offset=11)], keywords=[], lineno=1, col_offset=0), lineno=1, col_offset=0)]))rrOr+r�)r%�noderrr�	test_dump�szASTHelpers_Test.test_dumpcCs_tjddd�}tjtjd�|jj�|j_|jtj|dd�d�dS)Nz1 + 1�moder=r*r�Tz�Expression(body=BinOp(left=Num(n=1, lineno=1, col_offset=0), op=Add(), right=Num(n=2, lineno=1, col_offset=4), lineno=1, col_offset=0)))rrOZ
copy_locationrprPrxr+r�)r%�srcrrr�test_copy_location�s'z"ASTHelpers_Test.test_copy_locationcCs�tjd�}|jjtjtjtjdtj��tjd�gg���|j	|tj
|��|j	tj|dd�d�dS)Nz
write("spam")�spamZeggsr�Ta|Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, col_offset=6)], keywords=[], lineno=1, col_offset=0), lineno=1, col_offset=0), Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], keywords=[], lineno=1, col_offset=0), lineno=1, col_offset=0)]))rrOrPrr��Callr^r�r�r+r�r�)r%r�rrr�test_fix_missing_locations�s*z*ASTHelpers_Test.test_fix_missing_locationscCs�tjddd�}|jtj|dd�|�|jtj|dd�d�tjddd�}|jtj|jdd�|j�|jtj|dd�d�dS)	Nz1 + 1r�r=rrrzr�Tz�Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, col_offset=0)))rrOr+Zincrement_linenor�rP)r%r�rrr�test_increment_lineno�s%z%ASTHelpers_Test.test_increment_linenocCsitjddd�}ttj|j��}|j|jd�jd�|j|dgdgi�dS)Nzfoo()r�r=�func�foo�keywordsrf)rrOr�Ziter_fieldsrPr+�pop�id)r%r��drrr�test_iter_fields�sz ASTHelpers_Test.test_iter_fieldscCs�tjddd�}|jtttj|j���d�tj|j�}|jt|�jd�|jt|�j	d�|jt|�j	d�|jtj
t|��d�dS)	Nzspam(23, 42, eggs='leek')r�r=r{r��r(z(keyword(arg='eggs', value=Str(s='leek')))rrOr+�lenrZiter_child_nodesrP�nextr�rrr�)r%r��iteratorrrr�test_iter_child_nodes�s(z%ASTHelpers_Test.test_iter_child_nodescCsbtjd�}|jtj|jd�d�tjd�}|jtj|jd�d�dS)Nz&def foo():
  """line one
  line two"""rzline one
line twoz#async def foo():
  """spam
  ham"""zspam
ham)rrOr+Z
get_docstringrP)r%r�rrr�test_get_docstrings
z"ASTHelpers_Test.test_get_docstringcCs�|jtjd�dddg�|jtjd�ddi�|jtjd�d�|jtjd�dddh�|jtjd�d
�|jttjd�|jtjd�d�|jtjd�d�|jtjd�d�dS)Nz	[1, 2, 3]rkr*rzz{"foo": 42}r�r(z(True, False, None)TFz	{1, 2, 3}zb"hi"shizfoo()z-6�z-6j+3y@z3.25g
@)TFNi����y@�)r+rr�r-r�)r%rrr�test_literal_evals""z!ASTHelpers_Test.test_literal_evalcCsO|jtjd�d�|jtjd�d�|jtjd�d�dS)	NZ2jy@z10 + 2j�
z1.5 - 2jg�?y$@@y�?�)r+rr�)r%rrr�test_literal_eval_issue4907sz+ASTHelpers_Test.test_literal_eval_issue4907cCs�tjdddtjdd�gdddddd�g}tj|�}|jt��}t|d	d
�WdQRX|jdt|j	��dS)NrVZtime�namesr&Zsleep�levelr	r
�testr;zinvalid integer value: None)
rrX�aliasrtr-r�rHr�rr�)r%rPrZr�rrr�test_bad_integersz ASTHelpers_Test.test_bad_integerN)rr3r4r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s	r�c@sPeZdZdddedd�Zddedd�Zddd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1dS)`�ASTValidatorTestsNr;�exccCsod|_|_tj|�|j|��}t|d|�WdQRX|dk	rk|j|t|j��dS)Nrz<test>)	r	r
rr�r-rHr�rr�)r%rZ�msgr�r�r�rrrrZ)s
zASTValidatorTests.modcCs5tjtj|�g�}|j||d|�dS)Nr�)rrtr�rZ)r%r�r�r�rZrrrr!1szASTValidatorTests.exprcCs&tj|g�}|j||�dS)N)rrtrZ)r%r"r�rZrrrr"5szASTValidatorTests.stmtcCsxtjtjtjdtj���g�}|j|dd�tjtjdtj���}|j|dd�dS)Nr1zmust have Load contextr<r=)r�Interactiver�r^�StorerZ�
Expression)r%r�rrrru9s-!zASTValidatorTests.test_modulec	s�dddddd�fdd�}tjdtjdtj���g}||d|�d�||d|�d�||dtjd�g�d	�||d
tjd�g�d�tjdtjdtj���g}||d|dtjdtj��g�d�tjd
tjdtj���tjdtjdtj���g}||d|d
dtjdtj��g�d�dS)Ncsp|dkrg}|dkr$g}|dkr6g}|dkrHg}tj||||||�}�|�S)N)rrm)rfr/rgrirjrh)�facrrrm@sz5ASTValidatorTests._check_arguments.<locals>.argumentsr1rfzmust have Load contextrgrjrzz"more positional defaults than argsrhr{z3length of kwonlyargs is not the same as kw_defaultsr6r��y)r�argr^r�rpr�)r%r�Zcheckrmrfr)r�r�_check_arguments?s$''*!'z"ASTValidatorTests._check_argumentscCs�tjgdggdg�}tjd|ggd�}|j|d�tjd|tj�gtjdtj��gd�}|j|d�tjd|tj�ggtjdtj���}|j|d�dd�}|j||j�dS)Nr1zempty body on FunctionDefzmust have Load contextcSs"tjd|tj�ggd�S)Nr1)r�FunctionDef�Pass)rfrrrr�hsz+ASTValidatorTests.test_funcdef.<locals>.fac)rrmr�r"r�r^r�r�)r%r6rr�rrr�test_funcdef^s0	zASTValidatorTests.test_funcdefcCs�dddddd�}|j|dtjdtj��g�d�|j|dtjdtjdtj���g�d�|j|dg�d�|j|ddg�d	�|j|d
tjdtj��g�d�dS)NcSsj|dkrg}|dkr$g}|dkr?tj�g}|dkrQg}tjd||||�S)NZmyclass)rr��ClassDef)�basesr�rP�decorator_listrrr�clsmsz,ASTValidatorTests.test_classdef.<locals>.clsr�r1zmust have Load contextr�rPzempty body on ClassDefzNone disallowedr�)r"rr^r��keyword)r%r�rrr�
test_classdefls'3'zASTValidatorTests.test_classdefcCsg|jtjg�d�|jtjdg�d�|jtjtjdtj��g�d�dS)Nzempty targets on DeletezNone disallowedr1zmust have Del context)r"r�Deleter^r�)r%rrr�test_delete�s'zASTValidatorTests.test_deletecCs�|jtjgtjd��d�|jtjdgtjd��d�|jtjtjdtj��gtjd��d�|jtjtjdtj��gtjdtj���d�dS)Nrzzempty targets on AssignzNone disallowedr1zmust have Store contextr�zmust have Load context)r"r�Assignrpr^r�r�)r%rrr�test_assign�s%(3$zASTValidatorTests.test_assigncCs�tjtjdtj��tj�tjdtj���}|j|d�tjtjdtj��tj�tjdtj���}|j|d�dS)Nr1r�zmust have Store contextzmust have Load context)r�	AugAssignr^r�r~r"r�)r%Zaugrrr�test_augassign�s$$z ASTValidatorTests.test_augassigncCs>tjdtj��}tjdtj��}tj�}|jtj||gg�d�|jtjtjdtj��||gg�d�|jtj|tjdtj��|gg�d�tjtjdtj���}|jtj|||gg�d�|jtj|||g|g�d�dS)Nr1r�zempty body on Forzmust have Store contextzmust have Load context)rr^r�r�r�r"r]r�)r%r1r��prrrr�test_for�s"00!%zASTValidatorTests.test_forcCs�|jtjtjd�gg�d�|jtjtjdtj��tj�gg�d�|jtjtjd�tj�gtjtjdtj���g�d�dS)Nrzzempty body on Whiler1zmust have Load context)r"r�Whilerpr^r�r�r�)r%rrr�
test_while�s(3$$zASTValidatorTests.test_whilecCs
|jtjtjd�gg�d�tjtjdtj��tj�gg�}|j|d�tjtjd�tjtjdtj���gg�}|j|d�tjtjd�tj�gtjtjdtj���g�}|j|d�dS)Nrzzempty body on Ifr1zmust have Load context)r"r�Ifrpr^r�r�r�)r%rLrrr�test_if�s(0<'zASTValidatorTests.test_ifcCs�tj�}|jtjg|g�d�tjtjd�d�}|jtj|gg�d�tjtjdtj��d�}|jtj|g|g�d�tjtjd�tjdtj���}|jtj|g|g�d�dS)Nzempty items on Withrzzempty body on Withr1zmust have Load contextzmust have Store context)	rr�r"�With�withitemrpr^r�r�)r%r�rLrrr�	test_with�s$"-zASTValidatorTests.test_withcCs�tjdtjd��}|j|d�tjtjdtj��d�}|j|d�tjtjd�tjdtj���}|j|d�dS)Nrzz!Raise with cause but no exceptionr1zmust have Load contextr{)r�Raiserpr"r^r�)r%�rrrr�
test_raise�s$-zASTValidatorTests.test_raisecCs"tj�}tjggg|g�}|j|d�tjtjtjdtj���ggg|g�}|j|d�tj|gggg�}|j|d�tj|gg|g|g�}|j|d�tj|gtjddg�ggg�}|j|d�tjtjdtj��d|g�g}|jtj|g|gg�d�tjdd|g�g}tj|g|tjtjdtj���g|g�}|j|d�tj|g||gtjtjdtj���g�}|j|d�dS)Nzempty body on Tryr1zmust have Load contextz-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlerszempty body on ExceptHandlerr�)rr��Tryr"r�r^r��
ExceptHandler)r%r�rrrrr�test_try�s$9!--%<<zASTValidatorTests.test_trycCsx|jtjtjdtj��d�d�tjtjdtj��tjdtj���}|j|d�dS)Nr1zmust have Load contextr�)r"r�Assertr^r�r�)r%Zassrtrrr�test_assert�s
'zASTValidatorTests.test_assertcCs|jtjg�d�dS)Nzempty names on Import)r"r�Import)r%rrr�test_import�szASTValidatorTests.test_importcCsWtjdtjdd�gd�}|j|d�|jtjdgd�d�dS)Nr1r(zlevel less than -1rzempty names on ImportFromi���)rrXr�r")r%Zimprrr�test_importfrom�s$z!ASTValidatorTests.test_importfromcCs|jtjg�d�dS)Nzempty names on Global)r"r�Global)r%rrr�test_global�szASTValidatorTests.test_globalcCs|jtjg�d�dS)Nzempty names on Nonlocal)r"rZNonlocal)r%rrr�
test_nonlocal�szASTValidatorTests.test_nonlocalcCs5tjtjdtj���}|j|d�dS)Nr1zmust have Load context)rr�r^r�r")r%rrrr�	test_expr�s!zASTValidatorTests.test_exprcCs�tjtj�g�}|j|d�tjtj�tjd�g�}|j|d�tjtj�tjd�dg�}|j|d�tjtj�tjd�tjdtj��g�}|j|d�dS)Nzless than 2 valuesrzr{zNone disallowedr1zmust have Load context)r�BoolOp�Andr!rpr^r�)r%r�rrr�test_boolop�s$'9zASTValidatorTests.test_boolopcCs>tjtj�tjdtj���}|j|d�dS)Nr1zmust have Load context)r�UnaryOp�Notr^r�r!)r%�urrr�test_unaryops*zASTValidatorTests.test_unaryopcCsotjgdggdg�}|jtj|tjdtj���d�dd�}|j||j�dS)Nr1zmust have Load contextcSs"tj|tjdtj���S)Nr1)r�Lambdar^r�)rfrrrr�sz*ASTValidatorTests.test_lambda.<locals>.fac)rrmr!r�r^r�r�)r%r6r�rrr�test_lambdas
'zASTValidatorTests.test_lambdacCs�tjdtj��}tjdtj��}xK|||f|||f|||ffD]}|jtj|�d�q[WdS)Nr1r�zmust have Load context)rr^r�r�r!ZIfExp)r%�l�srfrrr�
test_ifexps1zASTValidatorTests.test_ifexpcCsutjgtjdtj��g�}|j|d�tjtjdtj��gdg�}|j|d�dS)Nr1zsame number of keys as valueszNone disallowed)r�Dictr^r�r!)r%r�rrr�	test_dicts'*zASTValidatorTests.test_dictcCsT|jtjdg�d�tjtjdtj��g�}|j|d�dS)NzNone disallowedr1zmust have Load context)r!r�Setr^r�)r%r�rrr�test_sets$zASTValidatorTests.test_setcCsb|j|g�d�tjtjdtj��tjdtj��g�}|j||g�d�tjtjdtj��tjdtj��g�}|j||g�d�tjdtj��}tjdtj��}tj||dg�}|j||g�d�tj||tjdtj��g�}|j||g�d�dS)Nz comprehension with no generatorsr1zmust have Store contextzmust have Load contextr�zNone disallowed)r!rr_r^r�r�)r%r��gr1r�rrr�_check_comprehensions*z&ASTValidatorTests._check_comprehensioncs�tjtjdtj��tjdtj��g�}|j�tjdtj��|g�d��fdd�}|j|�dS)Nr1zmust have Load contextcs�tjdtj��|�S)Nr1)rr^r�)Zgens)r�rr�wrap1sz,ASTValidatorTests._simple_comp.<locals>.wrap)rr_r^r�r�r!r)r%r�rrr)r�r�_simple_comp,s'zASTValidatorTests._simple_compcCs|jtj�dS)N)rr�ListComp)r%rrr�
test_listcomp5szASTValidatorTests.test_listcompcCs|jtj�dS)N)rr�SetComp)r%rrr�test_setcomp8szASTValidatorTests.test_setcompcCs|jtj�dS)N)rr�GeneratorExp)r%rrr�test_generatorexp;sz#ASTValidatorTests.test_generatorexpcCs�tjtjdtj��tjdtj��g�}tjtjdtj��tjdtj��|g�}|j|d�tjtjdtj��tjdtj��|g�}|j|d�dd�}|j|�dS)Nr�r�r1zmust have Load contextcSsCtjdtj��}tjdtj��}tj|||�S)Nr1r�)rr^r��DictComp)�comps�krrrr�factoryGsz0ASTValidatorTests.test_dictcomp.<locals>.factory)rr_r^r�r�rr!r)r%r�crrrr�
test_dictcomp>s!!zASTValidatorTests.test_dictcompcCsZ|jtjtjdtj���d�|jtjtjdtj���d�dS)Nr1zmust have Load)r!rZYieldr^r�Z	YieldFrom)r%rrr�
test_yieldMs+zASTValidatorTests.test_yieldcCstjdtj��}tj|tj�gg�}|j|d�tj|tj�gtjd�tjd�g�}|j|d�tjtjd�tj�g|g�}|j|ddt�tj|tj�gtjd�g�}|j|ddt�dS)	Nr1zno comparatorsr{ryz,different number of comparators and operandsZblahznon-numericr�)rr^r��CompareZInr!rpr0)r%rv�comprrr�test_compareQs6**zASTValidatorTests.test_comparecCs	tjdtj��}tjdtj��g}tjdtjdtj���g}tjtjdtj��||�}|j|d�tj|dg|�}|j|d�tjdtjdtj���g}tj|||�}|j|d�dS)Nr1r��w�zzmust have Load contextzNone disallowed)rr^r�r�r�r�r!)r%r�rfr�ZcallZbad_keywordsrrr�	test_call\s'''zASTValidatorTests.test_callcCs�Gdd�dt�}Gdd�dt�}Gdd�dt�}xEdd|�|�|�fD]%}|jtj|�d	d
t�qaWdS)Nc@seZdZdS)z*ASTValidatorTests.test_num.<locals>.subintN)rr3r4rrrr�subintisrc@seZdZdS)z,ASTValidatorTests.test_num.<locals>.subfloatN)rr3r4rrrr�subfloatksrc@seZdZdS)z.ASTValidatorTests.test_num.<locals>.subcomplexN)rr3r4rrrr�
subcomplexmsr�0Zhelloznon-numericr�)r
�floatrr!rrpr0)r%rrr�objrrr�test_numhs
%zASTValidatorTests.test_numcCsAtjtjdtj��dtj��}|j|d�dS)Nr1r�zmust have Load context)r�	Attributer^r�r�r!)r%�attrrrr�test_attributers-z ASTValidatorTests.test_attributecCs�tjtjdtj��tjtjd��tj��}|j|d�tjdtj��}tj|tjtjdtj���tj��}|j|d�tjdtj��}xf|ddfd|dfdd|ffD]:}tj|�}|jtj||tj��d�q�Wtj	g�}|jtj||tj��d�tj	tj|�g�}|jtj||tj��d�dS)Nr1rzzmust have Load contextr�zempty dims on ExtSlice)
r�	Subscriptr^r�ZIndexrpr�r!�SliceZExtSlice)r%�subr1r�rfZslrrr�test_subscriptvs 0'1%z ASTValidatorTests.test_subscriptcCsqtjtjtjdtj��tj��gtj��}tj|gtjd��}|j|d�dS)Nr1r{zmust have Store context)	r�List�Starredr^r�r�r�rpr")r%rvZassignrrr�test_starred�s0zASTValidatorTests.test_starredcCsZ|j|dgtj��d�|j|tjdtj��gtj��d�dS)NzNone disallowedr1zmust have Load context)r!rr�r^r�)r%r�rrr�	_sequence�s"-zASTValidatorTests._sequencecCs|jtj�dS)N)r)rr&)r%rrr�	test_list�szASTValidatorTests.test_listcCs|jtj�dS)N)r)r�Tuple)r%rrr�
test_tuple�szASTValidatorTests.test_tuplecCs|jtjd�d�dS)Nr{z&singleton must be True, False, or None)r!r�NameConstant)r%rrr�test_nameconstant�sz#ASTValidatorTests.test_nameconstantcCs�tjjtj�}dd�tj|�D�}|jddg�xp|D]h}tjj||�}t|ddd��}|j	�}WdQRXtj
||�}t||d�qKWdS)	NcSs%g|]}|jd�r|�qS)z.py)�endswith)r�fnrrrr�s	z;ASTValidatorTests.test_stdlib_validates.<locals>.<listcomp>ztest/test_grammar.pyztest/test_unpack_ex.pyr��encodingzutf-8r;)�os�path�dirnamer�__file__�listdir�extend�join�open�readrOrH)r%�stdlibZtestsrVr0�fp�sourcerZrrr�test_stdlib_validates�s
z'ASTValidatorTests.test_stdlib_validates)2rr3r4r�rZr!r"rur�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr
rrrrrr!r%r(r)r*r,r.r>rrrrr�'s\	



	
r�c
Cs�tdkrdStjdd�dgkr�x�tdftdftdffD]^\}}t|d�x7|D]/}tttt	|d|d	���d
�qoWtd�qNWtd�t
�tj�dS)
N�__main__rkz-gr;r<r=z_results = [r@i�,�]zmain())
r�sys�argvrArCrE�print�reprrrH�
SystemExit�unittest�main)Z
statementsrKr�rrrrH�s
-
rHrtr�rkr-r�rrmr��	r�r�r6r�rp��rlrf��kwargs�r�r�r��r�#�)�+r(�1��r&�r�r���:r��Cr^�objectZReturn�r�r{ZDelr�r�r�r~ryr]r�r�rzr�r�r1r��
r��q�r�r�r�r��stringr�r*r�r�r�r�rBrXr�ZBreakZContinuer+rr_r	�ZAaZBbZCcrrr��r�� rrr�r�ZAsyncFunctionDefZAwaitZ	somethingZAsyncForrL�Z	AsyncWithr�r'r�r}r�r�r�r�r�r�rZLtr�rr"r#)r2rBrGrr7r�rrrArCrEZTestCaserr�r�rHrBrDrFrrrr�<module>s*			����*K`r]]�Q6N]3EH]EEc�ZoB3'-*]]��������������WNK3??*?��]�6lTTT�