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

�
g f߫�3@s�ddlZddlZddlZddlZddlZddlmZdd�Zddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*g&Zd+gZ	dd,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBgZ
GdCdD�dDej�ZGdEdF�dFej�Z
GdGdH�dHej�ZdIdJ�ZdKdLdMdfdNdMdfdffgfdKdOdMdfdPdQgdggdgfdRdMdSffggdfgfdKdOdMdfdPdQdTdMdUfdVdfgdggdgfdRdMdWffggdfgfdKdOdMdfdPdQdTdMdUfdVdfgdggddXdMdYfdfgfdRdMdZffggdfgfdKdOdMdfdPdQgdTdMd[fd\dfggdgfdRdMd]ffggdfgfdKdOdMdfdPdQgdggdTdMdYfd^dfgfdRdMd_ffggdfgfdKdOdMdfdPdQdTdMdUfdVdfdTdMdSfd`dfdTdMd]fdadfdTdMdbfdcdfdTdMddfdedfgdTdMdffd\dfdTdMdgfdPdfgdXdMdhfdifgdTdMdjfd^dfdXdMdkfdMfdNdMdlfdfdmdMdnfgdoffdpdMdqfggfgfdRdMdrffggdfgfdKdsdMdfdtggdddRdMdYffggf	gfdKdsdMdfdtdudMdYfdvdoffggdddRdMd_ffggf	gfdKdOdMdfdPdQgdggdgfdwdMdYfdXdMdxfdMffggdfgfdKdydMdfdudMdzfd<d{ffgfgfdKd|dMdfdudMdfd<d}ffgdXdMdzfdMffgfdKd~dMdfdudMdfd<d}ffdfdXdMd�fdMffgfdKd�dMdfdudMdzfd<d}ffdudMdSfd<doffdRdMdkffggfgfdKd�dMdfdudMdUfd<doffdRdMdYffggfgfdKd�dMdfdudMd�fd<doffdRdMd�ffggfgfdKd�dMdfd�dudMd�fd�doffdudMdWfd�d}fffgdRdMd�ffgfgfdKd�dMdfd�dudMd�fd�doffdudMdWfd�d}fffd�dudMd�fd�doffdudMd�fd�d}fffgdRdMd�ffgfgfdKd�dMdfd�dMdUfdudMdUfd�doffd�dMdlfd�fggddfdfgfdKd�dMdfdRd�d�ffgd�d�dfdud�d[fd�doffddRdzd�ffgfgggfgfdKd�dMdfdRd�d�ffgggdRdzd�ffgfgfdKd�dMdfdudMd[fd<doffdfgfdKd�dMdfd�d�dfgfgfdKd�dMdfd�d�d<dfgdfgfdKd�dMdfd<gfgfdKdLdMdfdXdMdfdMffgfdKdRdMdffgfdKd�dMdffgfdKd�dMdffgfdKd�dMdfd�dMdzfdudMdzfdVd}ffdudMdUfd`d}ffgd}ffdudMdkfdadoffdRdMd]ffggfgfdKdLdMdfd�dMdMfd�dMd�fdudMd�fdVdoffdudMdzfd`doffgdoffd�d�dMdkfdudMdkfdVd}ffdudMd�fd`d}ffgd}ffdudMd�fdadoffgfgffgfdKdLdMdfd�dMdMfd�dMd�fdudMd�fdVdoffdudMdzfd`doffgdoffd�d�dMdkfdudMdkfdVd}ffdudMd�fd`d}ffgd}ffdudMd�fdadoffgfgffgfdKdLdMdfd�dMdMfd�dMd�fdudMd�fdVdoffdudMdzfd`doffgdoffd�d�dMdZfdudMdZfdVd}ffdudMd]fd`d}ffgd}ffdudMd�fdadoffgfgffgfdKdLdMdfd�d�dzfd�d�dzfdud�dzfd�doffdud�d[fd�doffgdoffd�d�dYdzfdudYdzfd�d}ffdudWdzfd�d}ffgd}ffdudWdWfd�doffgfgffgfdKdLdMdfd�dMdMfdudMdMfdVdoffdudMd�fd`doffd�dudMdkfd�d}ffdudMdlfd�doffgfd�dudMdbfd�d}ffdudMd�fd�doffdudMd�fd�doffgfgffgfdKdLdMdfd�dMdMfdudMdMfdVdoffdudMd�fd`doffd�d�dMdkfdudMdkfd<d}ffdudMd�fd�d}ffgd}ffdudMd�fd�doffgfgffgfdKdLdMdfd�dMdMfdudMdMfd�doffd�dudMd[fd�d}ffdudMdZfd�doffdudMd_fd�doffgfgffgfdKdLdMdfd�dMdMfdudMdMfd�doffd�d�dMd[fdudMd[fd�d}ffdudMdSfd�d}ffgd}ffdudMd]fd�doffgfgffgfg&Zd�dLdMdfd�dMdfdXdMdfdMfdfdXdMd�fd�fffgfgZd�dNdMdfdffd�d�dMdfd�fdudMdfdVdoffdudMdUfd`doffgffd�d�dMdfdudMdfdVdoffdfdudMdzfd`doffffd�d�dMdfd�fdudMdzfd<doffffd�d�dMdfdQgdggdgfdNdMd[fdfffd�dpdMdfdXdMd�fdMfgdXdMdzfd�fgffd�dpdMdfggffd�d�dMdfdNdMdMfdfgffd�dpdMdfdXd�dUfdMfgdXdzdWfd�fgffd�d�dMdMfdudMdMfdVdoffd�dudMd[fd`d}ffdudMdZfdadoffdudMd_fdcdoffgfgffd�d�dMdMfdudMdMfdVdoffd�dudMd[fd`d}ffdudMdZfdadoffdudMd_fdcdoffgfgffd�d�dMdfdXdMdfdMfd�fd�fgdXdMdzfd�fdXdMdYfd�fgffd�d�dMdfdudMdfdPdoffdXdMd�fdMfdXdMdzfd�fgd�dadXdMdYfd�ffgdudMdkfdcdoffdudMdxfdedoffffd�dXdMdfdWffd�d�dMdfd�ffd�d�dMdfdudMdfdVdoffd`dofffd�d�dMdfdudMdfdVdoffd�dudMd�fd`doffdudMdzfdadoffdfdofffd�dudMdfd<dofffd�dmdMdfdXdMdMfdMfdXdMd�fd�fdXdMd�fd�fgdofffd�dmdMdfgdofffd�d�dMdfdXdMdfdMfdXdMd�fd�fdXdMdzfd�fgdofffd�d�dMdMfdXdMdMfdMfdXdMd�fd�fdXdMd�fd�fgdofffd�d�dMdfgdofffd�d�dMdfd�dMdfd�dMdfd�dMdfdudMdfdVdoffd`doffdadoffdcdoffd�dMdYfd�dMdYfdudMdYfdVdoffd`doffd�dXdMdZfdMfdXdMd]fd�fdfdoffggddffgZe�dS)��N)�supportcCs�|dks$t|tttf�r(|St|t�rHdd�|D�S|jjg}t|d�r�t|d�r�|j|j	|j
f�n|jdkr�t|�Sx-|jD]"}|jt
t||���q�Wt|�S)NcSsg|]}t|��qS�)�to_tuple)�.0�err�2/opt/alt/python34/lib64/python3.4/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�pass�break�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}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}nxr|jD]g}t
||�}t|t�r�x@|D]}|j||�q�Wq�|dk	r�|j||�q�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��|jWdQX|jt	��tjd�WdQXdS)N�*�foobar�)
r!r"�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r7)	r!r"r3�a�weakref�refrZ
gc_collect�assertIsNone)r'r7r8r:rrr�test_AST_garbage_collection�s
z%AST_Tests.test_AST_garbage_collectioncCs�x�ttdfttdfttdffD]m\}}}x[t||�D]J\}}t|d|tj	�}|j
t|�|�|j|d�qJWq+WdS)N�exec�single�eval�?r)rr)
�
exec_tests�exec_results�single_tests�single_results�
eval_tests�eval_results�zip�compiler!�
PyCF_ONLY_ASTr-rr&)r'�input�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)�slicer;�upper�lower�step)r'Zslcrrr�
test_slice�szAST_Tests.test_slicecCs*tjd�jd}|j|j�dS)Nzfrom . import yr)r!rPrQr;�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=)r!rPZassertIsInstancerQ�
ImportFrom�striprWrH)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_classes�szAST_Tests.test_base_classescCs�x�tjj�D]q\}}t|t�r|dkr|dj�r|�}t|tj�r�|jt|j�t	�q�qqWdS)Nr"r)
r!r.�itemsr�type�isupperr"r-rr)r'r(�itemr3rrr�test_field_attr_existences
+	z#AST_Tests.test_field_attr_existencec
Csktj�}|j|jd
�|jt��|jWdQXtjtdd��}|j|jd	�dS)N�argsr1�
kwonlyargs�kw_defaults�kwarg�defaults��r,)zargszvarargz
kwonlyargszkw_defaultszkwargzdefaults)r!�	argumentsr-rr/r0r1�range)r'r3rrr�test_argumentss
zAST_Tests.test_argumentscCs,tj�}d|_|j|jd�dS)Ni�)r!�Numrr-)r'r3rrr�test_field_attr_writables	z"AST_Tests.test_field_attr_writablecCsGtj�}|j|jd�|jt��|jWdQXtjd�}|j|jd�|jt��|jWdQX|jt��|jWdQXtjdd�}|j|jd�tjddd�}|j|jd�|j|jd�|j|jd�|jt	tjdd�|jt	tjdddd�dS)	N�nr*r	r,rrl)rs)rs)
r!rqr-rr/r0rsr	r+r2)r'r3rrr�test_classattrss$


zAST_Tests.test_classattrscCs8tjd�g}tj|�}|j|j|�dS)Nr*)r!rq�Moduler-rQ)r'rQr3rrr�test_module3szAST_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�rl�r,r	r��	foobarbazr*)zleftzopzright)
r!�BinOpr-rr}rq�Addrwrxryr	r/r2)r'r3Zn1Zn3Zaddoprrr�test_nodeclasses8s>	%$zAST_Tests.test_nodeclassescCs#tj�}|j|jf�dS)N)r!ZSubr-r)r'r3rrr�test_no_fieldshs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)Nrrlr,css$|]}t|ddd�VqdS)r@r=iN)rH)rrMrrr�	<genexpr>xsz*AST_Tests.test_pickling.<locals>.<genexpr>)	�pickle�cPickler�ImportErrorrA�loads�dumpsr-r)	r'r�Zmodsr�Z	protocolsr[Zprotocolr!Zast2rrr�
test_picklingms	


zAST_Tests.test_picklingcCs�tdddd�}tjtjtj|�|�g�}|jt��}t|dd�WdQX|jdt	|j
��dS)Nr	r,r
r{z<test>r=zbut got <_ast.expr)�dictr!ru�Exprr#r/r2rH�assertInr�	exception)r'�pos�m�cmrrr�test_invalid_sum|s
'zAST_Tests.test_invalid_sumcCstjtjtjdtj���g�}tj|�|jt��}t|dd�WdQX|j	dt
|j��dS)Nr*z<test>r=zidentifier must be of type str)r!rur�r_�Load�fix_missing_locationsr/r2rHr�rr�)r'r�r�rrr�test_invalid_identitifer�s
-
z"AST_Tests.test_invalid_identitifercCsvtjtjtjd��g�}tj|�|jt��}t|dd�WdQX|jdt	|j
��dS)Nr*z<test>r=zstring must be of type str)r!rur��Strr�r/r2rHr�rr�)r'r�r�rrr�test_invalid_string�s
$
zAST_Tests.test_invalid_stringcCsntjd�}d|jdjdj_|jt��}t|dd�WdQX|jdt|j	��dS)Nzdef f():
 yield from g()rz<test>r=zfield value is required)
r!rPrQr)r/�
ValueErrorrHr�rr�)r'Zempty_yield_fromr�rrr�test_empty_yield_from�s
zAST_Tests.test_empty_yield_fromN)rr5r6r&r4r<rOrVrXr\rarfrprrrtrvr�r�r�r�r�r�r�rrrrr �s(	0r c@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=)r!rPrHrIr-�dump)r'r8�brrr�
test_parse�szASTHelpers_Test.test_parsecCs]yddWnJtk
rX|jt��}tjd�WdQX|j|jj�YnXdS)Nrlrz'\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=[], starargs=None, kwargs=None))])Zannotate_fieldsFzeModule([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), Str('and cheese')], [], None, None))])�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=[], starargs=None, kwargs=None, lineno=1, col_offset=0), lineno=1, col_offset=0)]))r!rPr-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)))r!rPZ
copy_locationrqrQryr-r�)r'�srcrrr�test_copy_location�s'z"ASTHelpers_Test.test_copy_locationcCs�tjd�}|jjtjtjtjdtj��tjd�ggdd���|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=[], starargs=None, kwargs=None, 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=[], starargs=None, kwargs=None, lineno=1, col_offset=0), lineno=1, col_offset=0)]))r!rPrQrr��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?rsr{r�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)))r!rPr-Zincrement_linenor�rQ)r'r�rrr�test_increment_lineno�s%z%ASTHelpers_Test.test_increment_linenocCsytjddd�}ttj|j��}|j|jd�jd�|j|igd6dd6gd6dd	6�dS)
Nzfoo()r�r?�func�foo�keywords�kwargsrg�starargs)r!rPr�Ziter_fieldsrQr-�pop�id)r'r��drrr�test_iter_fields�s
z 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')))r!rPr-�lenrZiter_child_nodesrQ�nextr�rsr�)r'r��iteratorrrr�test_iter_child_nodes�s(z%ASTHelpers_Test.test_iter_child_nodescCs3tjd�}|jtj|jd�d�dS)Nz&def foo():
  """line one
  line two"""rzline one
line two)r!rPr-Z
get_docstringrQ)r'r�rrr�test_get_docstring�sz"ASTHelpers_Test.test_get_docstringcCs�|jtjd�dddg�|jtjd�idd6�|jtjd�d�|jtjd�dddh�|jtjd�d
�|jttjd�|jtjd�d�|jtjd�d�|jtjd�d�dS)Nz	[1, 2, 3]rlr,r{z{"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-r!r�r/r�)r'rrr�test_literal_eval�s" "z!ASTHelpers_Test.test_literal_evalcCsO|jtjd�d�|jtjd�d�|jtjd�d�dS)	NZ2jy@z10 + 2j�
z1.5 - 2jg�?y$@@y�?�)r-r!r�)r'rrr�test_literal_eval_issue4907sz+ASTHelpers_Test.test_literal_eval_issue4907cCs�tjdddtjdd�gdddddd�g}tj|�}|jt��}t|d	d
�WdQX|jdt|j	��dS)NrWZtime�namesr(Zsleep�levelr	r
�testr=zinvalid integer value: None)
r!rY�aliasrur/r�rHr�rr�)r'rQr[r�rrr�test_bad_integer
sz ASTHelpers_Test.test_bad_integerN)rr5r6r�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=�exccCsqd|_|_tj|�|j|��}t|d|�WdQX|dk	rm|j|t|j��ndS)Nrz<test>)	r	r
r!r�r/rHr�rr�)r'r[�msgr�r�r�rrrr[s
zASTValidatorTests.modcCs5tjtj|�g�}|j||d|�dS)Nr�)r!rur�r[)r'r�r�r�r[rrrr##szASTValidatorTests.exprcCs&tj|g�}|j||�dS)N)r!rur[)r'r$r�r[rrrr$'szASTValidatorTests.stmtcCsxtjtjtjdtj���g�}|j|dd�tjtjdtj���}|j|dd�dS)Nr3zmust have Load contextr>r?)r!�Interactiver�r_�Storer[�
Expression)r'r�rrrrv+s-!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)Ncs||dkrg}n|dkr*g}n|dkr?g}n|dkrTg}ntj||||||�}�|�S)N)r!rn)rgr1rhrjrkri)�facrrrn2s				z5ASTValidatorTests._check_arguments.<locals>.argumentsr3rgzmust have Load contextrhrkr{z"more positional defaults than argsrir|z3length of kwonlyargs is not the same as kw_defaultsr8r��y)r!�argr_r�rqr�)r'r�Zcheckrnrgr)r�r�_check_arguments1s$''*!'z"ASTValidatorTests._check_argumentscCs�tjgdggdg�}tjd|ggd�}|j|d�tjd|tj�gtjdtj��gd�}|j|d�tjd|tj�ggtjdtj���}|j|d�dd�}|j||j�dS)Nr3zempty body on FunctionDefzmust have Load contextcSs"tjd|tj�ggd�S)Nr3)r!�FunctionDef�Pass)rgrrrr�Zsz+ASTValidatorTests.test_funcdef.<locals>.fac)r!rnr�r$r�r_r�r�)r'r8rr�rrr�test_funcdefPs0	zASTValidatorTests.test_funcdefcCsCdddddddd�}|j|dtjdtj��g�d�|j|dtjdtjdtj���g�d�|j|dtjdtj���d�|j|dtjdtj���d�|j|d	g�d
�|j|d	dg�d�|j|dtjdtj��g�d�dS)
NcSs||dkrg}n|dkr*g}n|dkrHtj�g}n|dkr]g}ntjd||||||�S)NZmyclass)r!r��ClassDef)�basesr�r�r�rQ�decorator_listrrr�cls_s			z,ASTValidatorTests.test_classdef.<locals>.clsr�r3zmust have Load contextr�r�r�rQzempty body on ClassDefzNone disallowedr�)r$r!r_r��keyword)r'r�rrr�
test_classdef^s'3$$'zASTValidatorTests.test_classdefcCsg|jtjg�d�|jtjdg�d�|jtjtjdtj��g�d�dS)Nzempty targets on DeletezNone disallowedr3zmust have Del context)r$r!�Deleter_r�)r'rrr�test_deletexs'zASTValidatorTests.test_deletecCs�|jtjgtjd��d�|jtjdgtjd��d�|jtjtjdtj��gtjd��d�|jtjtjdtj��gtjdtj���d�dS)Nr{zempty targets on AssignzNone disallowedr3zmust have Store contextr�zmust have Load context)r$r!�Assignrqr_r�r�)r'rrr�test_assign~s%(3$zASTValidatorTests.test_assigncCs�tjtjdtj��tj�tjdtj���}|j|d�tjtjdtj��tj�tjdtj���}|j|d�dS)Nr3r�zmust have Store contextzmust have Load context)r!�	AugAssignr_r�rr$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)Nr3r�zempty body on Forzmust have Store contextzmust have Load context)r!r_r�r�r�r$r^r�)r'r3r��prrrr�test_for�s"00!%zASTValidatorTests.test_forcCs�|jtjtjd�gg�d�|jtjtjdtj��tj�gg�d�|jtjtjd�tj�gtjtjdtj���g�d�dS)Nr{zempty body on Whiler3zmust have Load context)r$r!�Whilerqr_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)Nr{zempty body on Ifr3zmust have Load context)r$r!�Ifrqr_r�r�r�)r'rMrrr�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 Withr{zempty body on Withr3zmust have Load contextzmust have Store context)	r!r�r$�With�withitemrqr_r�r�)r'r�rMrrr�	test_with�s$"-zASTValidatorTests.test_withcCs�tjdtjd��}|j|d�tjtjdtj��d�}|j|d�tjtjd�tjdtj���}|j|d�dS)Nr{z!Raise with cause but no exceptionr3zmust have Load contextr|)r!�Raiserqr$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 Tryr3zmust have Load contextz-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlerszempty body on ExceptHandlerr�)r!r��Tryr$r�r_r��
ExceptHandler)r'r�rrrrr�test_try�s$9!--%<<zASTValidatorTests.test_trycCsx|jtjtjdtj��d�d�tjtjdtj��tjdtj���}|j|d�dS)Nr3zmust 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)Nr3r*zlevel less than -1rzempty names on ImportFromi���)r!rYr�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$r!ZNonlocal)r'rrr�
test_nonlocal�szASTValidatorTests.test_nonlocalcCs5tjtjdtj���}|j|d�dS)Nr3zmust have Load context)r!r�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 valuesr{r|zNone disallowedr3zmust have Load context)r!�BoolOp�Andr#rqr_r�)r'r�rrr�test_boolop�s$'9zASTValidatorTests.test_boolopcCs>tjtj�tjdtj���}|j|d�dS)Nr3zmust have Load context)r!�UnaryOp�Notr_r�r#)r'�urrr�test_unaryop�s*zASTValidatorTests.test_unaryopcCsotjgdggdg�}|jtj|tjdtj���d�dd�}|j||j�dS)Nr3zmust have Load contextcSs"tj|tjdtj���S)Nr3)r!�Lambdar_r�)rgrrrr��sz*ASTValidatorTests.test_lambda.<locals>.fac)r!rnr#r�r_r�r�)r'r8r�rrr�test_lambda�s
'zASTValidatorTests.test_lambdacCs�tjdtj��}tjdtj��}xK|||f|||f|||ffD]}|jtj|�d�q[WdS)Nr3r�zmust have Load context)r!r_r�r�r#ZIfExp)r'�l�srgrrr�
test_ifexps1zASTValidatorTests.test_ifexpcCs�tjgtjdtj��g�}|j|d�tjdgtjdtj��g�}|j|d�tjtjdtj��gdg�}|j|d�dS)Nr3zsame number of keys as valueszNone disallowed)r!�Dictr_r�r#)r'r�rrr�	test_dict	s'**zASTValidatorTests.test_dictcCsT|jtjdg�d�tjtjdtj��g�}|j|d�dS)NzNone disallowedr3zmust 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 generatorsr3zmust have Store contextzmust have Load contextr�zNone disallowed)r#r!r`r_r�r�)r'r��gr3r�rrr�_check_comprehensions*z&ASTValidatorTests._check_comprehensioncs�tjtjdtj��tjdtj��g�}|j�tjdtj��|g�d��fdd�}|j|�dS)Nr3zmust have Load contextcs�tjdtj��|�S)Nr3)r!r_r�)Zgens)r�rr�wrap*sz,ASTValidatorTests._simple_comp.<locals>.wrap)r!r`r_r�r�r#r)r'r�rrr)r�r�_simple_comp%s'zASTValidatorTests._simple_compcCs|jtj�dS)N)rr!�ListComp)r'rrr�
test_listcomp.szASTValidatorTests.test_listcompcCs|jtj�dS)N)rr!�SetComp)r'rrr�test_setcomp1szASTValidatorTests.test_setcompcCs|jtj�dS)N)rr!�GeneratorExp)r'rrr�test_generatorexp4sz#ASTValidatorTests.test_generatorexpcCs�tjtjdtj��tjdtj��g�}tjtjdtj��tjdtj��|g�}|j|d�tjtjdtj��tjdtj��|g�}|j|d�dd�}|j|�dS)Nr�r�r3zmust have Load contextcSsCtjdtj��}tjdtj��}tj|||�S)Nr3r�)r!r_r��DictComp)�comps�krrrr�factory@sz0ASTValidatorTests.test_dictcomp.<locals>.factory)r!r`r_r�r�rr#r)r'r�crrrr�
test_dictcomp7s!!zASTValidatorTests.test_dictcompcCsZ|jtjtjdtj���d�|jtjtjdtj���d�dS)Nr3zmust have Load)r#r!ZYieldr_r�Z	YieldFrom)r'rrr�
test_yieldFs+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)	Nr3zno comparatorsr|rzz,different number of comparators and operandsZblahznon-numericr�)r!r_r��CompareZInr#rqr2)r'rw�comprrr�test_compareJs6**zASTValidatorTests.test_comparecCs�tjdtj��}tjdtj��g}tjdtjdtj���g}tjdtj��}tjdtj��}tjtjdtj��||||�}|j|d�tj|dg|||�}|j|d�tjdtjdtj���g}tj|||||�}|j|d�tj|||tjdtj��|�}|j|d�tj||||tjdtj���}|j|d�dS)	Nr3r��w�zr��qzmust have Load contextzNone disallowed)r!r_r�r�r�r�r#)r'r�rgr�Zstarargrj�callZbad_keywordsrrr�	test_callUs$'$	'-zASTValidatorTests.test_callcCs�Gdd�dt�}Gdd�dt�}Gdd�dt�}xEdd|�|�|�fD]%}|jtj|�d	d
t�qaWdS)Nc@seZdZdS)z*ASTValidatorTests.test_num.<locals>.subintN)rr5r6rrrr�subintjsrc@seZdZdS)z,ASTValidatorTests.test_num.<locals>.subfloatN)rr5r6rrrr�subfloatlsrc@seZdZdS)z.ASTValidatorTests.test_num.<locals>.subcomplexN)rr5r6rrrr�
subcomplexnsr�0Zhelloznon-numericr�)r
�floatrr#r!rqr2)r'rrr�objrrr�test_numis
%zASTValidatorTests.test_numcCsAtjtjdtj��dtj��}|j|d�dS)Nr3r�zmust have Load context)r!�	Attributer_r�r�r#)r'�attrrrr�test_attributess-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)Nr3r{zmust have Load contextr�zempty dims on ExtSlice)
r!�	Subscriptr_r�ZIndexrqr�r#�SliceZExtSlice)r'�subr3r�rgZslrrr�test_subscriptws 0'1%z ASTValidatorTests.test_subscriptcCsqtjtjtjdtj��tj��gtj��}tj|gtjd��}|j|d�dS)Nr3r|zmust have Store context)	r!�ListZStarredr_r�r�r�rqr$)r'rwZassignrrr�test_starred�s0zASTValidatorTests.test_starredcCsZ|j|dgtj��d�|j|tjdtj��gtj��d�dS)NzNone disallowedr3zmust have Load context)r#r!r�r_r�)r'r�rrr�	_sequence�s"-zASTValidatorTests._sequencecCs|jtj�dS)N)r-r!r+)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_nameconstantcCs�tjjtj�}dd�tj|�D�}|jddg�xo|D]g}tjj||�}t|ddd��}|j	�}WdQXtj
||�}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�readrPrH)r'�stdlibZtestsrWr4�fp�sourcer[rrr�test_stdlib_validates�s
z'ASTValidatorTests.test_stdlib_validates)2rr5r6r�r[r#r$rvr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	rr
rrrrr#r&r*r,r-r.r0r2rBrrrrr�s\	



	
r�c
Cs�tdkrdStjdd�dgkr�x�tdftdftdffD]^\}}t|d�x7|D]/}tttt	|d|d	���d
�qoWtd�qNWtd�t
�ntj�dS)
N�__main__rlz-gr=r>r?z_results = [r@i�,�]zmain())
r�sys�argvrArCrE�print�reprrrH�
SystemExit�unittest�main)Z
statementsrLr�rrrrL�s
-
	rLrur�rlr1r�rrnr��	r�r�r8r�rq��rmrg�r��r�r�r��r�#�)�+r*�1��r+�r�r��:r��Cr_�objectZReturn�r�r|ZDelr�r�r�rrzr^r�r�r{r�r�r3r��
r�r�r�r�r�r��stringr�r,r�r�r�r�rFrYr�ZBreakZContinuer/rr`r�ZAaZBbZCcrrr��r�� rr
r�r�r�r~r�r�r�r�r�r�rrZLtr�r$r'r()r6rFrKr!r9r�rrrArCrEZTestCaser r�r�rLrBrDrFrrrr�<module>s			���*K`r]]�Q<T]3EH]EEc�`oB3'-*���������WNK3??*?��]�6lTTT�