a
    ze^                 O   @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ dd Zg dZdgZg dZG d	d
 d
ejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZejG dd dejZdd Zddgg fddgg fdddddg g dg g dg fd gg ddfgg fddd!ddg g dg g dg fd"gg ddfgg fddd#ddg d$gdg g dg fd%gg ddfgg fddd&ddg d$gdg g dd'gfd(gg ddfgg fddd)ddg g d*g g dg fd+gg ddfgg fddd,ddg g dg g d-g fd.gg ddfgg fddd/ddg g d0d1d2gd3gd4d5d6d7d8g d9fd:d;g g fgfd<gg ddfgg fdd=d>d?g g d@gg fgg fdd=dAd?g g dBgg fgg fdd=d,d?dCgg d.gg fgg fddd&ddg g dg g dg fdDgg ddfgg fddEdFdGgfgg fddHdFdIgdJdfgg fddHdKdLdMdNdOgdPfgdQdfgg fddHdRdLdFdSdTgdPfgdUdfgg fddHdRd7dFdSdTgdPfgdUdfgg fddVgg fddWdXdYdZd[gg dfgg fdd\d>d]d@gg fgg fdd^dRd_d`gg fgg fdd^dadbdcgd^dddedfgg fgfgg fdd^dgdbdcgd^dhdedfgdigfgfgg fddjdkdlgdmgdfgg fddjdndldogdpgdfgg fddqdndrdsdtdugg fdfgg fddvdadcgdwdddxddfgfgg g fgg fddvdadcgg g dfgfgg fddygg fddzd{d|gfgg fdd}dkd~dgd fgg fddddgfgg fddgg fddgg fddWd&dYdZdgg dfgg fddWddYdZdgg dfgg fddWd)dLdddgdPfdd+gg dfgg fddWddLdddgdPfddgg dfgg fddWdd7dddgdPfddgg dfgg fddddddLdddgd9fddLdddgdPfdg d fgffgg fddddddddddg d fddddgd fgffgg fdddddddddLdddgdPfdg d fgffgg fddddddddddgd fgffgg fddd&dd&dddLdddgdPfdg d fgffgg fdddddg g dg g dg fddddddrddg g fffgg ddfgg fdddddg g dg g dg fdddddgdgdfgg ddfgg fdddddg g dg g dg fdddgdgdfgg ddfgg fddd#d:d#ddgd:ddJgdgfdgffgg fddd>dd>ddddddgfd9fdgffgg fdddddg g dg g dg fddddddddg dfgffgg ddfgg fdddddg g dg g dg fdgddrddg g fdrdddgg fgddfgg fdddddg g dg g dg fdgddrddg g fdrdddgg fgddfgg fdd=dd?g g dgddrddg g fdrdddgg fgfgg fdddddg g dg g dg fdgdrddddddddg d fgfgg fgddfgg fdddddg g dg g dg fdgdgddfgg fddgg fddd)ddd$gg dg g dg fd+gg ddfgg fdddddd$gg ddg g dg fdgg ddfgg fddd!ddd$gdgdddgddgdg fdgg ddfgg fdddddd$gdgdddgddgdg fdgg ddfgg fdddddd$gg dg g ddgfdgg ddfgg fddd!ddd$gddgdg g dg dfdgg ddfgg fdddAddd$gdgddgdgdddgfdgg ddfgg fdddddd$gdgddgdgdddgfdgg ddfgg fdddddd$gdgddgdgdddgfdgg ddfgg fdddddd$gdgddgdgd ddgfdgg ddfgg fgCZddgfgZddddKddd	gffd
dddddg g dg g dg fdffdd:dKdgdgffdd:dg g ffdddKdgffdd:ddgdgffddddddddgd fgffddddddddgd fgffddddLdddgd9fddLdddgdPfdg d fgffddϐddLdddgd9fddLddd gdPfd!g d fgffddϐddLdddgd9fdd7ddd gdPfd!g d fgffddddLdddgd9fddLdddgdPfdg d fgffddddLdddgd9fddLddd gdPfd!g d fgffddddLdddgd9fdd7ddd gdPfd!g d fgffddddLdddgd9fddLdddgdPfdg d fgffddddLdddgd9fddLddd gdPfd!g d fgffddddLdddgd9fdd7ddd gdPfd!g d fgffdd"dRd#d$d$gdd%gffddrdkd&g d'd(d)gffddrd{d&dʐd*d7d+d,d-gd9fd9fgg ffddrdXd&dd.ddd/d0g d fgfgg ffd1d2d3d4d5dd7dKg d6d9ffdd7dg d9ffddLdFg d7d9ffddLdKg d6d9ffddLdg d9ffddrdkd8d9gg ffg#Ze  dS (:      N)dedent)supportc                 C   s   | d u st | tttfr| S t | tr4dd | D S | jjg}t| drt| dr|| j	| j
f t| drt| dr|d  | j| jf7  < | jd u rt|S | jD ]}|tt| | qt|S )Nc                 S   s   g | ]}t |qS  )to_tuple).0er   r   #/usr/lib/python3.9/test/test_ast.py
<listcomp>       zto_tuple.<locals>.<listcomp>lineno
col_offset
end_linenoend_col_offset)
isinstancestrintcomplexlist	__class____name__hasattrappendr   r   r   r   _fieldstupler   getattr)tresultfr   r   r   r      s    



r   )CNonez'module docstring'zdef f(): passzdef f(): 'function docstring'zdef f(a): passzdef f(a=0): passzdef f(*args): passzdef 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'zclass C(object): passzdef f():return 1zdel vv = 1za,b = cz	(a,b) = cz	[a,b] = czv += 1zfor v in v:passzwhile v:passz	if v:passzif a:
  pass
elif b:
  passz(if a:
  pass
elif b:
  pass
else:
  passzwith x as y: passzwith x as y, z as q: passzraise Exception('string')z$try:
  pass
except Exception:
  passztry:
  pass
finally:
  passzassert vz
import syszfrom sys import vzglobal v1passzfor v in v:breakzfor v in v:continuezfor a,b in c: passzfor (a,b) in c: passzfor [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)zdef f(a, /,): passzdef f(a, /, c, d, e): passzdef f(a, /, c, *, d, e): passz'def f(a, /, c, *, d, e, **kwargs): passzdef f(a=1, /,): passzdef f(a=1, /, b=2, c=4): passz def f(a=1, /, b=2, *, c=4): passzdef 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): passz1+2)#r   za and ba + bznot vzlambda: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 < 3zf(1,2,c=3,*d,**e)
f(*[0, 1])zf(a for a in b)Z10z'string'a.bza[b:c]vz[1,2,3]z[]z1,2,3z(1,2,3)()za.b.c.d(a.b[1:2])c                   @   s
  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zejd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?S )@	AST_Testsc                 C   s0   t |tsdS d|jvrdS |dko.|d  S )NFastASTr   )r   type
__module__isupper)selfnamenoder   r   r   _is_ast_node   s
    

zAST_Tests._is_ast_nodec                 C   s   t |tjr|jd u rd S t |tjtjtjfrT|j|jf}| 	|| |j|jf}|jD ]h}t
||}t |tr|}|r|dkr|d j|d jf}|D ]}| || qqZ|d urZ| || qZd S )Ndecorator_listr   )r   r+   r,   r   exprstmtZexcepthandlerr   r   ZassertGreaterEqualr   r   _assertTrueorder)r0   ast_nodeZ
parent_posZnode_posr1   valueZ	first_poschildr   r   r   r7     s     


zAST_Tests._assertTrueorderc                 C   s   t  }| |jd d|_| |jd | |jd d | t |j W d    n1 sb0    Y  | t	 t d W d    n1 s0    Y  d S )Nr   *   foobar   )
r+   r,   assertEqualr   r<   __dict__assertRaisesAttributeErrorvararg	TypeErrorr0   xr   r   r   test_AST_objects  s    $zAST_Tests.test_AST_objectsc                 C   sL   G dd d}t  }| |_||j_t|j}~t  | |  d S )Nc                   @   s   e Zd ZdS )z0AST_Tests.test_AST_garbage_collection.<locals>.XNr   r.   __qualname__r   r   r   r   X$  s   rI   )	r+   r,   rE   aweakrefrefr   
gc_collectassertIsNone)r0   rI   rJ   rL   r   r   r   test_AST_garbage_collection#  s    z%AST_Tests.test_AST_garbage_collectionc              
   C   s   t tdfttdfttdffD ]\}}}t||D ]\}}| jd|d< t|d|t	j
}| t|| | |d W d    n1 s0    Y  | jd||d	 t|d| W d    q01 s0    Y  q0qd S )
NexecsingleevalZparsing)actioninput?)r   r   Z	compiling)rS   rT   kind)
exec_testsexec_resultssingle_testssingle_results
eval_testseval_resultszipsubTestcompiler+   PyCF_ONLY_ASTr>   r   r7   )r0   rT   outputrV   ioast_treer   r   r   test_snippets.  s    *zAST_Tests.test_snippetsc                 C   s0   t t t }|D ]}t|}t|dd qd S )N<string>rP   )rW   rY   r[   r+   parser_   )r0   Zsnippets_to_validateZsnippettreer   r   r   test_ast_validation:  s    
zAST_Tests.test_ast_validationc                 C   s<   t djd jj}| |j | |j | |j d S )Nzx[::]r   )	r+   rg   bodyr9   slicerN   upperlowerstep)r0   Zslcr   r   r   
test_sliceA  s    zAST_Tests.test_slicec                 C   s    t djd }| |j d S )Nzfrom . import yr   )r+   rg   rj   rN   module)r0   imr   r   r   test_from_importG  s    zAST_Tests.test_from_importc                 C   s>   t d}| |jd t j d |jd _t|dd d S )Nzfrom __future__ import divisionr   z __future__ <test>rP   )r+   rg   assertIsInstancerj   
ImportFromstriprp   r_   )r0   modr   r   r   !test_non_interned_future_from_astK  s    
z+AST_Tests.test_non_interned_future_from_astc                 C   s|   |  ttjtj |  ttjtj |  ttjtj |  ttjtj |  ttjtj |  ttj	tj d S N)

assertTrue
issubclassr+   Forr6   Namer5   r,   comprehensionZGtr0   r   r   r   test_base_classesQ  s    zAST_Tests.test_base_classesc                 C   sR   t j D ]B\}}| ||r
|dkr(q
| }t|t jr
| t|jt	 q
d S )NZIndex)
r+   r?   itemsr3   r   r,   r>   r-   r   r   )r0   r1   itemrE   r   r   r   test_field_attr_existenceY  s    z#AST_Tests.test_field_attr_existencec                 C   s   t  }| |jd | t |j W d    n1 s<0    Y  | |j t jt	dd }| |jd | |jd d S )N)posonlyargsargsrB   
kwonlyargskw_defaultskwargdefaults      r=      )
r+   	argumentsr>   r   r@   rA   r   rN   rB   rangerD   r   r   r   test_argumentsd  s    $zAST_Tests.test_argumentsc                 C   s    t  }d|_| |jd d S )Ni  )r+   Numr   r>   rD   r   r   r   test_field_attr_writableq  s    z"AST_Tests.test_field_attr_writablec                 C   s  t  }| |jd | t |j W d    n1 s<0    Y  | t |j W d    n1 sl0    Y  t d}| |jd | |jd | t |j W d    n1 s0    Y  | t |j	 W d    n1 s0    Y  t jdd}| |jd t jddd}| |jd | |jd | |jd | |jd | t
t jdd d | jt
t jdd ddd | t jdddjd | t jdddjd | t
d	 t jddd
 W d    n1 s0    Y  | t
d t jddd W d    n1 s&0    Y  | t djd | t djd | t djd | t djd | t djd | t djd | t djd | t d jd  | t djd | t djd | t djd | t djd | t djd | t djd | t djd | t d jd  | t djd d S )N)r9   rV   r;   r=   r   r   r   Zbar)fooz(Num got multiple values for argument 'n'nz1Constant got multiple values for argument 'value'r9         @              @42   42TF.)r+   r   r>   r   r@   rA   r9   r   r   r<   rC   Constantr   assertRaisesRegexStrsBytesassertIsNameConstantrD   r   r   r   test_classattrsw  sZ    $$
$$..zAST_Tests.test_classattrsc                 C   s   |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttd tj |  tt tj d S )Nr;   r   r   r   r   TF)	r>   r-   r+   r   r   r   r   r   Ellipsisr   r   r   r   test_realtype  s    zAST_Tests.test_realtypec                 C   s  |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttd tj |  tt tj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttdtj |  ttd tj |  ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	ttdtj | 	tt tj | 	tt tj | 	tt tj | 	tt tj | 	tt tj G d	d
 d
t
}|  tt|dtj | 	tt|dtj d S )Nr;   g@y        @r   r   TF.c                   @   s   e Zd ZdS )z$AST_Tests.test_isinstance.<locals>.SNrG   r   r   r   r   S  r
   r   )rz   r   r+   r   r   r   r   r   r   assertFalser   )r0   r   r   r   r   test_isinstance  sP    zAST_Tests.test_isinstancec                 C   s   G dd dt j}G dd dt j}|d}| |jd | |jd | t|| | t|| | t|t j | t|| | tt d| |dd}| |jd | t|| d S )Nc                       s   e Zd Z fddZ  ZS )z$AST_Tests.test_subclasses.<locals>.Nc                    s   t  j|i | d| _d S )Nspam)super__init__z)r0   r   kwargsr   r   r   r     s    z-AST_Tests.test_subclasses.<locals>.N.__init__)r   r.   rH   r   __classcell__r   r   r   r   N  s   r   c                   @   s   e Zd ZdS )z%AST_Tests.test_subclasses.<locals>.N2NrG   r   r   r   r   N2  s   r   r;   r   r   )	r+   r   r>   r   r   r-   rz   r   r   )r0   r   r   r   r   r   r   test_subclasses  s    
zAST_Tests.test_subclassesc                 C   s*   t dg}t |g }| |j| d S )Nr;   )r+   r   Moduler>   rj   )r0   rj   rE   r   r   r   test_module  s    zAST_Tests.test_modulec              	   C   s  t  }| |jd d|_| |jd t d}t d}t  }t |||}| |j| | |j| | |j	| t ddd}| |jd | |jd | |j	d t jddddd}| |jd | |jd | |j	d | |j
d | tt jdddd | jtt jdddddd t jddddd	}| |jd | |jd | |j	d | |j
d t jdddd
d}| |jd
 d S )N)leftopright   r   r   r=   r   r      )r   r   r   r   r;   )	foobarbaz)r+   BinOpr>   r   r   r   Addr   r   r   r   r@   rC   )r0   rE   Zn1Zn3Zaddopr   r   r   test_nodeclasses  s:    

zAST_Tests.test_nodeclassesc                 C   s   t  }| |jd d S )Nr   )r+   ZSubr>   r   rD   r   r   r   test_no_fields2  s    zAST_Tests.test_no_fieldsc           	   	   C   s   dd l }|g}zdd l}|| W n ty6   Y n0 g d}|D ]H}|D ]>}dd tD D ]*}||||}| t|t| q^qLqDd S )Nr   )r   r   r=   c                 s   s   | ]}t |d ddV  qdS )rU   rP   i   N)r_   )r   rb   r   r   r   	<genexpr>B  r
   z*AST_Tests.test_pickling.<locals>.<genexpr>)	picklecPickler   ImportErrorrW   loadsdumpsr>   r   )	r0   r   Zmodsr   Z	protocolsrw   protocolr+   ast2r   r   r   test_pickling7  s    zAST_Tests.test_picklingc                 C   s   t ddd}ttjtjf i |fi |gg }| t}t|dd W d    n1 s`0    Y  | dt	|j
 d S )Nr=   r   r   r   rs   rP   zbut got <ast.expr)dictr+   r   Exprr5   r@   rC   r_   assertInr   	exception)r0   posmcmr   r   r   test_invalid_sumF  s
    (*zAST_Tests.test_invalid_sumc              	   C   sv   t t t dt  gg }t | | t}t|dd W d    n1 sV0    Y  | 	dt
|j d S )Nr;   rs   rP   zidentifier must be of type str)r+   r   r   r}   Loadfix_missing_locationsr@   rC   r_   r   r   r   )r0   r   r   r   r   r   test_invalid_identifierM  s
     
*z!AST_Tests.test_invalid_identifierc              	   C   sx   t ddt ftddt ffD ]X}tjt|d}t| | td t|dd W d    q1 sh0    Y  qd S )Nr   r=   rj   zinvalid type in Constant: typers   rR   )	r   	frozensetr+   
Expressionr   r   r   rC   r_   )r0   Zinvalid_constantr   r   r   r   test_invalid_constantT  s    
zAST_Tests.test_invalid_constantc                 C   sj   t d}d |jd jd j_| t}t|dd W d    n1 sJ0    Y  | dt|j	 d S )Nzdef f():
 yield from g()r   rs   rP   zfield 'value' is required)
r+   rg   rj   r9   r@   
ValueErrorr_   r   r   r   )r0   Zempty_yield_fromr   r   r   r   test_empty_yield_from]  s
    
*zAST_Tests.test_empty_yield_fromc                 C   sR   dd l }dd }t|d|  | ttjd W d    n1 sD0    Y  d S )Nr   c                  W   s   d S ry   r   r   r   r   r   bad_normalizej  s    z0AST_Tests.test_issue31592.<locals>.bad_normalize	normalizeu   ϕ)unicodedatar   	swap_attrr@   rC   r+   rg   )r0   r   r   r   r   r   test_issue31592e  s    zAST_Tests.test_issue31592c                 C   sD  t d}|jd j}|j}|j}| |jd | |jd | |jd | |jd | |jd | |jd t d}|jd j}|j}|j}| |jd | |jd | |jd | |j	d	 | |jd | |jd | |jd	 | |j	d	 | |jd | |jd | |jd | |j	d d S )
Nz4+5+6+7r      r   r   z
4+5-\
 6-7r   r   r=   )
r+   rg   rj   r9   r   r>   r   r   r   r   )r0   rh   Zparent_binopZchild_binopZgrandchild_binopr   r   r    test_issue18374_binop_col_offseto  s4    

z*AST_Tests.test_issue18374_binop_col_offsetc                 C   s.   t d}|jd jd j}| |jd d S )Nr#   r   r   )r+   rg   rj   r4   r9   r>   r   )r0   rh   Zattr_br   r   r   *test_issue39579_dotted_name_end_col_offset  s    
z4AST_Tests.test_issue39579_dotted_name_end_col_offsetc                 C   s   |  tjjd |  tjjd |  tjjd |  tjjd dd tj D }dtj d j |d< | 	tjj
d	| d S )
Nz0withitem(expr context_expr, expr? optional_vars)GtEz%Name(identifier id, expr_context ctx)zBcmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotInc                 S   s   g | ]}d |j  qS )z     | )__doc__)r   r2   r   r   r   r	     r
   z5AST_Tests.test_ast_asdl_signature.<locals>.<listcomp>zexpr = r   
)r>   r+   withitemr   r   r}   Zcmpopr5   __subclasses__ZassertCountEqualsplit)r0   Zexpressionsr   r   r   test_ast_asdl_signature  s    z!AST_Tests.test_ast_asdl_signaturec                 C   sJ   t jddd | t t jddd W d    n1 s<0    Y  d S )Nzf"{x=}")r   r   )Zfeature_version)r   r   )r+   rg   r@   SyntaxErrorr   r   r   r   test_issue40614_feature_version  s    z)AST_Tests.test_issue40614_feature_versionc              	   C   sn   dD ]d}t t |t  }t | | td| d t|dd W d    q1 s^0    Y  qd S )N)TrueFalser   zName node can't be used with 'z
' constantrs   rR   )r+   r   r}   r   r   r   r   r_   )r0   Zconstantr5   r   r   r   test_constant_as_name  s
    
zAST_Tests.test_constant_as_nameN)$r   r.   rH   r3   r7   rF   rO   re   ri   ro   rr   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   cpython_onlyr   r   r   r   r   r   r   r   r   r   r*      s@   </,	
		r*   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 ZdS )2ASTHelpers_TestNc                 C   s6   t d}tdddt j}| t |t | d S )Nz
foo(1 + 1)z	<unknown>rP   )r+   rg   r_   r`   r>   dump)r0   rJ   br   r   r   
test_parse  s    
zASTHelpers_Test.test_parsec                 C   sf   zdd  W nT t y`   | t}td W d    n1 sD0    Y  | |jj Y n0 d S )Nr   r   z'\U')	Exceptionr@   r   r+   literal_evalZassertIsNotNoner   __context__r0   r   r   r   r   test_parse_in_error  s    (z#ASTHelpers_Test.test_parse_in_errorc                 C   sL   t d}| t |d | t j|ddd | t j|ddd d S )	Nspam(eggs, "and cheese")zModule(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+   rg   r>   r   r0   r2   r   r   r   	test_dump  s    
zASTHelpers_Test.test_dumpc                 C   sT   t d}| t j|ddd | t j|dddd | t j|d	dd
d d S )Nr   r   )indentzModule(
   body=[
      Expr(
         value=Call(
            func=Name(id='spam', ctx=Load()),
            args=[
               Name(id='eggs', ctx=Load()),
               Constant(value='and cheese')],
            keywords=[]))],
   type_ignores=[])F	)r   r   zModule(
	[
		Expr(
			Call(
				Name('spam', Load()),
				[
					Name('eggs', Load()),
					Constant('and cheese')],
				[]))],
	[])T)r   r   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=[])r   r   r   r   r   test_dump_indent  s    
z ASTHelpers_Test.test_dump_indentc                 C   s   t jddd}| t |d | t j|ddd t jt jdt  d	ddd
}| t |d | t j|ddd | t j|ddd | t j|dddd t jt jdt  d	d}| t |d | t j|ddd d S )Nr   r   r   zRaise()Tr   zRaise(lineno=3, col_offset=4)r   )idctx)excr   r   z#Raise(exc=Name(id='e', ctx=Load()))Fr   zRaise(Name('e', Load()))z;Raise(exc=Name(id='e', ctx=Load()), lineno=3, col_offset=4))r   r   z0Raise(Name('e', Load()), lineno=3, col_offset=4))causez%Raise(cause=Name(id='e', ctx=Load()))zRaise(cause=Name('e', Load())))r+   Raiser>   r   r}   r   r   r   r   r   test_dump_incomplete  s6    z$ASTHelpers_Test.test_dump_incompletec                 C   s   t jddd}t t d|jj|j_| t j|ddd t jddddd	}t |t jd d d
}| 	|j
 | 	|j | |jd | |jd d S )N1 + 1rR   moder=   Tr   zExpression(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   )r   r   r   r   )r   r   )r+   rg   copy_locationr   rj   r   r>   r   CallrN   r   r   r   r   )r0   srcnewr   r   r   test_copy_location(  s    z"ASTHelpers_Test.test_copy_locationc                 C   sl   t d}|jt t t dt  t dgg  | 	|t 
| d | _| 	t j|ddd d S )Nzwrite("spam")r   ZeggsTr   a  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+   rg   rj   r   r   r  r}   r   r   r>   r   maxDiffr   r0   r  r   r   r   test_fix_missing_locations8  s    
z*ASTHelpers_Test.test_fix_missing_locationsc                 C   s   t jddd}| t j|dd| | t j|ddd t jddd}| t j|jdd|j | t j|ddd t jt d	t  g g d
d}| t |j	d | 
t |j d S )Nr	  rR   r
  r   r   Tr   zExpression(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+   rg   r>   Zincrement_linenor   rj   r  r}   r   r   rN   r   r  r   r   r   test_increment_linenoL  s    z%ASTHelpers_Test.test_increment_linenoc                 C   sH   t jddd}tt |j}| |djd | |g g d d S )Nfoo()rR   r
  r  r   )r  r   )r+   rg   r   Ziter_fieldsrj   r>   popr  )r0   r2   dr   r   r   test_iter_fieldsd  s    z ASTHelpers_Test.test_iter_fieldsc                 C   s   t jddd}| ttt |jd t |j}| t|jd | t|j	d | t|j	d | t 
t|d d S )	Nzspam(23, 42, eggs='leek')rR   r
  r   r      r;   z1keyword(arg='eggs', value=Constant(value='leek')))r+   rg   r>   lenr   Ziter_child_nodesrj   nextr  r9   r   )r0   r2   iteratorr   r   r   test_iter_child_nodesj  s    z%ASTHelpers_Test.test_iter_child_nodesc                 C   s   t d}| t |d t d}| t |jd d t d}| t |jd d t d}| t |jd d d S )Nz"""line one
  line two"""zline one
line twoz&class foo:
  """line one
  line two"""r   z&def foo():
  """line one
  line two"""z#async def foo():
  """spam
  ham"""zspam
ham)r+   rg   r>   get_docstringrj   r   r   r   r   test_get_docstringu  s    



z"ASTHelpers_Test.test_get_docstringc                 C   s.  |  ttd td}|  t| td}|  t| td}|  t|jd  td}|  t|jd  td}|  t|jd  td}|  t|jd  td}|  t|jd  td	}|  t|jd  td
}|  t|jd  d S )N zx = "not docstring"zdef foo():
  passzclass foo:
  passr   z class foo:
  x = "not docstring"z class foo:
  def bar(self): passz def foo():
  x = "not docstring"zasync def foo():
  passz&async def foo():
  x = "not docstring")rN   r+   r!  rg   rj   r   r   r   r   test_get_docstring_none  s&    








z'ASTHelpers_Test.test_get_docstring_nonec                 C   s  t d}| |jd jd | |jd jd | |jd jd jd | |jd jd jd | |jd jd jd jd | |jd jd jd jd | |jd jd jd | |jd jd jd | |jd jd | |jd jd	 d S )
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"""

r   r   r=   r   r   	         )r+   rg   r>   rj   r   r   r   r   r   r   :test_multi_line_docstring_col_offset_and_lineno_issue16806  s      zJASTHelpers_Test.test_multi_line_docstring_col_offset_and_lineno_issue16806c                 C   s:   t d}|jd jd }| |jd | |jd d S )Nz if a:
    pass
elif b:
    pass
r   r   r+   rg   rj   orelser>   r   r   r0   r2   Z	elif_stmtr   r   r   test_elif_stmt_start_position  s    
z-ASTHelpers_Test.test_elif_stmt_start_positionc                 C   s:   t d}|jd jd }| |jd | |jd d S )Nz/if a:
    pass
elif b:
    pass
else:
    pass
r   r   r)  r+  r   r   r   'test_elif_stmt_start_position_with_else  s    
z7ASTHelpers_Test.test_elif_stmt_start_position_with_elsec                 C   s<   t d}|jd jjd }| |jd | |jd d S )Nr&   r   r   r%  )r+   rg   rj   r9   r   r>   r   r   )r0   r2   Zstarred_exprr   r   r   *test_starred_expr_end_position_within_call  s    
z:ASTHelpers_Test.test_starred_expr_end_position_within_callc                 C   s@  |  tdg d |  tdddi |  tdd |  tdh d	 |  td
d |  tdt  | ttjd |  tdd |  tdd |  tdd |  tdd |  tdd |  tdd |  ttdd | ttjd | ttjd | ttjd d S )Nz	[1, 2, 3]r   r=   r   z{"foo": 42}r   r;   z(True, False, None))TFNz	{1, 2, 3}>   r   r=   r   zb"hi"s   hizset()r  6   z+6z-6iz3.25g      
@z+3.25z-3.25g      
z-0.0z++6z+Truez2+3)r>   r+   r   setr@   r   reprr   r   r   r   test_literal_eval  s"    z!ASTHelpers_Test.test_literal_evalc              	   C   s   t dr td | t}td W d    n1 s@0    Y  | dt|j | dt|j W d    n1 s0    Y  d S )Ni  A  3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333A  33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333zExceeds the limit z Consider hexadecimal )	r   Zadjust_int_max_str_digitsr+   r   r@   r   r   r   r   )r0   Zerr_ctxr   r   r   test_literal_eval_str_int_limit  s    
(z/ASTHelpers_Test.test_literal_eval_str_int_limitc                 C   s>  |  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
 | ttjd | ttjd | ttjd | ttjd | ttjd d S )NZ6jy              @z-6jy             z6.75jy              @z-6.75jy             z3+6jy      @      @z-3+6jy            @z3-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+3jz3+-6jz3+(0+6j)z-(3+6j))r>   r+   r   r@   r   r   r   r   r   test_literal_eval_complex  s$    z)ASTHelpers_Test.test_literal_eval_complexc                 C   sp   t jt dt dgt dgd}| tt j| t jt dgt dt dgd}| tt j| d S )Nr   r=   r   )keysvalues)r+   Dictr   r@   r   r   )r0   Z	malformedr   r   r   &test_literal_eval_malformed_dict_nodes  s    &&z6ASTHelpers_Test.test_literal_eval_malformed_dict_nodesc                 C   sx   t jdt jddgd d d dg}t |g }| t}t|dd W d    n1 sX0    Y  | dt|j	 d S )Ntimesleepr1   rp   nameslevelr   r   r  rP   zinvalid integer value: None)
r+   ru   aliasr   r@   r   r_   r   r   r   )r0   rj   rw   r   r   r   r   test_bad_integer  s    *z ASTHelpers_Test.test_bad_integerc                 C   sV   t jdt jddgd dddg}t |g }t|dd}i }t|| | d| d S )Nr;  r<  r=  r   r>  r  rP   )r+   ru   rA  r   r_   rP   r   )r0   rj   rw   codensr   r   r   test_level_as_none  s    
z"ASTHelpers_Test.test_level_as_nonec              	   C   s   t jt  ddd}||_| tJ t " tt 	|dd W d    n1 sV0    Y  W d    n1 st0    Y  d S Nr   )r   r   r   rs   rR   
r+   UnaryOpNotoperandr@   RecursionErrorr   Zinfinite_recursionr_   r   r   r   r   r   test_recursion_direct  s
    
z%ASTHelpers_Test.test_recursion_directc              	   C   s   t jt  ddd}t jt  ddd}||_||_| tJ t " tt 	|dd W d    n1 sp0    Y  W d    n1 s0    Y  d S rF  rG  )r0   r   r   r   r   r   test_recursion_indirect  s    
z'ASTHelpers_Test.test_recursion_indirect)r   r.   rH   r  r   r   r   r  r  r  r  r  r  r   r"  r$  r(  r,  r-  r.  r4  r5  r6  r:  rB  rE  rL  rM  r   r   r   r   r     s2   =r   c                   @   s  e Zd Zd`edddZdaedddZdbdd	Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<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_ Z1dS )cASTValidatorTestsNrP   r  c                C   sx   d |_ |_t| |d u r,t|d| nH| |}t|d| W d    n1 sX0    Y  | |t|j d S )Nr   rs   )	r   r   r+   r   r_   r@   r   r   r   )r0   rw   msgr  r  r   r   r   r   rw   !  s    
*zASTValidatorTests.modc                C   s(   t t |gg }| j|||d d S )NrO  )r+   r   r   rw   )r0   r2   rP  r  rw   r   r   r   r5   +  s    zASTValidatorTests.exprc                 C   s   t |gg }| || d S ry   )r+   r   rw   )r0   r6   rP  rw   r   r   r   r6   /  s    zASTValidatorTests.stmtc              	   C   sT   t t t dt  g}| |dd t t dt  }| |dd d S )NrE   must have Load contextrQ   rR   )r+   Interactiver   r}   Storerw   r   )r0   r   r   r   r   r   3  s    zASTValidatorTests.test_modulec              	      s  d fdd	}t dt dt  g}|||dd |||dd |||dd ||t dgd	d
 ||t dgdd t dt dt  g}|||t dt  gdd t dt dt  t dt dt  g}|||d t dt  gdd d S )Nc              	      sZ   | d u rg } |d u rg }|d u r$g }|d u r0g }|d u r<g }t | ||||||}  | S ry   )r+   r   )r   r   rB   r   r   r   r   facr   r   r   :  s    z5ASTValidatorTests._check_arguments.<locals>.argumentsrE   r   rQ  )r   )r   r   )r   z"more positional defaults than argsr   )r   z3length of kwonlyargs is not the same as kw_defaults)r   r   rJ   r   y)r   r   )NNNNNNN)r+   argr}   rS  r   r   )r0   rU  checkr   r   r   rT  r   _check_arguments9  s4       z"ASTValidatorTests._check_argumentsc                 C   s   t g g d g g d g }t d|g g d }| |d t d|t  gt dt  gd }| |d t d|t  gg t dt  }| |d dd }| || j d S )NrE   zempty body on FunctionDefrQ  c                 S   s   t d| t  gg d S NrE   )r+   FunctionDefPassr   r   r   r   rU  e  s    z+ASTValidatorTests.test_funcdef.<locals>.fac)r+   r   r[  r6   r\  r}   rS  rY  )r0   rJ   r   rU  r   r   r   test_funcdef[  s     zASTValidatorTests.test_funcdefc                 C   s   ddd}|  |tdt gdd |  |tdtdt gdd |  |g dd |  |d gdd	 |  |tdt gd
d d S )Nc                 S   sH   | d u rg } |d u rg }|d u r*t  g}|d u r6g }t d| |||S )NZmyclass)r+   r\  ClassDef)basesr  rj   r4   r   r   r   clsj  s    

z,ASTValidatorTests.test_classdef.<locals>.clsrE   )r_  rQ  )r  r   zempty body on ClassDefNone disallowed)r4   )NNNN)r6   r+   r}   rS  keyword)r0   r`  r   r   r   test_classdefi  s    
"zASTValidatorTests.test_classdefc              	   C   sJ   |  tg d |  td gd |  ttdt gd d S )Nzempty targets on Deletera  rE   zmust have Del context)r6   r+   Deleter}   r   r   r   r   r   test_delete~  s
    zASTValidatorTests.test_deletec              
   C   s   |  tg tdd |  td gtdd |  ttdt gtdd |  ttdt gtdt d d S )Nr   zempty targets on Assignra  rE   must have Store contextrV  rQ  )r6   r+   Assignr   r}   r   rS  r   r   r   r   test_assign  s    "zASTValidatorTests.test_assignc              	   C   sp   t t dt  t  t dt  }| |d t t dt  t  t dt  }| |d d S )NrE   rV  rf  rQ  )r+   	AugAssignr}   r   r   r6   rS  )r0   Zaugr   r   r   test_augassign  s    z ASTValidatorTests.test_augassignc              
   C   s   t dt  }t dt  }t  }| t ||g g d | t t dt  ||gg d | t |t dt  |gg d t t dt  }| t |||gg d | t |||g|gd d S )NrE   rV  zempty body on Forrf  rQ  )r+   r}   rS  r   r\  r6   r|   r   )r0   rE   rV  pr   r   r   r   test_for  s      zASTValidatorTests.test_forc                 C   s~   |  ttdg g d |  ttdt t gg d |  ttdt gttdt gd d S )Nr   zempty body on WhilerE   rQ  )r6   r+   Whiler   r}   rS  r\  r   r   r   r   r   
test_while  s    "zASTValidatorTests.test_whilec                 C   s   |  ttdg g d ttdt t gg }|  |d ttdttdt gg }|  |d ttdt gttdt g}|  |d d S )Nr   zempty body on IfrE   rQ  )r6   r+   Ifr   r}   rS  r\  r   )r0   rb   r   r   r   test_if  s     (zASTValidatorTests.test_ifc                 C   s   t  }| t g |gd t t dd }| t |gg d t t dt  d }| t |g|gd t t dt dt  }| t |g|gd d S )Nzempty items on Withr   zempty body on WithrE   rQ  rf  )	r+   r\  r6   Withr   r   r}   rS  r   )r0   rk  rb   r   r   r   	test_with  s    zASTValidatorTests.test_withc                 C   sp   t d t d}| |d t t dt  d }| |d t t dt dt  }| |d d S )Nr   z!Raise with cause but no exceptionrE   rQ  r   )r+   r  r   r6   r}   rS  )r0   rr   r   r   
test_raise  s    zASTValidatorTests.test_raisec                 C   sx  t  }t g g g |g}| |d t t t dt  gg g |g}| |d t |gg g g }| |d t |gg |g|g}| |d t |gt d dg gg g }| |d t t dt  d|gg}| t |g|g g d t d d|gg}t |g|t t dt  g|g}| |d t |g||gt t dt  g}| |d d S )Nzempty body on TryrE   rQ  z-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlerszempty body on ExceptHandlerrV  )r+   r\  Tryr6   r   r}   rS  ExceptHandler)r0   rk  r   r   r   r   r   test_try  s$    &((zASTValidatorTests.test_tryc              	   C   sT   |  ttdt d d ttdt tdt }|  |d d S )NrE   rQ  rV  )r6   r+   Assertr}   rS  r   )r0   Zassrtr   r   r   test_assert  s    zASTValidatorTests.test_assertc                 C   s   |  tg d d S )Nzempty names on Import)r6   r+   Importr   r   r   r   test_import  s    zASTValidatorTests.test_importc                 C   s>   t d t dd gd}| |d | t d g dd d S )NrE   izNegative ImportFrom levelr   zempty names on ImportFrom)r+   ru   rA  r6   )r0   impr   r   r   test_importfrom  s    z!ASTValidatorTests.test_importfromc                 C   s   |  tg d d S )Nzempty names on Global)r6   r+   Globalr   r   r   r   test_global  s    zASTValidatorTests.test_globalc                 C   s   |  tg d d S )Nzempty names on Nonlocal)r6   r+   ZNonlocalr   r   r   r   test_nonlocal  s    zASTValidatorTests.test_nonlocalc                 C   s&   t t dt  }| |d d S NrE   rQ  )r+   r   r}   rS  r6   r   r   r   r   	test_expr  s    zASTValidatorTests.test_exprc              	   C   s   t t  g }| |d t t  t dg}| |d t t  t dd g}| |d t t  t dt dt  g}| |d d S )Nzless than 2 valuesr   r   ra  rE   rQ  )r+   BoolOpAndr5   r   r}   rS  )r0   r   r   r   r   test_boolop  s    &zASTValidatorTests.test_boolopc                 C   s,   t t  t dt  }| |d d S r  )r+   rH  rI  r}   rS  r5   )r0   ur   r   r   test_unaryop  s    zASTValidatorTests.test_unaryopc              
   C   sP   t g g d g g d g }| t |t dt  d dd }| || j d S )NrE   rQ  c                 S   s   t | t dt  S rZ  )r+   Lambdar}   r   r   r   r   r   rU    s    z*ASTValidatorTests.test_lambda.<locals>.fac)r+   r   r5   r  r}   rS  rY  )r0   rJ   rU  r   r   r   test_lambda  s    zASTValidatorTests.test_lambdac                 C   sX   t dt  }t dt  }|||f|||f|||ffD ]}| t j| d q<d S NrE   rV  rQ  )r+   r}   r   rS  r5   ZIfExp)r0   lr   r   r   r   r   
test_ifexp	  s     zASTValidatorTests.test_ifexpc                 C   sR   t g t dt  g}| |d t t dt  gd g}| |d d S )NrE   zsame number of keys as valuesra  )r+   r9  r}   r   r5   )r0   r  r   r   r   	test_dict  s    zASTValidatorTests.test_dictc                 C   s<   |  td gd ttdt g}|  |d d S Nra  rE   rQ  )r5   r+   Setr}   rS  r0   r   r   r   r   test_set  s    zASTValidatorTests.test_setc              	   C   s   |  |g d ttdt tdt g d}|  ||gd ttdt tdt g d}|  ||gd tdt }tdt }t||d gd}|  ||gd t||tdt gd}|  ||gd d S )Nz comprehension with no generatorsrE   r   rf  rQ  rV  ra  )r5   r+   r~   r}   r   rS  )r0   rU  grE   rV  r   r   r   _check_comprehension  s    z&ASTValidatorTests._check_comprehensionc                    sb   t t dt  t dt  g d}|  t dt  |gd  fdd}| | d S )NrE   r   rQ  c                    s    t dt  | S rZ  )r+   r}   rS  )ZgensrT  r   r   wrap.  s    z,ASTValidatorTests._simple_comp.<locals>.wrap)r+   r~   r}   rS  r   r5   r  )r0   rU  r  r  r   rT  r   _simple_comp)  s    zASTValidatorTests._simple_compc                 C   s   |  tj d S ry   )r  r+   ListCompr   r   r   r   test_listcomp2  s    zASTValidatorTests.test_listcompc                 C   s   |  tj d S ry   )r  r+   SetCompr   r   r   r   test_setcomp5  s    zASTValidatorTests.test_setcompc                 C   s   |  tj d S ry   )r  r+   GeneratorExpr   r   r   r   test_generatorexp8  s    z#ASTValidatorTests.test_generatorexpc                 C   s   t t dt  t dt  g d}t t dt  t dt  |g}| |d t t dt  t dt  |g}| |d dd }| | d S )NrV  rk  r   rE   rQ  c                 S   s.   t dt  }t dt  }t ||| S )NrE   rV  )r+   r}   r   DictComp)compskr(   r   r   r   factoryD  s    z0ASTValidatorTests.test_dictcomp.<locals>.factory)r+   r~   r}   rS  r   r  r5   r  )r0   r  cr  r   r   r   test_dictcomp;  s    zASTValidatorTests.test_dictcompc              	   C   s@   |  ttdt d |  ttdt d d S )NrE   zmust have Load)r5   r+   ZYieldr}   rS  Z	YieldFromr   r   r   r   
test_yieldJ  s    zASTValidatorTests.test_yieldc                 C   s   t dt  }t |t  gg }| |d t |t  gt dt dg}| |d t t dt  g|g}| | t |t  gt dg}| | d S )NrE   zno comparatorsr   r   z,different number of comparators and operandsZblah)r+   r}   r   CompareZInr5   r   )r0   r   compr   r   r   test_compareN  s    $
zASTValidatorTests.test_comparec                 C   s   t dt  }t dt  g}t dt dt  g}t t dt  ||}| |d t |d g|}| |d t dt dt  g}t |||}| |d d S )NrE   rV  wr   rQ  ra  )r+   r}   r   rb  r  rS  r5   )r0   r  r   r  callZbad_keywordsr   r   r   	test_callY  s    zASTValidatorTests.test_callc                 C   sz   G dd dt }G dd dt}G dd dt}dD ]}| t| q4| | | fD ]}| jt|dtd	 qZd S )
Nc                   @   s   e Zd ZdS )z*ASTValidatorTests.test_num.<locals>.subintNrG   r   r   r   r   subintf  s   r  c                   @   s   e Zd ZdS )z,ASTValidatorTests.test_num.<locals>.subfloatNrG   r   r   r   r   subfloath  s   r  c                   @   s   e Zd ZdS )z.ASTValidatorTests.test_num.<locals>.subcomplexNrG   r   r   r   r   
subcomplexj  s   r  )0Zhellozinvalid typerO  )r   floatr   r5   r+   r   rC   )r0   r  r  r  objr   r   r   test_nume  s    zASTValidatorTests.test_numc                 C   s.   t t dt  dt  }| |d d S r  )r+   	Attributer}   rS  r   r5   )r0   attrr   r   r   test_attributeq  s    z ASTValidatorTests.test_attributec              	   C   s  t t dt  t dt  }| |d t dt  }t |t dt  t  }| |d t dt  }|d d fd |d fd d |ffD ](}t j| }| t ||t  d qt g t  }| t ||t   t |gt  }| t ||t  d d S )NrE   r   rQ  rV  )	r+   	Subscriptr}   rS  r   r   r5   SliceTuple)r0   subrE   r   r   slr   r   r   test_subscriptu  s&     
z ASTValidatorTests.test_subscriptc              	   C   sN   t t t dt  t  gt  }t |gt d}| |d d S )NrE   r   rf  )	r+   ListStarredr}   r   rS  rg  r   r6   )r0   r   assignr   r   r   test_starred  s
     zASTValidatorTests.test_starredc                 C   s@   |  |d gt d |  |tdt gt d d S r  )r5   r+   r   r}   rS  )r0   rU  r   r   r   	_sequence  s    zASTValidatorTests._sequencec                 C   s   |  tj d S ry   )r  r+   r  r   r   r   r   	test_list  s    zASTValidatorTests.test_listc                 C   s   |  tj d S ry   )r  r+   r  r   r   r   r   
test_tuple  s    zASTValidatorTests.test_tuplec                 C   s   |  td d S )Nr   )r5   r+   r   r   r   r   r   test_nameconstant  s    z#ASTValidatorTests.test_nameconstantc              
   C   s   t jtj}dd t |D }|ddg |D ]}| |l t j||}t	|ddd}|
 }W d    n1 s~0    Y  t||}t||d W d    q41 s0    Y  q4d S )	Nc                 S   s   g | ]}| d r|qS )z.py)endswith)r   fnr   r   r   r	     r
   z;ASTValidatorTests.test_stdlib_validates.<locals>.<listcomp>ztest/test_grammar.pyztest/test_unpack_ex.pyrs  zutf-8)encodingrP   )ospathdirnamer+   __file__listdirextendr^   joinopenreadrg   r_   )r0   Zstdlibtestsrp   r  fpsourcerw   r   r   r   test_stdlib_validates  s    &z'ASTValidatorTests.test_stdlib_validates)NrP   )N)N)2r   r.   rH   r   rw   r5   r6   r   rY  r]  rc  re  rh  rj  rl  rn  rp  rr  rt  rw  ry  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   rN    s\   

"	


	rN  c                   @   sf   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
ejdd Zdd Zdd ZdS )ConstantTestsz$Tests on the ast.Constant node type.c                 C   s\   t d}|jd j}t j|d}t || ||jd _t|dd}i }t|| |d S )Nzx = 123r   r   rf   rP   rE   )r+   rg   rj   r9   r   r  r_   rP   )r0   r9   rh   r2   new_noderC  rD  r   r   r   compile_constant  s    

zConstantTests.compile_constantc                 C   sN   |  t}| g d W d    n1 s.0    Y  | t|jd d S )Nr/  z%got an invalid type in Constant: list)r@   rC   r  r>   r   r   )r0   r   r   r   r   test_validation  s
    ,zConstantTests.test_validationc              	   C   s^   d ddt dt fD ]F}| j|d& | |}| || W d    q1 sN0    Y  qd S )NFTr
   )const)r   r   r^   r  r   )r0   r  r9   r   r   r   test_singletons  s    
zConstantTests.test_singletonsc              	   C   s   d}t dh}tdD ]}|df}t |dh}qddddd	td
t d||f	}|D ]F}| j|d& | |}| || W d    qR1 s0    Y  qRd S )N)r   r   r   r=   {   g     ^@y             ^@unicode   bytesr   r   r   )r   r   r   r^   r  r>   )r0   Znested_tupleZnested_frozensetr@  r8  r9   r   r   r   r   test_values  s    

zConstantTests.test_valuesc                 C   s   t d}|jd jd }t jdd}t || ||jd jd< | t}t|dd W d    n1 sn0    Y  | 	t
|jd d S )Nx = 1r   r   r   stringrP   z6expression which can't be assigned to in Store context)r+   rg   rj   targetsr   r  r@   r   r_   r>   r   r   )r0   rh   target
new_targetr   r   r   r   test_assign_to_constant  s    
*z%ConstantTests.test_assign_to_constantc                 C   s    t d}| t |d d S )Nz'docstring'
x = 1Z	docstring)r+   rg   r>   r!  )r0   rh   r   r   r   r"    s    
z ConstantTests.test_get_docstringc                 C   s:   t |dd}g }t|D ]}|jdkr||j q|S )Nrf   rP   Z
LOAD_CONST)r_   disZget_instructionsopnamer   Zargval)r0   rh   coconstsZinstrr   r   r   get_load_const  s    
zConstantTests.get_load_constc                 C   s   g d}d dd |D }|d7 }|td f t|}| | || t|j|D ](\}}tj	|d}t
||j ||_qZ| | || d S )N)	NTF|   g       @y              @r  r  r/  r   c                 S   s   g | ]}d  |qS )zx={!r})format)r   r  r   r   r   r	     r
   z1ConstantTests.test_load_const.<locals>.<listcomp>z
x = ...r   )r  r  r   r+   rg   r>   r  r]   rj   r   r  r9   )r0   r  rC  rh   r  r  r  r   r   r   test_load_const  s    	
zConstantTests.test_load_constc                 C   sl   t d}|jd j}t jdd}t ||j ||_t jdd}t ||j ||_| t 	|d d S )Nz1 + 2r   
   r   y              4@y      $@      4@)
r+   rg   rj   r9   r   r  r   r   r>   r   )r0   rh   binopZnew_leftZ	new_rightr   r   r   r4    s    
zConstantTests.test_literal_evalc                 C   s   t jdddj}| |jd | |jd  t jdddj}| |jd | |jd t jdddj}| |jd | |jd  t jdddj}| |jd	 | |jd  d S )
Nz"x"rR   r
  rE   zu"x"r  zr"x"zb"x"   x)r+   rg   rj   r>   r9   rV   )r0   r  r   r   r   test_string_kind  s    zConstantTests.test_string_kindN)r   r.   rH   r   r  r  r  r  r  r"  r  r   r   r  r4  r  r   r   r   r   r    s   

r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>S )?EndPositionTestszTests for end position of AST nodes.

    Testing end positions of nodes requires a bit of extra care
    because of how LL parsers work.
    c                 C   s    |  |j| |  |j| d S ry   )r>   r   r   )r0   r8   r   r   r   r   r   _check_end_pos3  s    zEndPositionTests._check_end_posc                 C   s   |  t||| d S ry   )r>   r+   get_source_segment)r0   r  r8   Zcontentr   r   r   _check_content7  s    zEndPositionTests._check_contentc                 C   s   t |jd jS )Nr   )r+   rg   rj   r9   r  r   r   r   _parse_value:  s    zEndPositionTests._parse_valuec                 C   sJ   d}|  |}| ||jd | ||jjd d | ||jjd d S )Nzlambda x, *y: Noner   r   rE   rV  )r  r  rj   r   rB   )r0   r   Zlamr   r   r   r  ?  s
    
zEndPositionTests.test_lambdac                 C   s   t d }t|jd }| |dd | ||jd d | ||jjd d | ||jjd jd | ||jj	d | ||jj	jd	 d S )
Nz
            def func(x: int,
                     *args: str,
                     z: float = 0,
                     **kwargs: Any) -> bool:
                return True
            r   r      zreturn Truezx: intr   zkwargs: AnyAny)
r   rv   r+   rg   rj   r  r  r   
annotationr   r0   r   Zfdefr   r   r   test_func_defF  s    zEndPositionTests.test_func_defc                 C   sN   d}|  |}| ||jd | ||jd jd | ||jd jd d S )Nzfunc(x, y=2, **kw)r  r   2r   kw)r  r  r  r  r9   r0   r   r  r   r   r   r  V  s
    
zEndPositionTests.test_callc                 C   s0   d}|  |}| ||jd | |dd d S )Nzx[0]()zx[0]r   r1  )r  r  r  r  r  r   r   r   test_call_noargs]  s    
z!EndPositionTests.test_call_noargsc                 C   sV   t d }t|jd }| |dd | ||jd d | ||jd d d S )Nz?
            class C(A, B):
                x: int = 0
        r   r=      r   Bz
x: int = 0)r   rv   r+   rg   rj   r  r  r_  r0   r   cdefr   r   r   test_class_defc  s
    zEndPositionTests.test_class_defc                 C   s.   d}t |jd }| ||jd jd d S )Nz$class S(metaclass=abc.ABCMeta): passr   zabc.ABCMeta)r+   rg   rj   r  r  r9   r  r   r   r   test_class_kwm  s    zEndPositionTests.test_class_kwc                 C   s>   t d }t|jd }| |dd | |jdd d S )Nzh
            x = """Some multi-line text.

            It goes on starting from same indent."""
        r   r   (   r   rv   r+   rg   rj   r  r9   r0   r   r  r   r   r   test_multi_line_strr  s    z$EndPositionTests.test_multi_line_strc                 C   s>   t d }t|jd }| |dd | |jdd d S )NzB
            x = "first part" \
            "second part"
        r   r=   r'  r  r  r   r   r   test_continued_str|  s    z#EndPositionTests.test_continued_strc                 C   s  t d }t|}|jd }|jd }|jd }|jd }|jd }| |dd | |dd	 | |d	d
 | |dd | |dd | ||jd | ||jd d | ||jd jd | ||j	d | ||jd d | ||j
d jd d S )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
        r   r   r=   r   r   r   r%     r        r   zx = Nonezother()x, yzraise RuntimeErrorrC   )r   rv   r+   rg   rj   r  r  r  r*  r  handlersr-   )r0   r   rw   Z
while_loopZif_stmtZfor_loopZtry_stmtZ	pass_stmtr   r   r   test_suites  s$    





zEndPositionTests.test_suitesc                 C   s,   d}|  |}|jd j}| ||d d S )Nzx = f"abc {x + y} abc"r   zx + y)r  r8  r9   r  r0   r   Zfstrr  r   r   r   test_fstring  s    
zEndPositionTests.test_fstringc                 C   sT   t d }| |}|jd j}| |dd | ||jd | ||jd d S )Nz
            f"""Some multi-line text.
            {
            arg_one
            +
            arg_two
            }
            It goes on..."""
        r   r   r   Zarg_oneZarg_two)	r   rv   r  r8  r9   r  r  r   r   r  r   r   r   test_fstring_multi_line  s    	
z(EndPositionTests.test_fstring_multi_linec                 C   s.   t d }t|jd }| |dd d S )NzT
            from x.y.z import (
                a, b, c as c
            )
        r   r   r   )r   rv   r+   rg   rj   r  )r0   r   r|  r   r   r   test_import_from_multi_line  s    z,EndPositionTests.test_import_from_multi_linec                 C   s   d}d}t d }t| j|||f\}}}| ||jd | ||jjd | ||jjd | ||jjd | ||jj	d jd	 | ||jj	d
 jd | 
|dd d S )Nzf()[1, 2] [0]zx[ a.b: c.d]zN
            x[ a.b: f () ,
               g () : c.d
              ]
        z	f()[1, 2]z1, 2r'   zc.dr   f ()r   g ()r   )r   rv   mapr  r  r9   rk   rm   rl   eltsr  )r0   s1s2smZi1Zi2rq   r   r   r   test_slices  s    zEndPositionTests.test_slicesc                 C   sZ   t d }| |}| |dd | ||jd | ||jd | ||jjd d S )NzF
            (1 * 2 + (3 ) +
                 4
            )
        r=   r1  4z1 * 2 + (3 )3)r   rv   r  r  r  r   r   )r0   r   r  r   r   r   
test_binop  s    
zEndPositionTests.test_binopc                 C   sD   t d }t|jd j}| |dd | ||jd d d S )Nz{
            if (one_condition and
                    (other_condition or yet_another_one)):
                pass
        r   r=   ,   r   z"other_condition or yet_another_one)	r   rv   r+   rg   rj   r  r  r  r8  )r0   r   Zbopr   r   r   r    s    zEndPositionTests.test_boolopc           	      C   sp   d}d}d}t d }t| j||||f\}}}}| ||d | ||d | ||d | |dd	 d S )
Nzx = () ;z	x = 1 , ;zx = (1 , 2 ) ;z?
            x = (
                a, b,
            )
        r)   z1 ,z(1 , 2 )r   r   )r   rv   r  r  r  r  )	r0   r  r  Zs3r  t1t2Zt3Ztmr   r   r   test_tuples  s    zEndPositionTests.test_tuplesc                 C   s4   d}|  |}| ||| | ||jd d d S )Nzfunc(x. y .z)r   zx. y .z)r  r  r   r  r   r   r   test_attribute_spaces  s    
z&EndPositionTests.test_attribute_spacesc                 C   sv   d}t |jd j}| t|jd | ||d d| }t |jd jj}| t|jd | ||d d S )Nz( ( ( a + b ) ) )r   r   r$   await )r+   rg   rj   r9   r>   r-   r   r  )r0   r   r(   r  r   r   r   test_redundant_parenthesis  s    z+EndPositionTests.test_redundant_parenthesisc              	   C   s   d}|D ]\}}|  |~ t|jd j}| t|j| | ||| d| }t|jd jj}| t|j| | ||| W d    q1 s0    Y  qd S )N))z( ( ( a ) ) ) ( )r  )z( ( ( a ) ) ) ( b )r  )z( ( ( a ) ) ) [ b ]r  )z( ( ( a ) ) ) . br  r   r   )	r^   r+   rg   rj   r9   r>   r-   r   r  )r0   r  r   r   r(   r  r   r   r   (test_trailers_with_redundant_parenthesis  s    z9EndPositionTests.test_trailers_with_redundant_parenthesisc                 C   s   d}d}|  |}|  |}| ||jd d | ||jd d | ||jd d | ||jd d	 | ||jd d
 d S )Nz[{}, {1, }, {1, 2,} ]z{a: b, f (): g () ,}r   r%   r   z{1, }r=   z{1, 2,}r  r  )r  r  r  r7  r8  )r0   r  r  c1c2r   r   r   test_displays(  s    

zEndPositionTests.test_displaysc                 C   s   t d }| |}| |dd | ||jd jd | ||jjd jd | ||jjd jd d | ||jjd j	d d S )	Nza
            x = [{x for x, y in stuff
                  if cond.x} for stuff in things]
        r=   %   r   Zthingsstuffzcond.xr	  )
r   rv   r  r  r  
generatorsitereltifsr  )r0   r   cmpr   r   r   test_comprehensions3  s    
z$EndPositionTests.test_comprehensionsc                 C   sL   t d }t|jd }| ||jd jd | ||jd jd d S )NzT
            async def f():
                yield x
                await y
        r   zyield xr   zawait y)r   rv   r+   rg   rj   r  r9   r  r   r   r   test_yield_await?  s    z!EndPositionTests.test_yield_awaitc                 C   s<   t d }t d }| |}| t||j| d S )NzD
            x = (
                a, b,
            ) + ()
        z;
            (
                a, b,
            )
        )r   rv   r  r>   r+   r  r   )r0   s_origZs_tupler  r   r   r   test_source_segment_multiI  s    
z*EndPositionTests.test_source_segment_multic                 C   sB   t d }d}t|jd }| tj||jd dd| d S )Nuf   
            class C:
                def fun(self) -> None:
                    "ЖЖЖЖЖ"
        u/       def fun(self) -> None:
        "ЖЖЖЖЖ"r   TZpaddedr   rv   r+   rg   rj   r>   r  )r0   r/  s_methodr  r   r   r   test_source_segment_paddedW  s    z+EndPositionTests.test_source_segment_paddedc                 C   sd   d}t |j\}}}}}| ||d | ||d | ||d | ||d | ||d d S )Nz!v = 1
w = 1
x = 1
y = 1z = 1
r    zw = 1r  zy = 1zz = 1)r+   rg   rj   r  )r0   r   r(   r  rE   rV  r   r   r   r   test_source_segment_endingsc  s    z,EndPositionTests.test_source_segment_endingsc                 C   sB   t d }d}t|jd }| tj||jd dd| d S )Nzb
            class C:
              	  def fun(self) -> None:
              	      pass
        z+  	  def fun(self) -> None:
  	      passr   Tr1  r2  )r0   r   r3  r  r   r   r   test_source_segment_tabsl  s    z)EndPositionTests.test_source_segment_tabsc                 C   st   d}t |j\}}}}|`|`|`|`| t || | t || | t || | t || d S )Nzv = 1
w = 1
x = 1
y = 1
)	r+   rg   rj   r   r   r   r   rN   r  )r0   r   r(   r  rE   rV  r   r   r    test_source_segment_missing_infox  s    z1EndPositionTests.test_source_segment_missing_infoN)"r   r.   rH   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.  r0  r4  r5  r6  r7  r   r   r   r   r  -  s>   

	,	

	r  c                   @   s   e Zd Zdd ZdS )NodeVisitorTestsc                    s   G  fdddt j}t td}| }g  tjdd(}tddt || W d    n1 sh0    Y  | 	 g d | 	d	d
 |D g d d S )Nc                       sH   e Zd Z fddZ fddZ fddZ fddZ fd	d
ZdS )z9NodeVisitorTests.test_old_constant_nodes.<locals>.Visitorc                    s     |jd|jf d S )Nr   )r   r   r   r   logr   r   	visit_Num  s    zCNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_Numc                    s     |jd|jf d S )Nr   r   r   r   r   r9  r   r   	visit_Str  s    zCNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_Strc                    s     |jd|jf d S )Nr   r<  r   r9  r   r   visit_Bytes  s    zENodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_Bytesc                    s     |jd|jf d S )Nr   )r   r   r9   r   r9  r   r   visit_NameConstant  s    zLNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_NameConstantc                    s     |jddf d S )Nr   .)r   r   r   r9  r   r   visit_Ellipsis  s    zHNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_EllipsisN)r   r.   rH   r;  r=  r>  r?  r@  r   r9  r   r   Visitor  s
   rA  z            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  )r1  r   T)r   r   N)r   r   .c                 S   s   g | ]}t |jqS r   )r   message)r   r  r   r   r   r	     r
   z<NodeVisitorTests.test_old_constant_nodes.<locals>.<listcomp>)+visit_Num is deprecated; add visit_ConstantrE  rE  z+visit_Str is deprecated; add visit_Constantz-visit_Bytes is deprecated; add visit_Constant4visit_NameConstant is deprecated; add visit_ConstantrF  z0visit_Ellipsis is deprecated; add visit_Constant)
r+   ZNodeVisitorrg   r   warningscatch_warningsfilterwarningsDeprecationWarningZvisitr>   )r0   rA  rw   ZvisitorZwlogr   r9  r   test_old_constant_nodes  s    
(
z(NodeVisitorTests.test_old_constant_nodesN)r   r.   rH   rK  r   r   r   r   r8    s   r8  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ModuleStateTestsc                 C   s<   d}d}d}t |||tjd}t |||}| |tj d S )Nzx + 1rf   rR   )flags)r_   r+   r`   rt   typesCodeType)r0   rC  filenamer  rd   r   r   r   check_ast_module  s    z!ModuleStateTests.check_ast_modulec                 C   sp   t tjdd 8 tjd= dd l}tjd= dd l}|   W d    n1 sN0    Y  ~~t   |   d S )N_astr   )r   	swap_itemsysmodulesrR  rQ  rM   )r0   Zast1r   r   r   r   test_reload_module  s    &z#ModuleStateTests.test_reload_modulec              	      s   t    fdd}ttjdd p tjd= ttd|: |   | dtj dd l	}| 
|  W d    n1 sz0    Y  W d    n1 s0    Y  d S )Nc                    s    t j| <  S ry   )rT  rU  )r1   r   r  Zlazy_modr   r   	my_import  s    
z4ModuleStateTests.test_sys_modules.<locals>.my_importrR  
__import__r   )objectr   rS  rT  rU  r   builtinsrQ  ZassertNotInrR  r   )r0   rX  rR  r   rW  r   test_sys_modules  s    z!ModuleStateTests.test_sys_modulesc                 C   s"   t d}t|}| |d d S )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   )r   r   Zrun_in_subinterpr>   )r0   rC  resr   r   r   test_subinterpreter  s    
z$ModuleStateTests.test_subinterpreterN)r   r.   rH   rQ  rV  r\  r^  r   r   r   r   rL    s   rL  c                  C   s   t dkrd S tjdd  dgkrtdftdftdffD ]F\} }t|d  | D ]$}t|d|}td	t	|f  qNtd
 q6td t
t  d S )N__main__r   z-grP   rQ   rR   z_results = [rU   z%r,]zmain())r   rT  argvrW   rY   r[   printr+   rg   r   
SystemExitunittestmain)Z
statementsrV   Z	statementrh   r   r   r   re    s    
re  r   )r   r   r   r   r   r   rf  NN)r   r   r   r      )r   rh  zmodule docstringNr[  )r   r   r   r'  r   r   )r\  )r   r%  r   r'  )r   r   r      )r   r   r%  r   rj  )r   rk  zfunction docstringN)r   r   r   r  rW  r   r1  r   r   rJ   NN)r\  )r   r  r   r  )r   r   r      )r   r   r   r   r%  r   N)r\  )r   r  r   rn  rh  )rW  r   r   r   r&  r   NN)r\  )r   r  r   ri  )r   r   r      )rW  r   r   r   r  r   NN)r\  )r   r  r   rq  )r   r   r   G   )rl  )rW  r   r%  r   r  r   NN)rW  r   r  r   r  r  NN)rW  r      r   r  r  NN)rW  )r      r   rj  r   NN)rW  r   #   r   '   r   NN)rW  )r   )   r   r;   r   NN)r   )r   +   r   -   r;   N)rW  )r   1   r   7   r   NN)r   r   r&  r   r  r   N)r   r   rn  r      NNr  )r      r      r   r9  )r      r       )r   r   :   r   rs  )r   r  zdoc for f()Nr^  )r   r   r   r  C)r\  )r   r   r   r  )r   r   r   r  )r   r   r%  r   r  )r   r  zdocstring for class CN)r}   rr  rZ  r  )ZReturnr   r   r   rn  )r   r   r  r   rn  r   Nrd  r   r   r   r   )r}   r   r   r   r   r(   )ZDelrg  r}   r   r   r   r   r(   rS  )r   r  r   Nr   r   r   r   r  r   r   r   r   )r}   r  rJ   r  )r}   r   r=   r   r   r   r  r  )r}   rm  r  r  )r   r   r   r%  r}   r   r   r   r=   rJ   r  )r}   r   r   r   r   r   r  )r}   ro  r  r  )ri  r   r   r   r1  r  r   )r   r   r   r   r1  r   Nr|   )r   r   r   r  )r}   r  r(   r  )r}   rt  r(   r  )r\  )r   r&  r   r  rm  )r}   rm  r(   r  ro  )r}   r  r(   r  )r\  )r   r   r   r%  )r   r   r   r1  )r}   r  rJ   r  )r\  )r=   r=   r=   r1  )r   r   r   r1  )r}   )r   r   r   r1  r   r  )r\  )r   r=   r   r1  )r   r   r1  r1  )r   r   r1  r1  )r\  )r1  r=   r1  r1  rq  )r   r   r   r  )r   )r}   r  rE   r  )r}   r   r  r   r&  rV  r  )r\  )r   r'  r   r  )r   r   r      )r   )r}   r   r'  r   r  r   r  )r}   r   ri  r   r  qr  )r\  )r   rq  r   r  r  r  )r   r1  r   r  )r}   )r   r1  r   r  r   r  )r   )r   rn  r   r  r  Nru  rv  )r}   r   r   r   rn  r   r  )rx  r   r   r   r   )r}   r   r   r   r   r(   r  Nrz  )r   r   r   r  )rA  rT  Nru   rT  )rA  r(   Nr~  r  r(   )r   r  r   r  r   N)r\  rf  )ZBreakr   r&  r   rn  )r   r   r   r  )ZContinue)r   r&  r   r  )r   r   r   r   )r}   r  rJ   r  )r}   rm  r   r  )r}   r  r  r  )r   r   r   r  )r   r   r   r%  )r}   r  rJ   r  )r}   r  r   r  )r}   r  r  r  )r\  r  r   )r   r   r&  r   r  )r=   r   r1  r   )r}   )r   r   r   r1  Aar  )r}   )r   r   r   r%  Bbr  r~   )r   r   r  r1  )r}   )r   r   r   r1  r  r  )r}   )r  r   r  r1  r  r  )r}   )r  r  r  r  ZCcr  )r   r   r   "   r  r}   r  rJ   r  )r}   r  r   r  )r}   r  r  r  )r}   r   rn  r   r  rE   r  )r}   rv  r   r  )r}   )r      r   rx  rk  r  )r}   )r   r  r   !   r  r  )r   r&  r   r  )r}   r  r(   r  )r}   r  r  r  )r}   r  rE   r  r  )r}   r  rs  r  )r}   r  r  r  )r}   r   r  r   r'  rE   r  )r}   r   r  r   ri  r  r  )r   r   r   r  )r}   rt  r   r  )r}   ru  rE   r  ZAsyncFunctionDef)r   r   r   ri  )r   r=   r   r=   r  )r   r  zasync functionN)r   r   r   ri  ZAwait)r   r   r   ri  )r}   r  Z	somethingr  )r   r   r   r   ZAsyncFor)r=   r   r   r   )r}   )r=   r&  r=   r  r   r  )r}   )r=   rn  r=   r  rb   r  )r   r=   r  r=   r  )r   r  r   N)r   r   r   r   r   )r   r  r=   N)r   r   r=   rq  Z	AsyncWith)r=   r   r=   rq  )r   )r}   )r=   r  r=   r'  rJ   r  )r}   )r=   r  r=   ri  r   r  )r   r=   r  r=   rq  )r   r  r   N)r   r  r=   N)r   r   r   r   )r   rm  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   rb   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   r1  Zdeco1r  )r=   r   r=   r   )r}   )r=   r   r=   r1  Zdeco2r  )r   r   r   r%  )r}   )r   r   r   r1  Zdeco3r  )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}   r   r   r   r   Zdecor  )r   r   r   r  )r}   rm  rJ   r  )r}   r  rJ   r  )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   rm  r   N)r   r   r   r  )rW  r  r  NN)rW  r  r  NN)rW  r  r   NN)r\  )r   rw  r   r  r  )rW  r  r  NN)rW  r   rq  r   rw  r   NN)r\  )r   r  r   rj  )r   r   r   r{  )rW  )r   r  r   r  r   NN)r\  ry  r   ro  r   N)rW  ru  r   NN)rW  )r   r  r   r  r  NN)r  r   r  r=   N)r   r  r   N)rW  rv  r  NN)r   )r   r  r   r  r   Nr  )r\  )r   rx  r   r  )r   r   r   r  )r\  )r   r  r   r  )r   r   r   r;   )rW  )r   rj  r   rz  r   NN)r\  )r   &   r   r;   )r   r   r   r  )rW  )r   r  r   r  r   NN)r\  )r   $   r   r  rR  )r   r  )r   r  r  r  r   r  r=   N)r   rg  r   r  )r  r}   r  rJ   r  )r}   rm  r   r  )r   )r   r  r  r  r}   r  r   r  )r   )rH  r  )rI  )r}   r  r(   r  r  )r   r   r   r&  )r   rp  NNr   r  r   Nr   r  r=   Nr   r   r   r=   )r   r  NN)r   r   r   r1  )r   )r=   r1  r=   r   r   N)r   )r   r  r   r&  r=   N)r}   r  r  r  )r}   r  r  r  r  )r}   r  rJ   r  r  )r}   r  rJ   r  )r}   r  r   r  )r}   r  r  r  )r   r   r   rw  r  )r}   ru  r   r  )r}   )r   r  r   rq  r  r  r  r  )ZLtr   ro  r   N)r}   r  r   r  )r  r  )r  )r   r  r   r  )r}   r  r  r  r  )rb  )r   r1  r   r%  r  r  )rb  )r   r'  r   rn  N)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}   ro  rJ   r  )r}   r  r   r  )r   )r   r  r  N)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   r&  )r}   ro  rJ   r  r   r  )r  )r   r  r   r  )r   r  r   N)r   ru  r=   NNr  )r+   r[  r  r  rT  rN  rd  rG  rK   textwrapr   r  r   r   rW   rY   r[   ZTestCaser*   r   rN  r  r  r8  r   rL  re  rX   rZ   r\   r   r   r   r   <module>   s   
K   2  x      Y2Q

,,.0,,L,"""
$&&


&&&<42&0D>:,,FHH6N.
.28806888<F&""@BB@BB@BB&"22%