Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.128.171.99
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_ast.cpython-310.pyc
o

`bs��@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZdd�Z
gd�ZdgZgd�ZGd	d
�d
ej�ZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZejGdd�dej��Zdd�Zgddggf�ddggf�dddddggdggdgfd ggddfggf�ddd!ddggdggdgfd"ggddfggf�ddd#ddgd$gdggdgfd%ggddfggf�ddd&ddgd$gdggdd'gfd(ggddfggf�ddd)ddggd*ggdgfd+ggddfggf�ddd,ddggdggd-gfd.ggddfggf�ddd/ddggd0�d1d2gd3gd4d5d6d7d8gd9fd:d;ggfgfd<ggddfggf�dd=d>d?ggd@ggfggf�dd=dAd?ggdBggfggf�dd=d,d?dCggd.ggfggf�ddd&ddggdggdgfdDggddfggf�ddEdFdGgfggf�ddHdFdIgdJdfggf�ddHdKdLdMdNdOgdPfgdQdfggf�ddHdRdLdFdSdTgdPfgdUdfggf�ddHdRd7dFdSdTgdPfgdUdfggf�ddVggf�ddWdXdYdZd[ggdfggf�dd\d>d]d@ggfggf�dd^dRd_d`ggfggf�dd^dadbdcgd^dddedfggfgfggf�dd^dgdbdcgd^dhdedfgdigfgfggf�ddjdkdlgdmgdfggf�ddjdndldogdpgdfggf�ddqdndrdsdtduggfdfggf�ddvdadcgdwdddxddfgfgggfggf�ddvdadcgggdfgfggf�ddyggf�ddzd{d|gfggf�dd}dkd~dgdfggf�dd�d�d�gfggf�dd�ggf�dd�ggf�ddWd&dYdZd�ggdfggf�ddWd�dYdZd�ggdfggf�ddWd)dLd�d�d�gdPfd�d+ggdfggf�ddWd�dLd�d�d�gdPfd�d�ggdfggf�ddWd�d7d�d�d�gdPfd�d�ggdfggf�dd�d�d�d�dLd�d�d�gd9fd�dLd�d�d�gdPfd�gdfgffggf�dd�d�d�d�d�d�d�d�d�gdfd�d�d�d�gdfgffggf�dd�d�d�d�d�d�d�dLd�d�d�gdPfd�gdfgffggf�dd�d�d�d�d�d�d�d�d�gdfgffggf�dd�d&d�d&d�d�dLd�d�d�gdPfd�gdfgffggf�dd�d�ddggdggdgfd�d�d�d�d�drd�d�ggfffggddfggf�dd�d�ddggdggdgfd�d�d�d�d�gd�gdfggddfggf�dd�d�ddggdggdgfd�d�d�gd�gdfggddfggf�dd�d#d:d#dd�gd:d�dJgd�gfd�gffggf�dd�d>d�d>d�d�d�d�d�d�gfd9fd�gffggf�dd�d�ddggdggdgfd�d�d�d�d�d�d�d�gd�fgffggddfggf�ddd�ddggdggdgfd�gd�drd�d�ggfdrd�d�d�ggfgddfggf�dd�d�ddggdggdgfd�gd�drd�d�ggfdrd�d�d�ggfgddfggf�dd=d�d?ggd�gd�drd�d�ggfdrd�d�d�ggfgfggf�ddd�ddggdggdgfd�gdrd�d�d�d�d�d�d�d�gdfgfggfgddfggf�ddd�ddggdggdgfd�gd�gddfggf�dd�ggf�ddd)ddd$ggdggdgfd+ggddfggf�ddd�ddd$ggd�dggdgfd�ggddfggf�ddd!ddd$gd�gdd�d�gddgdgfd�ggddfggf�ddd�ddd$gd�gdd�d�gddgd�gfd�ggddfggf�ddd�ddd$ggdggdd�gfd�ggddfggf�ddd!ddd$gd�d�gdggdgd��fd�ggddfggf�dddAddd$gd�gdd�gd�gdd�d�gfd�ggddfggf�ddd�ddd$gd�gdd�gdgdd�d�gfd�ggddfggf�ddd�ddd$gd�gdd�gd�gd�d�d�gfd�ggddfggf�ddd�ddd$gd�gdd�gdg�dd�d�gf�dggddfggf�Z�d�dgfgZg�d��d�ddK�d�d�d	gff��d
��d��d�d�d
dggdggdgf�dff��dd:dK�dg�dgff��dd:�dggff��dd�dK�dgff��dd:�d�dg�dgff��dd�d�d�d�d��d�dgdfgff��dd�d�d�d�d��d�dgdfgff��dd�d�dL�d�d�dgd9fd�dLd��d�dgdPf�dgdfgff��ddϐddL�d�d�dgd9fd�dL�dd�d gdPf�d!gdfgff��ddϐddL�d�d�dgd9fd�d7�dd�d gdPf�d!gdfgff��dd�d�dL�d�d�dgd9fd�dLd��d�dgdPf�dgdfgff��dd��ddL�d�d�dgd9fd�dL�dd�d gdPf�d!gdfgff��dd��ddL�d�d�dgd9fd�d7�dd�d gdPf�d!gdfgff��dd�d�dL�d�d�dgd9fd�dLd��d�dgdPf�dgdfgff��dd��ddL�d�d�dgd9fd�dL�dd�d gdPf�d!gdfgff��dd��ddL�d�d�dgd9fd�d7�dd�d gdPf�d!gdfgff��d�d"dR�d#�d$�d$g�d�d%gff��ddrdk�d&g�d'��d(�d)gff��ddrd{�d&dʐd*d7�d+�d,�d-gd9fd9fggff��ddrdX�d&d��d.�dd��d/�d0gdfgfggff��d1��d2��d3��d4��d5��dd7dKg�d6�d9ff��dd7�dgd9ff��ddLdFg�d7�d9ff��ddLdKg�d6�d9ff��ddL�dgd9ff��ddrdk�d8�d9ggff�Ze�dS(:�N)�dedent)�supportcCs�|dust|tttf�r|St|t�rdd�|D�S|jjg}t|d�rHt|d�rH|�|j	|j
f�t|d�rHt|d�rH|d|j|jf7<|j
durQt|�S|j
D]}|�tt||���qTt|�S)NcSsg|]}t|��qS�)�to_tuple)�.0�err�6/usr/local/python-3.10/lib/python3.10/test/test_ast.py�
<listcomp>szto_tuple.<locals>.<listcomp>�lineno�
col_offset�
end_lineno�end_col_offset���)�
isinstance�str�int�complex�list�	__class__�__name__�hasattr�appendr
rrr
�_fields�tupler�getattr)�t�result�frrrrs



r)C�Nonez'module docstring'z
def f(): passzdef f(): 'function docstring'zdef f(a): passzdef f(a=0): passzdef f(*args): passzdef f(**kwargs): passzGdef f(a, b=1, c=None, d=[], e={}, *args, f=42, **kwargs): 'doc for f()'zclass C:passz class C: 'docstring for class C'zclass C(object): passzdef f():return 1zdel v�v = 1za,b = cz	(a,b) = cz	[a,b] = czv += 1zfor v in v:passzwhile v:passz	if v:passzif a:
  pass
elif b:
  passz(if a:
  pass
elif b:
  pass
else:
  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: passzfor (a,b) in c: passzfor [a,b] in c: passzL(
    (
    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}z3async def f():
 'async function'
 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}z$async def f():
 [i async for b in c]z'@deco1
@deco2()
@deco3(1)
def f(): passz-@deco1
@deco2()
@deco3(1)
async def f(): passz'@deco1
@deco2()
@deco3(1)
class C: passz!@deco(a for a in b)
def f(): pass�@a.b.c
def f(): passz(a := 1)zdef f(a, /,): passzdef f(a, /, c, d, e): passzdef f(a, /, c, *, d, e): passz'def f(a, /, c, *, d, e, **kwargs): passzdef f(a=1, /,): passzdef f(a=1, /, b=2, c=4): passz def f(a=1, /, b=2, *, c=4): passzdef f(a=1, /, b=2, *, c): passz*def f(a=1, /, b=2, *, c=4, **kwargs): passz(def f(a=1, /, b=2, *, c, **kwargs): passz1+2)#rza and b�a + bznot vzlambda:Nonez{ 1:2 }�{}z{None,}z&{
      1
        :
          2
     }z[a for b in c if d]z(a for b in c if d)z[(a,b) for a,b in c]z[(a,b) for (a,b) in c]z[(a,b) for [a,b] in c]z{(a,b) for a,b in c}z{(a,b) for (a,b) in c}z{(a,b) for [a,b] in c}z((a,b) for a,b in c)z((a,b) for (a,b) in c)z((a,b) for [a,b] in c)z	1 < 2 < 3zf(1,2,c=3,*d,**e)�
f(*[0, 1])zf(a for a in b)Z10z'string'�a.bza[b:c]�vz[1,2,3]z[]z1,2,3z(1,2,3)�()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)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zejd5d6��Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAS)B�	AST_TestscCs0t|t�sdSd|jvrdS|dko|d��S)NF�ast�ASTr)r�type�
__module__�isupper)�self�name�noderrr�_is_ast_node�s


zAST_Tests._is_ast_nodecCs�t|tj�r|jdur
dSt|tjtjtjf�r*|j|jf}|�	||�|j|jf}|jD]4}t
||�}t|t�rW|}|rK|dkrK|dj|djf}|D]}|�||�qMq-|dura|�||�q-|�
|j|j�dS)N�decorator_listr)rr*r+r�expr�stmtZ
excepthandlerr
rZassertGreaterEqualrr�_assertTrueorder�assertEqual�__match_args__)r/�ast_nodeZ
parent_posZnode_posr0�valueZ	first_pos�childrrrr6s&


��zAST_Tests._assertTrueordercCs�t��}|�|jd�d|_|�|jd�|�|jdd�|�t��|jWd�n1s1wY|�t	��t�d�Wd�dS1sLwYdS)Nr�*�foobar�)
r*r+r7rr=�__dict__�assertRaises�AttributeError�vararg�	TypeError�r/�xrrr�test_AST_objectss�"�zAST_Tests.test_AST_objectscCsLGdd�d�}t��}|�|_||j_t�|j�}~t��|�|��dS)Nc@�eZdZdS)z0AST_Tests.test_AST_garbage_collection.<locals>.XN�rr-�__qualname__rrrr�X%�rJ)	r*r+rE�a�weakref�refr�
gc_collect�assertIsNone)r/rJrLrNrrr�test_AST_garbage_collection$sz%AST_Tests.test_AST_garbage_collectionc
Cs�ttdfttdfttdffD]Z\}}}t||�D]O\}}|jd|d��t|d|t	j
�}|�t|�|�|�
|d�Wd�n1sDwY|jd||d	��t|d|�Wd�n1sbwYqqdS)
N�exec�single�evalZparsing)�action�input�?)rrZ	compiling)rUrV�kind)�
exec_tests�exec_results�single_tests�single_results�
eval_tests�eval_results�zip�subTest�compiler*�
PyCF_ONLY_ASTr7rr6)r/rV�outputrX�i�o�ast_treerrr�
test_snippets/s ������zAST_Tests.test_snippetscCs0ttt}|D]
}t�|�}t|dd�qdS)N�<string>rR)rYr[r]r*�parsera)r/Zsnippets_to_validateZsnippet�treerrr�test_ast_validation;s

�zAST_Tests.test_ast_validationcCs<t�d�jdjj}|�|j�|�|j�|�|j�dS)Nzx[::]r)	r*ri�bodyr:�slicerP�upper�lower�step)r/Zslcrrr�
test_sliceBszAST_Tests.test_slicecCs t�d�jd}|�|j�dS)Nzfrom . import yr)r*rirlrP�module)r/�imrrr�test_from_importHszAST_Tests.test_from_importcCs>t�d�}|�|jdtj�d��|jd_t|dd�dS)Nzfrom __future__ import divisionrz __future__ �<test>rR)r*ri�assertIsInstancerl�
ImportFrom�striprrra)r/�modrrr�!test_non_interned_future_from_astLs
z+AST_Tests.test_non_interned_future_from_astcCs�t�d�jd}|�t|j�d�|jd}|�|jd�|�|j�|�|j	d�|�|j
d�|�|jd�|�|jd�t�d�jd}|jd}|�|jd�|�|j�|�|j	d�|�|j
d�|�|jd�|�|jd�dS)	Nzfrom bar import yr��y��zfrom bar import *�*)
r*rirlr7�len�namesr0rP�asnamer
rrr
)r/rs�aliasrrr�
test_aliasRs"

zAST_Tests.test_aliascCs||�ttjtj��|�ttjtj��|�ttjtj��|�ttjtj��|�ttjtj��|�ttj	tj��dS�N)
�
assertTrue�
issubclassr*�Forr5�Namer4r+�
comprehensionZGt�r/rrr�test_base_classesfszAST_Tests.test_base_classescCsRtj��D]!\}}|�||�r&|dkrq|�}t|tj�r&|�t|j�t	�qdS)NZIndex)
r*r?�itemsr2rr+r7r,rr)r/r0�itemrErrr�test_field_attr_existencens��z#AST_Tests.test_field_attr_existencecCs�t��}|�|jd�|�t��|jWd�n1swY|�|j�tjt	dd��}|�|jd�|�|jd�dS)N)�posonlyargs�argsrB�
kwonlyargs�kw_defaults�kwarg�defaultsr{�r>�)
r*�	argumentsr7rr@rAr�rPrB�rangerDrrr�test_argumentsys�zAST_Tests.test_argumentscCs t��}d|_|�|jd�dS)Ni�)r*�Numrr7rDrrr�test_field_attr_writable�sz"AST_Tests.test_field_attr_writablecCs�t��}|�|jd�|�t��|jWd�n1swY|�t��|jWd�n1s6wYt�d�}|�|jd�|�|jd�|�t��|jWd�n1sawY|�t��|j	Wd�n1sywYtjdd�}|�|jd�tjddd�}|�|jd�|�|jd�|�|jd�|�|jd�|�t
tjddd�|jt
tjddddd�|�tjddd�jd�|�tjddd�jd�|�
t
d	��tjddd
�Wd�n1s�wY|�
t
d��tjddd�Wd�n	1�swY|�t�d�jd�|�t�d
�jd
�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d
�jd
�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�|�t�d�jd�dS)N)r:rXr<r>�r
rr{Zbar)�fooz(Num got multiple values for argument 'n'��nz1Constant got multiple values for argument 'value'�r:�@�@�42�42TF.)r*r�r7rr@rAr:r�r
r=rC�Constantr��assertRaisesRegex�Str�s�Bytes�assertIs�NameConstantrDrrr�test_classattrs�sf��
����zAST_Tests.test_classattrscCs�|�tt�d��tj�|�tt�d��tj�|�tt�d��tj�|�tt�d��tj�|�tt�d��tj�|�tt�d��tj�|�tt�d��tj�|�tt�d��tj�|�tt���tj�dS)Nr<r�r�r�r�TF)	r7r,r*r�r�r�r�r��Ellipsisr�rrr�
test_realtype�szAST_Tests.test_realtypecCs�|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt��tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt�d�tj��|�	tt��tj��|�	tt��tj��|�	tt��tj��|�	tt��tj��|�	tt��tj��Gd	d
�d
t
�}|�tt�|d��tj��|�	tt�|d��tj��dS)Nr<g������@y������@r�r�TF.c@rG)z$AST_Tests.test_isinstance.<locals>.SNrHrrrr�S�sr�)r�rr*r�r�r�r�r�r��assertFalser)r/r�rrr�test_isinstance�sP zAST_Tests.test_isinstancecCs�Gdd�dtj�}Gdd�dtj�}|d�}|�|jd�|�|jd�|�t|�|�|�t||��|�t|tj��|�t||��|�tt�d�|��|dd�}|�|jd�|�t|�|�dS)NcseZdZ�fdd�Z�ZS)z$AST_Tests.test_subclasses.<locals>.Ncst�j|i|��d|_dS)N�spam)�super�__init__�z)r/r��kwargs�rrrr�s
z-AST_Tests.test_subclasses.<locals>.N.__init__)rr-rIr��
__classcell__rrr�r�Nsr�c@rG)z%AST_Tests.test_subclasses.<locals>.N2NrHrrrr�N2rKr�r<r�r�)	r*r�r7r�r�r,r�rr�)r/r�r�r�rrr�test_subclassess
zAST_Tests.test_subclassescCs*t�d�g}t�|g�}|�|j|�dS)Nr<)r*r��Moduler7rl)r/rlrErrr�test_moduleszAST_Tests.test_modulec	Cs�t��}|�|jd�d|_|�|jd�t�d�}t�d�}t��}t�|||�}|�|j|�|�|j|�|�|j	|�t�ddd�}|�|jd�|�|jd�|�|j	d�tjddddd�}|�|jd�|�|jd�|�|j	d�|�|j
d�|�ttjdddd�|jttjdddddd�tjddddd	�}|�|jd�|�|jd�|�|j	d�|�|j
d�tjdddd
d�}|�|jd
�dS)N)�left�op�right�r{r�r>rr��)r�r�r�r
r<)�	foobarbaz)
r*�BinOpr7rr�r��Addr�r�r�r
r@rC)r/rEZn1Zn3Zaddoprrr�test_nodeclassess:

zAST_Tests.test_nodeclassescCst��}|�|jd�dS)Nr)r*ZSubr7rrDrrr�test_no_fieldsGszAST_Tests.test_no_fieldsc		Cs�ddl}|g}zddl}|�|�Wn	tyYnwgd�}|D]$}|D]}dd�tD�D]}|�|�||��}|�t|�t|��q/q&q"dS)Nr)rr{r>css�|]
}t|ddd�VqdS)rWrRiN)ra)rrdrrr�	<genexpr>Ws�z*AST_Tests.test_pickling.<locals>.<genexpr>)	�pickle�cPickler�ImportErrorrY�loads�dumpsr7r)	r/r�Zmodsr�Z	protocolsry�protocolr*�ast2rrr�
test_picklingLs"����zAST_Tests.test_picklingcCs�tddd�}t�tjtjdi|��fi|��gg�}|�t��}t|dd�Wd�n1s0wY|�dt	|j
��dS)Nr>r��r
rrurRzbut got <ast.exprr)�dictr*r��Exprr4r@rCra�assertInr�	exception)r/�pos�m�cmrrr�test_invalid_sum[s(�zAST_Tests.test_invalid_sumc	Csvt�t�t�dt����gg�}t�|�|�t��}t|dd�Wd�n1s+wY|�	dt
|j��dS)Nr<rurRzidentifier must be of type str)r*r�r�r��Load�fix_missing_locationsr@rCrar�rr�)r/r�r�rrr�test_invalid_identifierbs 
�z!AST_Tests.test_invalid_identifierc	Csxtddtftddtf�fD],}tjt�|�d�}t�|�|�td��t|dd�Wd�n1s4wYq
dS)Nr{r>�rlzinvalid type in Constant: typerurT)	r�	frozensetr*�
Expressionr�r�r�rCra)r/Zinvalid_constantrrrr�test_invalid_constantis
����zAST_Tests.test_invalid_constantcCsjt�d�}d|jdjdj_|�t��}t|dd�Wd�n1s%wY|�dt|j	��dS)Nzdef f():
 yield from g()rrurRzfield 'value' is required)
r*rirlr:r@�
ValueErrorrar�rr�)r/Zempty_yield_fromr�rrr�test_empty_yield_fromrs
�zAST_Tests.test_empty_yield_fromcCsTddl}dd�}t�|d|��|�ttjd�Wd�dS1s#wYdS)NrcWsdSr�r�r�rrr�
bad_normalizesz0AST_Tests.test_issue31592.<locals>.bad_normalize�	normalizeuϕ)�unicodedatar�	swap_attrr@rCr*ri)r/r�r�rrr�test_issue31592zs
"�zAST_Tests.test_issue31592cCsDt�d�}|jdj}|j}|j}|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�t�d�}|jdj}|j}|j}|�|jd�|�|jd�|�|jd�|�|j	d	�|�|jd�|�|jd�|�|jd	�|�|j	d	�|�|jd�|�|jd�|�|jd�|�|j	d�dS)
Nz4+5+6+7r�r�r�z
4+5-\
 6-7r{r�r>)
r*rirlr:r�r7rr
r
r)r/rjZparent_binopZchild_binopZgrandchild_binoprrr� test_issue18374_binop_col_offset�s4

z*AST_Tests.test_issue18374_binop_col_offsetcCs.t�d�}|jdjdj}|�|jd�dS)Nr"rr�)r*rirlr3r:r7r
)r/rjZattr_brrr�*test_issue39579_dotted_name_end_col_offset�s
z4AST_Tests.test_issue39579_dotted_name_end_col_offsetcCs�|�tjjd�|�tjjd�|�tjjd�|�tjjd�dd�tj��D�}dtj��dj��|d<|�	tjj�
d	�|�dS)
Nz0withitem(expr context_expr, expr? optional_vars)�GtEz%Name(identifier id, expr_context ctx)zBcmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIncSsg|]}d|j���qS)z     | )�__doc__)rr1rrrr	�sz5AST_Tests.test_ast_asdl_signature.<locals>.<listcomp>zexpr = r�
)r7r*�withitemr�r�r�Zcmpopr4�__subclasses__ZassertCountEqual�split)r/Zexpressionsrrr�test_ast_asdl_signature�sz!AST_Tests.test_ast_asdl_signaturecCsLtjddd�|�t��tjddd�Wd�dS1swYdS)Nzf"{x=}")r�r�)Zfeature_version)r�r�)r*rir@�SyntaxErrorr�rrr�test_issue40614_feature_version�s"�z)AST_Tests.test_issue40614_feature_versionc	CsndD]2}t�t�|t����}t�|�|�td|�d���t|dd�Wd�n1s/wYqdS)N)�True�Falserz"identifier field can't represent 'z
' constantrurT)r*r�r�r�r�r�r�ra)r/Zconstantr4rrr�test_constant_as_name�s
���zAST_Tests.test_constant_as_nameN)%rr-rIr2r6rFrQrgrkrqrtrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�cpython_onlyr�r�r�r�r�r�rrrrr)�sD
</,	
		r)c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZdS)6�ASTHelpers_TestNcCs6t�d�}tdddtj�}|�t�|�t�|��dS)Nz
foo(1 + 1)z	<unknown>rR)r*rirarbr7�dump)r/rL�brrr�
test_parse�s
zASTHelpers_Test.test_parsecCsfzddWdSty2|�t��
}t�d�Wd�n1s#wY|�|jj�YdSw)Nr{rz'\U')�	Exceptionr@r�r*�literal_evalZassertIsNotNoner��__context__�r/rrrr�test_parse_in_error�s��z#ASTHelpers_Test.test_parse_in_errorcCsLt�d�}|�t�|�d�|�tj|dd�d�|�tj|dd�d�dS)	N�spam(eggs, "and cheese")z�Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), args=[Name(id='eggs', ctx=Load()), Constant(value='and cheese')], keywords=[]))], type_ignores=[])F��annotate_fieldszbModule([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), Constant('and cheese')], []))], [])T��include_attributesa�Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=4), args=[Name(id='eggs', ctx=Load(), lineno=1, col_offset=5, end_lineno=1, end_col_offset=9), Constant(value='and cheese', lineno=1, col_offset=11, end_lineno=1, end_col_offset=23)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=24), lineno=1, col_offset=0, end_lineno=1, end_col_offset=24)], type_ignores=[])�r*rir7r��r/r1rrr�	test_dump�s
���zASTHelpers_Test.test_dumpcCsTt�d�}|�tj|dd�d�|�tj|ddd�d�|�tj|d	dd
�d�dS)Nrr���indentz�Module(
   body=[
      Expr(
         value=Call(
            func=Name(id='spam', ctx=Load()),
            args=[
               Name(id='eggs', ctx=Load()),
               Constant(value='and cheese')],
            keywords=[]))],
   type_ignores=[])F�	)rrz�Module(
	[
		Expr(
			Call(
				Name('spam', Load()),
				[
					Name('eggs', Load()),
					Constant('and cheese')],
				[]))],
	[])T)rra�Module(
   body=[
      Expr(
         value=Call(
            func=Name(
               id='spam',
               ctx=Load(),
               lineno=1,
               col_offset=0,
               end_lineno=1,
               end_col_offset=4),
            args=[
               Name(
                  id='eggs',
                  ctx=Load(),
                  lineno=1,
                  col_offset=5,
                  end_lineno=1,
                  end_col_offset=9),
               Constant(
                  value='and cheese',
                  lineno=1,
                  col_offset=11,
                  end_lineno=1,
                  end_col_offset=23)],
            keywords=[],
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=24),
         lineno=1,
         col_offset=0,
         end_lineno=1,
         end_col_offset=24)],
   type_ignores=[])rr	rrr�test_dump_indent�s
z ASTHelpers_Test.test_dump_indentcCs�tjddd�}|�t�|�d�|�tj|dd�d�tjtjdt��d	�ddd
�}|�t�|�d�|�tj|dd
�d�|�tj|dd�d�|�tj|ddd�d�tjtjdt��d	�d�}|�t�|�d�|�tj|dd
�d�dS)Nr�r�r�zRaise()TrzRaise(lineno=3, col_offset=4)r)�id�ctx)�excr
rz#Raise(exc=Name(id='e', ctx=Load()))FrzRaise(Name('e', Load()))z;Raise(exc=Name(id='e', ctx=Load()), lineno=3, col_offset=4))rrz0Raise(Name('e', Load()), lineno=3, col_offset=4))�causez%Raise(cause=Name(id='e', ctx=Load()))zRaise(cause=Name('e', Load())))r*�Raiser7r�r�r�r	rrr�test_dump_incomplete s6��������z$ASTHelpers_Test.test_dump_incompletecCs�tjddd�}t�t�d�|jj�|j_|�tj|dd�d�tjddddd	�}t�|tjddd
��}|�	|j
�|�	|j�|�|jd�|�|j
d�dS)N�1 + 1rT��moder>Trz�Expression(body=BinOp(left=Constant(value=1, lineno=1, col_offset=0, end_lineno=1, end_col_offset=1), op=Add(), right=Constant(value=2, lineno=1, col_offset=4, end_lineno=1, end_col_offset=5), lineno=1, col_offset=0, end_lineno=1, end_col_offset=5))r{)rr
rr
)rr
)r*ri�
copy_locationr�rlr�r7r��CallrPrr
r
r)r/�src�newrrr�test_copy_location=s�z"ASTHelpers_Test.test_copy_locationcCslt�d�}|j�t�t�t�dt���t�d�gg���|�	|t�
|��d|_|�	tj|dd�d�dS)Nz
write("spam")r�ZeggsTra�Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=5), args=[Constant(value='spam', lineno=1, col_offset=6, end_lineno=1, end_col_offset=12)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=13), lineno=1, col_offset=0, end_lineno=1, end_col_offset=13), Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0), args=[Constant(value='eggs', lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)], keywords=[], lineno=1, col_offset=0, end_lineno=1, end_col_offset=0), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)], type_ignores=[]))
r*rirlrr�rr�r�r�r7r��maxDiffr��r/rrrr�test_fix_missing_locationsMs
��z*ASTHelpers_Test.test_fix_missing_locationscCs�tjddd�}|�tj|dd�|�|�tj|dd�d�tjddd�}|�tj|jdd�|j�|�tj|dd�d�tjt�d	t���ggd
d�}|�t�|�j	d�|�
t�|�j�dS)
NrrTrr�r�Trz�Expression(body=BinOp(left=Constant(value=1, lineno=4, col_offset=0, end_lineno=4, end_col_offset=1), op=Add(), right=Constant(value=1, lineno=4, col_offset=4, end_lineno=4, end_col_offset=5), lineno=4, col_offset=0, end_lineno=4, end_col_offset=5))�testr{)�funcr��keywordsr
r>)r*rir7Zincrement_linenor�rlrr�r�r
rPrrrrr�test_increment_linenoas���z%ASTHelpers_Test.test_increment_linenocCsHtjddd�}tt�|j��}|�|�d�jd�|�|ggd��dS)N�foo()rTrr!r�)r"r�)r*rir�Ziter_fieldsrlr7�popr)r/r1�drrr�test_iter_fieldsysz ASTHelpers_Test.test_iter_fieldscCs�tjddd�}|�ttt�|j���d�t�|j�}|�t|�jd�|�t|�j	d�|�t|�j	d�|�t�
t|��d�dS)	Nzspam(23, 42, eggs='leek')rTrr�r��r<z1keyword(arg='eggs', value=Constant(value='leek')))r*rir7r�rZiter_child_nodesrl�nextrr:r�)r/r1�iteratorrrr�test_iter_child_nodess�z%ASTHelpers_Test.test_iter_child_nodescCs�t�d�}|�t�|�d�t�d�}|�t�|jd�d�t�d�}|�t�|jd�d�t�d�}|�t�|jd�d�dS)Nz"""line one
  line two"""zline one
line twoz&class foo:
  """line one
  line two"""rz&def foo():
  """line one
  line two"""z#async def foo():
  """spam
  ham"""zspam
ham)r*rir7�
get_docstringrlr	rrr�test_get_docstring�s
�
�
�
z"ASTHelpers_Test.test_get_docstringcCs.|�t�t�d���t�d�}|�t�|��t�d�}|�t�|��t�d�}|�t�|jd��t�d�}|�t�|jd��t�d�}|�t�|jd��t�d�}|�t�|jd��t�d�}|�t�|jd��t�d	�}|�t�|jd��t�d
�}|�t�|jd��dS)N�zx = "not docstring"zdef foo():
  passzclass foo:
  passrz class foo:
  x = "not docstring"z class foo:
  def bar(self): passz def foo():
  x = "not docstring"zasync def foo():
  passz&async def foo():
  x = "not docstring")rPr*r,rirlr	rrr�test_get_docstring_none�s&








z'ASTHelpers_Test.test_get_docstring_nonecCst�d�}|�|jdjd�|�|jdjd�|�|jdjdjd�|�|jdjdjd�|�|jdjdjdjd�|�|jdjdjdjd�|�|jdjdjd�|�|jdjdjd�|�|jdjd�|�|jdjd	�dS)
Nz�"""line one
line two"""

def foo():
  """line one
  line two"""

  def bar():
    """line one
    line two"""
  """line one
  line two"""
"""line one
line two"""

rr{r>r�r��	��
)r*rir7rlrr
r	rrr�:test_multi_line_docstring_col_offset_and_lineno_issue16806�s�  zJASTHelpers_Test.test_multi_line_docstring_col_offset_and_lineno_issue16806cC�:t�d�}|jdjd}|�|jd�|�|jd�dS)Nz if a:
    pass
elif b:
    pass
rr��r*rirl�orelser7r
r�r/r1Z	elif_stmtrrr�test_elif_stmt_start_position��
z-ASTHelpers_Test.test_elif_stmt_start_positioncCr4)Nz/if a:
    pass
elif b:
    pass
else:
    pass
rr�r5r7rrr�'test_elif_stmt_start_position_with_else�r9z7ASTHelpers_Test.test_elif_stmt_start_position_with_elsecCs<t�d�}|jdjjd}|�|jd�|�|jd�dS)Nr%rr{r0)r*rirlr:r�r7rr
)r/r1Zstarred_exprrrr�*test_starred_expr_end_position_within_call�s
z:ASTHelpers_Test.test_starred_expr_end_position_within_callcCs@|�t�d�gd��|�t�d�ddi�|�t�d�d�|�t�d�hd	��|�t�d
�d�|�t�d�t��|�ttjd
�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�tt�d��d�|�ttjd�|�ttjd�|�ttjd�dS)Nz	[1, 2, 3]�r{r>r�z{"foo": 42}r�r<z(True, False, None))TFNz	{1, 2, 3}>r{r>r�zb"hi"shizset()r$�6�z+6z-6i����z3.25g
@z+3.25z-3.25g
�z-0.0z++6z+Truez2+3)r7r*r��setr@r��reprr�rrr�test_literal_eval�s"z!ASTHelpers_Test.test_literal_evalcCs>|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d	�d
�|�t�d�d�|�t�d
�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d
�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS)NZ6jy@z-6jy��z6.75jy@z-6.75jy��z3+6jy@@z-3+6jy�@z3-6jy@�z-3-6jy��z
3.25+6.75jy
@@z-3.25+6.75jy
�@z
3.25-6.75jy
@�z-3.25-6.75jy
��z(3+6j)z-6j+3z-6j+3jz3+-6jz3+(0+6j)z-(3+6j))r7r*r�r@r�r�rrr�test_literal_eval_complex�s$z)ASTHelpers_Test.test_literal_eval_complexcCsptjt�d�t�d�gt�d�gd�}|�ttj|�tjt�d�gt�d�t�d�gd�}|�ttj|�dS)Nr{r>r�)�keys�values)r*�Dictr�r@r�r�)r/Z	malformedrrr�&test_literal_eval_malformed_dict_nodes�s&&z6ASTHelpers_Test.test_literal_eval_malformed_dict_nodescCsJ|�t�d�d�|�t�d�d�|�t�d�d�|�ttjd�dS)Nz    -1rz		-1z 	 -1z
 -1)r7r*r�r@�IndentationErrorr�rrr�test_literal_eval_trailing_wssz-ASTHelpers_Test.test_literal_eval_trailing_wsc	Cs�d}|�t|��
t�d�Wd�n1swYt�t��t�t��t�d���}|�t|dd��d}|�t|��t�|�Wd�dS1sPwYdS)Nz#malformed node or string on line 3:z{'a': 1,
'b':2,
'c':++3,
'd':4}r>r
zmalformed node or string:)	r�r�r*r��UnaryOpZUAddr�rPr)r/�msgr1rrr�"test_literal_eval_malformed_linenos��"�z2ASTHelpers_Test.test_literal_eval_malformed_linenocCs@d}|�t|��t�d�Wd�dS1swYdS)Nz6unexpected character after line continuation characterz4
                \
                (\
            \ )r�r�r*r�)r/rJrrr�test_literal_eval_syntax_errorss"�z/ASTHelpers_Test.test_literal_eval_syntax_errorscCsxtjdtjdd�gdddd�g}t�|g�}|�t��}t|dd�Wd�n1s,wY|�dt|j	��dS)N�time�sleep�r0�rrr��levelr
rr rRzinvalid integer value: None)
r*rwr�r�r@r�rar�rr�)r/rlryr�rrr�test_bad_integers��z ASTHelpers_Test.test_bad_integercCsZtjdtjdddd�gdddd�g}t�|g�}t|dd�}i}t||�|�d|�dS)NrMrNr)r0r
rrPr rR)r*rwr�r�rarRr�)r/rlry�code�nsrrr�test_level_as_none*s��
z"ASTHelpers_Test.test_level_as_nonec	Cs�tjt��ddd�}||_|�t��.t���tt�	|�dd�Wd�n1s+wYWd�dSWd�dS1sCwYdS�Nr)r�r
rrurT�
r*rI�Not�operandr@�RecursionErrorrZinfinite_recursionrar�rrrr�test_recursion_direct6s
��"�z%ASTHelpers_Test.test_recursion_directc	Cs�tjt��ddd�}tjt��ddd�}||_||_|�t��.t���tt�	|�dd�Wd�n1s8wYWd�dSWd�dS1sPwYdSrVrW)r/rrrrr�test_recursion_indirect=s
��"�z'ASTHelpers_Test.test_recursion_indirect)rr-rIrr�rr
rrrrr#r'r+r-r/r3r8r:r;rArBrFrHrKrLrRrUr[r\rrrrr��s8=r�c@s�eZdZdted�dd�Zdued�dd�Zdudd	�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_�Z1e2�3d`�Z4e2�5e4�Z6e2�3da�Z7e2�5e7�Z8e2�3db�Z9e2�:db�Z;e2�<dce2�=��Z>e2�5e2�?e2�?e2�<dae2�@��dde2�=��dee2�=���e2�5e2�?e2�?e2�<dae2�=��dde2�@��dee2�=���e2�5e2�3df��e2�5e2�3db��e2�5e2�3dg��e2�:dh�e2�Ae2�:dh�g�e2�Ae2�Ae2�:dh�g�g�e2�Be4e9ge8g�e2jBe9e4ge8e6gdidj�e2jBe9e2�Ce2�<dke2�=��e2�=��ge8e6gdldj�e2jDe2�?e2�?e7dde2�=��dee2�=��gggdm�e2jDe>gdige6gdm�e2jDe>gge6gdm�e2jDe>e2�:dh�gggdm�e2jDe>e2�E�gggdm�e2jDe>gge2�E�gdm�e2�Ae2�Edi�g�e2jFdndo�e2�Gg�e2�Ge6g�e2�Ge6e8e2�:dp�g�e2jFdqdo�e2jEdado�e2�Ae2�Edq�g�e2jBggdqdj�gZHdrds�ZIdS)v�ASTValidatorTestsNrR�rcCszd|_|_t�|�|durt|d|�dS|�|��}t|d|�Wd�n1s-wY|�|t|j��dS)Nrru)	r
rr*r�rar@r�rr�)r/ryrJrrr�rrrryIs
�zASTValidatorTests.modcCs(t�t�|�gg�}|j|||d�dS)Nr^)r*r�r�ry)r/r1rJrryrrrr4SszASTValidatorTests.exprcCst�|gg�}|�||�dSr�)r*r�ry)r/r5rJryrrrr5WszASTValidatorTests.stmtc	CsTt�t�t�dt����g�}|�|dd�t�t�dt����}|�|dd�dS)NrE�must have Load contextrSrT)r*�Interactiver�r��Storeryr�)r/r�rrrr�[szASTValidatorTests.test_modulec	s			d�fdd�	}t�dt�dt����g}|||d�d�|||d�d�|||d�d�||t�d�gd	�d
�||t�d�gd�d
�t�dt�dt����g}|||t�dt���gd�d�t�dt�dt����t�dt�dt����g}|||dt�dt���gd�d�dS)Nc	sZ|durg}|durg}|durg}|durg}|durg}t�|||||||�}�|�Sr�)r*r�)r�r�rBr�r�r�r���facrrr�bs�z5ASTValidatorTests._check_arguments.<locals>.argumentsrEr�r_)r�)r�r�)r�z"more positional defaults than argsr�)r�z3length of kwonlyargs is not the same as kw_defaults)r�r�rLr�r|)r�r�)NNNNNNN)r*�argr�rar�r�)r/rc�checkr�r�rrbr�_check_argumentsas4�������z"ASTValidatorTests._check_argumentscCs�t�ggdggdg�}t�d|ggd�}|�|d�t�d|t��gt�dt���gd�}|�|d�t�d|t��ggt�dt����}|�|d�dd�}|�||j�dS)NrEzempty body on FunctionDefr_cSst�d|t��ggd�S�NrE)r*�FunctionDef�Passr�rrrrc��z+ASTValidatorTests.test_funcdef.<locals>.fac)r*r�rhr5rir�rarf)r/rLrrcrrr�test_funcdef�s ��zASTValidatorTests.test_funcdefcCs�ddd�}|�|t�dt���gd�d�|�|t�dt�dt����gd�d�|�|gd�d�|�|dgd�d	�|�|t�dt���gd
�d�dS)NcSsH|durg}|durg}|durt��g}|durg}t�d||||�S)NZmyclass)r*ri�ClassDef)�basesr"rlr3rrr�cls�s

�z,ASTValidatorTests.test_classdef.<locals>.clsrE)rmr_)r"r�zempty body on ClassDef�None disallowed)r3)NNNN)r5r*r�ra�keyword)r/rnrrr�
test_classdef�s
�"��zASTValidatorTests.test_classdefc	CsJ|�t�g�d�|�t�dg�d�|�t�t�dt���g�d�dS)Nzempty targets on DeleterorEzmust have Del context)r5r*�Deleter�r�r�rrr�test_delete�s
�zASTValidatorTests.test_deletec
Cs�|�t�gt�d��d�|�t�dgt�d��d�|�t�t�dt���gt�d��d�|�t�t�dt���gt�dt����d�dS)Nr�zempty targets on AssignrorE�must have Store contextr|r_)r5r*�Assignr�r�r�rar�rrr�test_assign�s"���zASTValidatorTests.test_assignc	Cspt�t�dt���t��t�dt����}|�|d�t�t�dt���t��t�dt����}|�|d�dS)NrEr|rtr_)r*�	AugAssignr�r�r�r5ra)r/Zaugrrr�test_augassign�s��z ASTValidatorTests.test_augassignc
Cs�t�dt���}t�dt���}t��}|�t�||gg�d�|�t�t�dt���||gg�d�|�t�|t�dt���|gg�d�t�t�dt����}|�t�|||gg�d�|�t�|||g|g�d�dS)NrEr|zempty body on Forrtr_)r*r�rar�rir5r�r�)r/rEr|�prrrr�test_for�s � � zASTValidatorTests.test_forc
Cs~|�t�t�d�gg�d�|�t�t�dt���t��gg�d�|�t�t�d�t��gt�t�dt����g�d�dS)Nr�zempty body on WhilerEr_)r5r*�Whiler�r�rarir�r�rrr�
test_while�s"���zASTValidatorTests.test_whilecCs�|�t�t�d�gg�d�t�t�dt���t��gg�}|�|d�t�t�d�t�t�dt����gg�}|�|d�t�t�d�t��gt�t�dt����g�}|�|d�dS)Nr�zempty body on IfrEr_)r5r*�Ifr�r�rarir�)r/rdrrr�test_if�s (�zASTValidatorTests.test_ifcCs�t��}|�t�g|g�d�t�t�d�d�}|�t�|gg�d�t�t�dt���d�}|�t�|g|g�d�t�t�d�t�dt����}|�t�|g|g�d�dS)Nzempty items on Withr�zempty body on WithrEr_rt)	r*rir5�Withr�r�r�rar�)r/ryrdrrr�	test_with�szASTValidatorTests.test_withcCspt�dt�d��}|�|d�t�t�dt���d�}|�|d�t�t�d�t�dt����}|�|d�dS)Nr�z!Raise with cause but no exceptionrEr_r�)r*rr�r5r�ra)r/�rrrr�
test_raise�szASTValidatorTests.test_raisecCsxt��}t�ggg|g�}|�|d�t�t�t�dt����ggg|g�}|�|d�t�|gggg�}|�|d�t�|gg|g|g�}|�|d�t�|gt�ddg�ggg�}|�|d�t�t�dt���d|g�g}|�t�|g|gg�d�t�dd|g�g}t�|g|t�t�dt����g|g�}|�|d�t�|g||gt�t�dt����g�}|�|d�dS)Nzempty body on TryrEr_z-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlerszempty body on ExceptHandlerr|)r*ri�Tryr5r�r�ra�
ExceptHandler)r/ryrrrrr�test_try�s$&((zASTValidatorTests.test_tryc	CsT|�t�t�dt���d�d�t�t�dt���t�dt����}|�|d�dS)NrEr_r|)r5r*�Assertr�rar�)r/Zassrtrrr�test_asserts��zASTValidatorTests.test_assertcC�|�t�g�d�dS)Nzempty names on Import)r5r*�Importr�rrr�test_import	�zASTValidatorTests.test_importcCs>t�dt�dd�gd�}|�|d�|�t�dgd�d�dS)NrEi���zNegative ImportFrom levelrzempty names on ImportFrom)r*rwr�r5)r/�imprrr�test_importfromsz!ASTValidatorTests.test_importfromcCr�)Nzempty names on Global)r5r*�Globalr�rrr�test_globalr�zASTValidatorTests.test_globalcCr�)Nzempty names on Nonlocal)r5r*ZNonlocalr�rrr�
test_nonlocalr�zASTValidatorTests.test_nonlocalcCs&t�t�dt����}|�|d�dS�NrEr_)r*r�r�rar5rrrr�	test_exprszASTValidatorTests.test_exprc	Cs�t�t��g�}|�|d�t�t��t�d�g�}|�|d�t�t��t�d�dg�}|�|d�t�t��t�d�t�dt���g�}|�|d�dS)Nzless than 2 valuesr�r�rorEr_)r*�BoolOp�Andr4r�r�ra)r/r�rrr�test_boolops&zASTValidatorTests.test_boolopcCs,t�t��t�dt����}|�|d�dSr�)r*rIrXr�rar4)r/�urrr�test_unaryop%szASTValidatorTests.test_unaryopc
CsPt�ggdggdg�}|�t�|t�dt����d�dd�}|�||j�dS)NrEr_cSst�|t�dt����Srg)r*�Lambdar�r�r�rrrrc-rjz*ASTValidatorTests.test_lambda.<locals>.fac)r*r�r4r�r�rarf)r/rLrcrrr�test_lambda)s�zASTValidatorTests.test_lambdacCsXt�dt���}t�dt���}|||f|||f|||ffD]}|�tj|�d�qdS�NrEr|r_)r*r�r�rar4ZIfExp)r/�lr�r�rrr�
test_ifexp1s
 �zASTValidatorTests.test_ifexpcCsRt�gt�dt���g�}|�|d�t�t�dt���gdg�}|�|d�dS)NrEzsame number of keys as valuesro)r*rEr�r�r4)r/r&rrr�	test_dict7szASTValidatorTests.test_dictcCs<|�t�dg�d�t�t�dt���g�}|�|d�dS�NrorEr_)r4r*�Setr�ra�r/r�rrr�test_set=szASTValidatorTests.test_setc	Cs�|�|g�d�t�t�dt���t�dt���gd�}|�||g�d�t�t�dt���t�dt���gd�}|�||g�d�t�dt���}t�dt���}t�||dgd�}|�||g�d�t�||t�dt���gd�}|�||g�d�dS)Nz comprehension with no generatorsrErrtr_r|ro)r4r*r�r�r�ra)r/rc�grEr|rrr�_check_comprehensionBs��z&ASTValidatorTests._check_comprehensioncsbt�t�dt���t�dt���gd�}|��t�dt���|g�d��fdd�}|�|�dS)NrErr_cs�t�dt���|�Srg)r*r�ra)Zgensrbrr�wrapVr�z,ASTValidatorTests._simple_comp.<locals>.wrap)r*r�r�rar�r4r�)r/rcr�r�rrbr�_simple_compQs��zASTValidatorTests._simple_compcC�|�tj�dSr�)r�r*�ListCompr�rrr�
test_listcompZ�zASTValidatorTests.test_listcompcCr�r�)r�r*�SetCompr�rrr�test_setcomp]r�zASTValidatorTests.test_setcompcCr�r�)r�r*�GeneratorExpr�rrr�test_generatorexp`r�z#ASTValidatorTests.test_generatorexpcCs�t�t�dt���t�dt���gd�}t�t�dt���t�dt���|g�}|�|d�t�t�dt���t�dt���|g�}|�|d�dd�}|�|�dS)Nr|ryrrEr_cSs.t�dt���}t�dt���}t�|||�S)NrEr|)r*r�r��DictComp)�comps�kr'rrr�factorylsz0ASTValidatorTests.test_dictcomp.<locals>.factory)r*r�r�rar�r�r4r�)r/r��cr�rrr�
test_dictcompcs���zASTValidatorTests.test_dictcompc	Cs@|�t�t�dt����d�|�t�t�dt����d�dS)NrEzmust have Load)r4r*ZYieldr�raZ	YieldFromr�rrr�
test_yieldrs"zASTValidatorTests.test_yieldcCs�t�dt���}t�|t��gg�}|�|d�t�|t��gt�d�t�d�g�}|�|d�t�t�d�t��g|g�}|�|�t�|t��gt�d�g�}|�|�dS)NrEzno comparatorsr�r�z,different number of comparators and operandsZblah)r*r�r��CompareZInr4r�)r/r��comprrr�test_comparevs$
zASTValidatorTests.test_comparecCs�t�dt���}t�dt���g}t�dt�dt����g}t�t�dt���||�}|�|d�t�|dg|�}|�|d�t�dt�dt����g}t�|||�}|�|d�dS)NrEr|�wr�r_ro)r*r�r�rprrar4)r/r!r�r"�callZbad_keywordsrrr�	test_call�szASTValidatorTests.test_callcCszGdd�dt�}Gdd�dt�}Gdd�dt�}dD]
}|�t�|��q|�|�|�fD]
}|jt�|�dtd	�q-dS)
Nc@rG)z*ASTValidatorTests.test_num.<locals>.subintNrHrrrr�subint�rKr�c@rG)z,ASTValidatorTests.test_num.<locals>.subfloatNrHrrrr�subfloat�rKr�c@rG)z.ASTValidatorTests.test_num.<locals>.subcomplexNrHrrrr�
subcomplex�rKr�)�0Zhellozinvalid typer^)r�floatrr4r*r�rC)r/r�r�r��objrrr�test_num�s�zASTValidatorTests.test_numcCs.t�t�dt���dt���}|�|d�dSr�)r*�	Attributer�rar�r4)r/�attrrrr�test_attribute�sz ASTValidatorTests.test_attributec	Cst�t�dt���t�d�t���}|�|d�t�dt���}t�|t�dt���t���}|�|d�t�dt���}|ddfd|dfdd|ffD]}tj|�}|�t�||t���d�qKt�gt���}|�t�||t����t�|gt���}|�t�||t���d�dS)NrEr�r_r|)	r*�	Subscriptr�rar�r�r4�Slice�Tuple)r/�subrEr�r��slrrr�test_subscript�s&�� 
�z ASTValidatorTests.test_subscriptc	CsNt�t�t�dt���t���gt���}t�|gt�d��}|�|d�dS)NrEr�rt)	r*�List�Starredr�r�rarur�r5)r/r��assignrrr�test_starred�s
 �zASTValidatorTests.test_starredcCs@|�|dgt���d�|�|t�dt���gt���d�dSr�)r4r*r�r�ra)r/rcrrr�	_sequence�s�zASTValidatorTests._sequencecCr�r�)r�r*r�r�rrr�	test_list�r�zASTValidatorTests.test_listcCr�r�)r�r*r�r�rrr�
test_tuple�r�zASTValidatorTests.test_tuplecCs|�t�d��dS)Nr�)r4r*r�r�rrr�test_nameconstant�sz#ASTValidatorTests.test_nameconstantc
Cs�tj�tj�}dd�t�|�D�}|�ddg�|D]E}|�|��6tj�||�}t	|ddd��}|�
�}Wd�n1s?wYt�||�}t||d�Wd�n1sZwYqdS)	NcSsg|]	}|�d�r|�qS)z.py)�endswith)r�fnrrrr	�sz;ASTValidatorTests.test_stdlib_validates.<locals>.<listcomp>ztest/test_grammar.pyztest/test_unpack_ex.pyr�zutf-8)�encodingrR)
�os�path�dirnamer*�__file__�listdir�extendr`�join�open�readrira)r/Zstdlib�testsrrr��fp�sourceryrrr�test_stdlib_validates�s
����z'ASTValidatorTests.test_stdlib_validatesr{rETZcarterr|r�.r<�stringr�)�restZlolZlegit)�patterns�	kwd_attrs�kwd_patternsr�rOZxxx�_c
Cs�t�dt���}|jD]S}|�tj|dd���?tj|tj|t��gd�gd�}t�	|�}t�
|gg�}|�t��t
|dd�Wd�n1sJwYWd�n1sYwYqdS)NrEr�r)�patternrl)�subject�casesrurR)r*r�r��_MATCH_PATTERNSr`r��MatchZ
match_caserir�r�r@r�ra)r/Zname_xr�r1rrrrr�test_match_validation_patternNs(
���
	�����z/ASTValidatorTests.test_match_validation_pattern)NrRr�)Jrr-rIr�ryr4r5r�rfrkrqrsrvrxrzr|r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r*r�Z
constant_1Z
MatchValueZ	pattern_1Z
constant_xZ	pattern_xZ
constant_trueZMatchSingletonZpattern_truer�r�Zname_carterr�raZ
MatchSequenceZMatchMappingr�Z
MatchClassZ	MatchStarZMatchAsZMatchOrr�r�rrrrr]GsP

"	



	





���	���	��������	��������
���������

�tr]c@sfeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ejdd��Z
dd�Zdd�ZdS)�
ConstantTestsz$Tests on the ast.Constant node type.cCs\t�d�}|jdj}tj|d�}t�||�||jd_t|dd�}i}t||�|dS)Nzx = 123rr�rhrRrE)r*rirlr:r�rrarR)r/r:rjr1�new_noderSrTrrr�compile_constantds

zConstantTests.compile_constantcCsN|�t��}|�gd��Wd�n1swY|�t|j�d�dS)Nr<z%got an invalid type in Constant: list)r@rCr�r7rr�)r/r�rrr�test_validationrs��zConstantTests.test_validationc	Cs^dddtdt�fD]#}|j|d��|�|�}|�||�Wd�n1s'wYq	dS)NFT�)�const)r�r�r`r�r�)r/r�r:rrr�test_singletonsxs
���zConstantTests.test_singletonsc	Cs�d}tdh�}td�D]}|df}t|dh�}qddddd	td
�td�||f	}|D]#}|j|d��|�|�}|�||�Wd�n1sGwYq)dS)
N)r{r{r�r>�{g�^@y�^@�unicode�bytesrr�r�)r�r�rr`r�r7)r/Znested_tupleZnested_frozensetrQrDr:rrrr�test_values~s"
�
���zConstantTests.test_valuescCs�t�d�}|jdjd}tjdd�}t�||�||jdjd<|�t��}t|dd�Wd�n1s7wY|�	t
|j�d�dS)N�x = 1rr{r�r�rRz6expression which can't be assigned to in Store context)r*rirl�targetsr�rr@r�rar7rr�)r/rj�target�
new_targetr�rrr�test_assign_to_constant�s
��z%ConstantTests.test_assign_to_constantcCs t�d�}|�t�|�d�dS)Nz'docstring'
x = 1Z	docstring)r*rir7r,)r/rjrrrr-�s
z ConstantTests.test_get_docstringcCs:t|dd�}g}t�|�D]
}|jdkr|�|j�q
|S)NrhrRZ
LOAD_CONST)ra�disZget_instructions�opnamerZargval)r/rj�co�constsZinstrrrr�get_load_const�s
�zConstantTests.get_load_constcCs�gd�}d�dd�|D��}|d7}|�tdf�t�|�}|�|�|�|�t|j|�D]!\}}t	|tj
�s>Jt�|���tj|d�}t�
||j�||_q-|�|�|�|�dS)N)	NTF�|g@y@r�r�r<r�cSsg|]}d�|��qS)zx={!r})�format)rr�rrrr	��z1ConstantTests.test_load_const.<locals>.<listcomp>z
x = ...r�)r�r�r�r*rir7rr_rlrrur�r�rr:)r/rrSrjr�r�r�rrr�test_load_const�s 	
��zConstantTests.test_load_constcCslt�d�}|jdj}tjdd�}t�||j�||_tjdd�}t�||j�||_|�t�	|�d�dS)Nz1 + 2r�
r�y4@y$@4@)
r*rirlr:r�rr�r�r7r�)r/rj�binopZnew_leftZ	new_rightrrrrA�s
zConstantTests.test_literal_evalcCs�tjddd�j}|�|jd�|�|jd�tjddd�j}|�|jd�|�|jd�tjddd�j}|�|jd�|�|jd�tjddd�j}|�|jd	�|�|jd�dS)
Nz"x"rTrrEzu"x"r�zr"x"zb"x"�x)r*rirlr7r:rX)r/r�rrr�test_string_kind�szConstantTests.test_string_kindN)rr-rIr�r�r�r�r�r�r-rrr�rrArrrrrr�as

r�c@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�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;�Z d<d=�Z!d>S)?�EndPositionTestsz�Tests for end position of AST nodes.

    Testing end positions of nodes requires a bit of extra care
    because of how LL parsers work.
    cCs |�|j|�|�|j|�dSr�)r7rr
)r/r9rr
rrr�_check_end_pos�szEndPositionTests._check_end_poscCs|�t�||�|�dSr�)r7r*�get_source_segment)r/r�r9Zcontentrrr�_check_content�rjzEndPositionTests._check_contentcCst�|�jdjS)Nr)r*rirlr:r�rrr�_parse_value�szEndPositionTests._parse_valuecCsJd}|�|�}|�||jd�|�||jjdd�|�||jjd�dS)Nzlambda x, *y: NonerrrEr|)rrrlr�rB)r/r�Zlamrrrr��s

zEndPositionTests.test_lambdacCs�td���}t�|�jd}|�|dd�|�||jdd�|�||jjdd�|�||jjdjd�|�||jj	d�|�||jj	jd	�dS)
Nz�
            def func(x: int,
                     *args: str,
                     z: float = 0,
                     **kwargs: Any) -> bool:
                return True
            rr��zreturn Truezx: intrzkwargs: AnyZAny)
rrxr*rirlr
rr��
annotationr��r/r�Zfdefrrr�
test_func_def�s�zEndPositionTests.test_func_defcCsNd}|�|�}|�||jd�|�||jdjd�|�||jdjd�dS)Nzfunc(x, y=2, **kw)r!r�2r{�kw)rrr!r"r:�r/r�r�rrrr�s

zEndPositionTests.test_callcCs0d}|�|�}|�||jd�|�|dd�dS)Nzx[0]()zx[0]r{r>)rrr!r
rrrr�test_call_noargss
z!EndPositionTests.test_call_noargscCsVtd���}t�|�jd}|�|dd�|�||jdd�|�||jdd�dS)Nz?
            class C(A, B):
                x: int = 0
        rr>�r{�Bz
x: int = 0)rrxr*rirlr
rrm�r/r��cdefrrr�test_class_defs�zEndPositionTests.test_class_defcCs.d}t�|�jd}|�||jdjd�dS)Nz$class S(metaclass=abc.ABCMeta): passrzabc.ABCMeta)r*rirlrr"r:rrrr�
test_class_kw&szEndPositionTests.test_class_kwcC�>td���}t�|�jd}|�|dd�|�|jdd�dS)Nzh
            x = """Some multi-line text.

            It goes on starting from same indent."""
        rr��(�rrxr*rirlr
r:�r/r�r�rrr�test_multi_line_str+s�z$EndPositionTests.test_multi_line_strcCr)NzB
            x = "first part" \
            "second part"
        rr>r2r!r"rrr�test_continued_str5s�z#EndPositionTests.test_continued_strcCstd���}t�|�}|jd}|jd}|jd}|jd}|jd}|�|dd�|�|dd	�|�|d	d
�|�|dd�|�|dd�|�||jd
�|�||jdd�|�||jdjd�|�||j	d�|�||jdd�|�||j
djd�dS)Na
            while True:
                pass

            if one():
                x = None
            elif other():
                y = None
            else:
                z = None

            for x, y in stuff:
                assert True

            try:
                raise RuntimeError
            except TypeError as e:
                pass

            pass
        rr{r>r�r�r�r0�rr~�r�zx = Nonezother()�x, yzraise RuntimeErrorrC)rrxr*rirlr
rr r6r��handlersr,)r/r�ryZ
while_loopZif_stmtZfor_loopZtry_stmtZ	pass_stmtrrr�test_suites>s(�





zEndPositionTests.test_suitescCs,d}|�|�}|jdj}|�||d�dS)Nzx = f"abc {x + y} abc"r{zx + y)rrDr:r�r/r�Zfstrr	rrr�test_fstringjs
zEndPositionTests.test_fstringcCsTtd���}|�|�}|jdj}|�|dd�|�||jd�|�||jd�dS)Nz�
            f"""Some multi-line text.
            {
            arg_one
            +
            arg_two
            }
            It goes on..."""
        r{r�r�Zarg_oneZarg_two)	rrxrrDr:r
rr�r�r*rrr�test_fstring_multi_lineps�
	z(EndPositionTests.test_fstring_multi_linecCsBtd���}t�|�jd}|�|dd�|�|jddd�dS)NzT
            from x.y.z import (
                a, b, c as c
            )
        rr�r{r>r})rrxr*rirlr
r�)r/r�r�rrr�test_import_from_multi_line�s�z,EndPositionTests.test_import_from_multi_linecCs�d}d}td���}t|j|||f�\}}}|�||jd�|�||jjd�|�||jjd�|�||jjd�|�||jj	djd	�|�||jj	d
jd�|�
|dd�dS)
Nz
f()[1, 2] [0]zx[ a.b: c.d]zN
            x[ a.b: f () ,
               g () : c.d
              ]
        z	f()[1, 2]z1, 2r&zc.dr�f ()r{�g ()r�)rrx�maprrr:rmrorn�eltsr
)r/�s1�s2�smZi1Zi2rsrrr�test_slices�s�zEndPositionTests.test_slicescCsZtd���}|�|�}|�|dd�|�||jd�|�||jd�|�||jjd�dS)NzF
            (1 * 2 + (3 ) +
                 4
            )
        r>r>�4z1 * 2 + (3 )�3)rrxrr
rr�r�)r/r�r	rrr�
test_binop�s�
zEndPositionTests.test_binopcCsDtd���}t�|�jdj}|�|dd�|�||jdd�dS)Nz{
            if (one_condition and
                    (other_condition or yet_another_one)):
                pass
        rr>�,r{z"other_condition or yet_another_one)	rrxr*rirlr r
rrD)r/r�Zboprrrr��s��zEndPositionTests.test_boolopc	Cspd}d}d}td���}t|j||||f�\}}}}|�||d�|�||d�|�||d�|�|dd	�dS)
Nzx = () ;z	x = 1 , ;zx = (1 , 2 ) ;z?
            x = (
                a, b,
            )
        r(z1 ,z(1 , 2 )r�r{)rrxr0rrr
)	r/r2r3Zs3r4�t1�t2Zt3Ztmrrr�test_tuples�s�zEndPositionTests.test_tuplescCs4d}|�|�}|�|||�|�||jdd�dS)Nz
func(x. y .z)rzx. y .z)rrr�rrrr�test_attribute_spaces�s
z&EndPositionTests.test_attribute_spacescCsvd}t�|�jdj}|�t|�jd�|�||d�d|}t�|�jdjj}|�t|�jd�|�||d�dS)Nz( ( ( a + b ) ) )rr�r#�await )r*rirlr:r7r,rr)r/r�r'r3rrr�test_redundant_parenthesis�sz+EndPositionTests.test_redundant_parenthesisc	Cs�d}|D]P\}}|�|��?t�|�jdj}|�t|�j|�|�|||�d|}t�|�jdjj}|�t|�j|�|�|||�Wd�n1sOwYqdS)N))z( ( ( a ) ) ) ( )r)z( ( ( a ) ) ) ( b )r)z( ( ( a ) ) ) [ b ]r�)z( ( ( a ) ) ) . br�rr>)	r`r*rirlr:r7r,rr)r/r�r�rr'r3rrr�(test_trailers_with_redundant_parenthesis�s���z9EndPositionTests.test_trailers_with_redundant_parenthesiscCs�d}d}|�|�}|�|�}|�||jdd�|�||jdd�|�||jdd�|�||jdd	�|�||jdd
�dS)Nz[{}, {1, }, {1, 2,} ]z{a: b, f (): g () ,}rr$r{z{1, }r>z{1, 2,}r.r/)rrr1rCrD)r/r2r3�c1�c2rrr�
test_displays�s

zEndPositionTests.test_displayscCs�td���}|�|�}|�|dd�|�||jdjd�|�||jjdjd�|�||jjdjdd�|�||jjdj	d�dS)	Nza
            x = [{x for x, y in stuff
                  if cond.x} for stuff in things]
        r>�%rZthings�stuffzcond.xr')
rrxrr
r�
generators�iter�elt�ifsr�)r/r��cmprrr�test_comprehensions�s�
z$EndPositionTests.test_comprehensionscCsLtd���}t�|�jd}|�||jdjd�|�||jdjd�dS)NzT
            async def f():
                yield x
                await y
        rzyield xr{zawait y)rrxr*rirlrr:rrrr�test_yield_await�s�z!EndPositionTests.test_yield_awaitcCs<td���}td���}|�|�}|�t�||j�|�dS)NzD
            x = (
                a, b,
            ) + ()
        z;
            (
                a, b,
            )
        )rrxrr7r*rr�)r/�s_origZs_tupler	rrr�test_source_segment_multis��
z*EndPositionTests.test_source_segment_multicC�Btd���}d}t�|�jd}|�tj||jddd�|�dS)Nuf
            class C:
                def fun(self) -> None:
                    "ЖЖЖЖЖ"
        u/    def fun(self) -> None:
        "ЖЖЖЖЖ"rT�Zpadded�rrxr*rirlr7r)r/rM�s_methodrrrr�test_source_segment_paddeds��z+EndPositionTests.test_source_segment_paddedcCsdd}t�|�j\}}}}}|�||d�|�||d�|�||d�|�||d�|�||d�dS)Nz!v = 1
w = 1
x = 1

y = 1
z = 1
rzw = 1r�zy = 1zz = 1)r*rirlr)r/r�r'r�rEr|r�rrr�test_source_segment_endingssz,EndPositionTests.test_source_segment_endingscCrO)Nzb
            class C:
              	  def fun(self) -> None:
              	      pass
        z+  	  def fun(self) -> None:
  	      passrTrPrQ)r/r�rRrrrr�test_source_segment_tabs&s�"z)EndPositionTests.test_source_segment_tabscCstd}t�|�j\}}}}|`|`|`|`|�t�||��|�t�||��|�t�||��|�t�||��dS)Nzv = 1
w = 1
x = 1

y = 1
)	r*rirlr
rrr
rPr)r/r�r'r�rEr|rrr� test_source_segment_missing_info2sz1EndPositionTests.test_source_segment_missing_infoN)"rr-rIr�r
rrr�rr�rrrr#r$r)r+r,r-r5r8r�r<r=r?r@rCrKrLrNrSrTrUrVrrrrr�s@

	,


	rc@seZdZdd�ZdS)�NodeVisitorTestscs�G�fdd�dtj�}t�td��}|�}g�tjdd��}t�ddt�|�|�Wd�n1s4wY|�	�gd��|�	d	d
�|D�gd��dS)NcsHeZdZ�fdd�Z�fdd�Z�fdd�Z�fdd�Z�fd	d
�ZdS)z9NodeVisitorTests.test_old_constant_nodes.<locals>.Visitorc���|jd|jf�dS)Nr�)rr
r�r	��logrr�	visit_NumArjzCNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_NumcrX)Nr��rr
r�r	rYrr�	visit_StrCrjzCNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_StrcrX)Nr�r\r	rYrr�visit_BytesErjzENodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_BytescrX)Nr�)rr
r:r	rYrr�visit_NameConstantGrjzLNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_NameConstantcs��|jddf�dS)Nr�.)rr
r	rYrr�visit_EllipsisIr�zHNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_EllipsisN)rr-rIr[r]r^r_r`rrYrr�Visitor@sraz�            i = 42
            f = 4.25
            c = 4.25j
            s = 'string'
            b = b'bytes'
            t = True
            n = None
            e = ...
            T)�record�alwaysr.))r{r�r<)r>r�r�)r�r�r�)r�r�r�)r�r�r�)r>r�T)r�r�N)r�r�.cSsg|]}t|j��qSr)r�message)rr�rrrr	drz<NodeVisitorTests.test_old_constant_nodes.<locals>.<listcomp>)�+visit_Num is deprecated; add visit_Constantrerez+visit_Str is deprecated; add visit_Constantz-visit_Bytes is deprecated; add visit_Constant�4visit_NameConstant is deprecated; add visit_Constantrfz0visit_Ellipsis is deprecated; add visit_Constant)
r*ZNodeVisitorrir�warnings�catch_warnings�filterwarnings�DeprecationWarningZvisitr7)r/raryZvisitorZwlogrrYr�test_old_constant_nodes?s
�
z(NodeVisitorTests.test_old_constant_nodesN)rr-rIrkrrrrrW>srWc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ModuleStateTestscCs<d}d}d}t|||tjd�}t|||�}|�|tj�dS)Nzx + 1rhrT)�flags)rar*rbrv�types�CodeType)r/rS�filenamerrfrrr�check_ast_moduletsz!ModuleStateTests.check_ast_modulecCspt�tjdd��tjd=ddl}tjd=ddl}|��Wd�n1s'wY~~t��|��dS)N�_astr)r�	swap_item�sys�modulesrrrqrO)r/Zast1r�rrr�test_reload_module�s
�
z#ModuleStateTests.test_reload_modulec	s�t���fdd�}t�tjdd��Atjd=t�td|��|��|�dtj�ddl	}|�
|��Wd�n1s=wYWd�dSWd�dS1sUwYdS)Ncs�tj|<�Sr�)rtru)r0r�r�Zlazy_modrr�	my_import�s
z4ModuleStateTests.test_sys_modules.<locals>.my_importrr�
__import__r)�objectrrsrtrur��builtinsrqZassertNotInrrr�)r/rxrrrrwr�test_sys_modules�s��"�z!ModuleStateTests.test_sys_modulescCs"td�}t�|�}|�|d�dS)Nap
            import _ast
            import ast
            import gc
            import sys
            import types

            # Create _ast.AST subclasses instances and call PyAST_Check()
            ast_tree = compile('x+1', '<string>', 'eval',
                               flags=ast.PyCF_ONLY_AST)
            code = compile(ast_tree, 'string', 'eval')
            if not isinstance(code, types.CodeType):
                raise AssertionError

            # Unloading the _ast module must not crash.
            del ast, _ast
            del sys.modules['ast'], sys.modules['_ast']
            gc.collect()
        r)rrZrun_in_subinterpr7)r/rS�resrrr�test_subinterpreter�s
z$ModuleStateTests.test_subinterpreterN)rr-rIrqrvr|r~rrrrrlps

rlcCs�tdkrdStjdd�dgkrEtdftdftdffD]#\}}t|d�|D]}t�|d|�}td	t	|�f�q'td
�qtd�t
�t��dS)N�__main__r{z-grRrSrTz_results = [rWz%r,�]zmain())
rrt�argvrYr[r]�printr*rir�
SystemExit�unittest�main)Z
statementsrXZ	statementrjrrrr��s�
r�r�)r��r{rr{r��r�r�NN)r��r{rr{�)r�r�zmodule docstringNrh)r{rr{r2rr�)ri)r{r0r{r2)r{rr{�)r��r{r0r{r�)r�r�zfunction docstringN)r{rr{r�rd�r{r>r{r�rLNN)ri)r{rr{r)r{rr{r})r��r{r�r{r0rN)ri)r{r%r{r}r�)rd�r{r�r{r1r�NN)ri)r{rr{r�)r{rr{�)rd�r{r�r{rr�NN)ri)r{r~r{r�)r{rr{�G)r�)rd�r{r0r{rr�NN)rd�r{rr{rr�NN)rd�r{�r{r(r&NN)rd)r{�r{r�rNN)rd�r{�#r{�'r�NN)rd)r{�)r{r<rNN)r�)r{�+r{�-r<N)rd)r{�1r{�7r�NN)r��r{r1r{r%r{N)r��r{r}r{�NNr�)r{�r{��r�rE)r{�r{� )r��r{�:r{r�)r�r�zdoc for f()Nrl)r{rr{r%�C)ri)r{r�r{r%)r{rr{r�)r��r{r0r{r�)r�r�zdocstring for class CN)r�r�rzr�)ZReturn�r{r�r{r})r��r{rr{r}r{Nrr�r{rr{r�)r��r{r�r{r�r')ZDelru�r��r{rr{r{r'�ra)r�r�r{N�r{rr{r�r��r{rr{r�)r�r�rLr�)r��r{r>r{r�r�r�r�)r�r�r�r�)r{rr{r0�r��r{r{r{r>rLr�)r��r{r�r{r�r�r�)r�r�r�r�)rw�r{rr{r>r��r�)r��r{r�r{r>r{Nr�)r{rr{r)r�r�r'r�)r�r�r'r�)ri)r{r1r{rr{)r�r�r'r�r})r�r�r'r�)ri)r{r�r{r0)r{rr�r>)r�r�rLr�)ri)r>r>r>r>)r�rr�r>)r�)r�r�r�r>r�r�)ri)r�r>r�r>)r{rr>r>)r�rr>r>)ri)r>r>r>r>r)r{rr{r~)r�)r�r�rEr�)r��r{rr{r1r|r�)ri)r{r2r{r~)r{rr{�)r�)r��r{r2r{rr�r�)r��r{r�r{r&�qr�)ri)r{r�r{r�rr)r{r>r{r�)r�)r{r>r{rr�r�)r�)r{r}r{r�r�Nr�r�)r��r�r�r�r}r�r�)r��r{rr{r�)r��r{r�r{r�r'r�Nr�)r{rr{r)r��r{r�r{rrtNrwrt)r��r{r}r{r~r'Nr�r�r')r�r��r�r�r{N)rir�)ZBreak�r{r1r{r})r{rr{r&)ZContinue)r{r1r{r&)r{r�r{r�)r�r�rLr�)r�r�r�r�)r�r�r�r�)r{rr{r�)r{r�r{r0)r�r�rLr�)r�r�r�r�)r�r�r�r�)rir�r�)r{rr1r�r�)r>r�r>r�)r�)r�r�r�r>�Aar�)r�)r�r�r�r0�Bbr�r�)r�r�rr>)r�)r�r�r�r>r�r�)r�)rr�rr>r�r�)r�)rrrr%ZCcr�)r{rr{�"r��r�r�rLr�)r�r�r�r�)r�r�r�r�)r�r�rEr�)r�r�r�r�)r�)r{�r{r�ryr�)r�)r{r�r{�!r�r�)r{r1r{r)r�r�r'r�)r�r�r�r�)r�r�rEr�r�)r�r�r�r�)r�r�r�r�)r��r{r%r{r2rEr�)r��r{r~r{r�r�r�r�)r�r�r�r�)r�r�rEr�ZAsyncFunctionDef)r{rr�r�)r��r>r{r>r~)r�r�zasync functionN)r�r{r�r�ZAwait)r�r�r�r�)r�r�Z	somethingr�)r{rr�r�ZAsyncFor)r>r{r�r�)r�)r>r1r>r%rr�)r�)r>r}r>r~rdr�)r��r>r&r>r�)r�r�r{N)r��r�r�r�r�)r�r�r>N)r{rr>r�Z	AsyncWith)r>r{r>r�)r�)r�)r>r%r>r2rLr�)r�)r>r~r>r�r�r�)r��r>r�r>r�)r�r�r{N)r�r�r>N)r{r�r{r�)r�r�r>N)r�r�r�Nr�r�)r{r{r{r�)r{r>r{r�)r�r�r{N)r�r�r�Nr�)r�)r>r>r>r�rdr�)r�)r>rr>rr�r�)r�r�r�r�r{)r�rr�r2)ri)r�r0r�r2)r��r{r{r{r>Zdeco1r�)r>r{r>r�)r�)r>r{r>r>Zdeco2r�)r�r{r�r0)r�)r�r{r�r>Zdeco3r�)r�r�r{N)r�rr�r&)ri)r�rr�r&)r>rr>r2)ri)r>r0r>r2)r{r{r{r&)r��r{r{r{r�Zdecor�)r{r�r{r&)r�r�rLr�)r�r�rLr�)r�r�r�r�)r�r�)r�)r{r{r{r�r�r�r�r�r�)r�r�)Z	NamedExpr)r{r{r{r�r�)r�r�r{N)r{rr{r�)�rdr�r�NN)rdr�r&NN)rdr�rNN)ri)r{r�r{r�r�)rdr�r&NN)rd�r{r�r{r�rNN)ri)r{r�r{r�)r{rr{r�)rd)r{r�r{r�r�NN)rir��r�r�r{N)rdr�r�NN)rd)r{r&r{r�r�NN)r��r�r�r>N)r�r�r�N)rdr�r�NN)r�)r{r�r{r�r�Nr�)ri)r{r�r{r�)r{rr{r�)ri)r{r�r{r�)r{rr{r<)rd)r{r�r{r�r�NN)ri)r{�&r{r<)r{rr{r )rd)r{r�r{r�r�NN)ri)r{�$r{r r`)r�r�)r�r�r�r��r�r�r>N)r�r�r�r�)r��r�r�rLr�)r�r�r�r�)r�)r�r�r�r��r�r�r�r�)r�)rIr�)rX)r�r�r'r�r�)r{rr{r1)r�r�NN�r�r�r{N�r�r�r>N�r{rr{r>)r�r�NN)r{rr�r>)r�)r>r>r>r�r{N)r�)r�rr�r1r>N)r�r�r�r�)r�r�r&r�r�)r�r�rLr�r�)r�r�rLr�)r�r�r�r�)r�r�r�r�)r{rr{r�r�)r�r�r�r�)r�)r{r�r{r�r�r�r�r�)ZLt�r�r�r�N)r�r�rr�)r�r�)r�)r{rr{r%)r�r�r&r�r�)rp)r{r>r{r0r�r�)rp)r{r2r{r}N)r�r�rr�)r{r>r{r0)r{r�r{r0)r�r�rN)r�r�r{N)r{r{r{r)r�r�rLr�)r�r�r�r�)r�)r�r�rN)r�)r�r�r�N)r��r�r�r�r�r�)r�)r�r�r�)r�)r{r>r{r�)r�r�r�r�)r�r�r�r�Nr�)r�)r�r�r'r�))r�r�r{N)r�r�r>N)r�r�r�N)r�r�)r�r�r�N)r�r�)r�r�r�r�r�r&r�)r�r�)r�)r{r�r{r1)r�r�rLr�r�r�)r�)r{r%r{r)r�r�r{N)r�r�r>NNr�)r*r{r�r�rtrnr�rgrM�textwraprr rrrYr[r]ZTestCaser)r�r]r�rrWr�rlr�rZr\r^rrrr�<module>s�
�KGZ2Q
�
�,�,�.�0�,�,�L	�
���,
���"�"�"�
����$�&����&��
�� �!�
"�
#�$�%�&&�&'�&(�<)�4*�2+�&,�0-�D.�>/�:0�,1�,2�F3�H4�H5�66�N7�.8�
9�.:�2;�8<�8=�0>�6?�8@�8A�8B�<C�F�����&����	�"
�"�@�B
�B�@�B�B�@�B�B�&�"�2�2�������� �!�"�#�
%
© 2025 GrazzMean