o
    GXh                    @   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g 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ZddgfgZg 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Ze  dS (:      N)dedent)supportc                 C   s   | d u st | tttfr| S t | trdd | D S | jjg}t| drHt| drH|| j	| j
f t| drHt| drH|d  | j| jf7  < | jd u rQt|S | jD ]}|tt| | qTt|S )Nc                 S   s   g | ]}t |qS  )to_tuple).0er   r   7/opt/python-3.10.19/usr/lib/python3.10/test/test_ast.py
<listcomp>   s    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d3d4 Zejd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGS )H	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r*|j|jf}| 	|| |j|jf}|jD ]4}t
||}t |trW|}|rK|dkrK|d j|d jf}|D ]}| || qMq-|d ura| || q-| |j|j d S )Ndecorator_listr   )r   r*   r+   r   exprstmtZexcepthandlerr
   r   ZassertGreaterEqualr   r   _assertTrueorderassertEqual__match_args__)r/   ast_nodeZ
parent_posZnode_posr0   valueZ	first_poschildr   r   r   r6     s&   


zAST_Tests._assertTrueorderc                 C   s   t  }| |jd d|_| |jd | |jd d | t |j W d    n1 s1w   Y  | t	 t d W d    d S 1 sLw   Y  d S )Nr   *   foobar   )
r*   r+   r7   r   r=   __dict__assertRaisesAttributeErrorvararg	TypeErrorr/   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                   @      e Zd ZdS )z0AST_Tests.test_AST_garbage_collection.<locals>.XNr   r-   __qualname__r   r   r   r   X%      rJ   )	r*   r+   rE   aweakrefrefr   
gc_collectassertIsNone)r/   rJ   rL   rN   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 ]Z\}}}t||D ]O\}}| jd|d t|d|t	j
}| t|| | |d W d    n1 sDw   Y  | jd||d	 t|d| W d    n1 sbw   Y  qqd S )
NexecsingleevalZparsing)actioninput?)r   r   Z	compiling)rU   rV   kind)
exec_testsexec_resultssingle_testssingle_results
eval_testseval_resultszipsubTestcompiler*   PyCF_ONLY_ASTr7   r   r6   )r/   rV   outputrX   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>rR   )rY   r[   r]   r*   parsera   )r/   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*   ri   bodyr:   slicerP   upperlowerstep)r/   Zslcr   r   r   
test_sliceB  s   zAST_Tests.test_slicec                 C   s    t djd }| |j d S )Nzfrom . import yr   )r*   ri   rl   rP   module)r/   imr   r   r   test_from_importH  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>rR   )r*   ri   assertIsInstancerl   
ImportFromstriprr   ra   )r/   modr   r   r   !test_non_interned_future_from_astL  s   
z+AST_Tests.test_non_interned_future_from_astc                 C   s  t djd }| t|jd |jd }| |jd | |j | |j	d | |j
d | |jd | |jd t djd }|jd }| |jd | |j | |j	d | |j
d | |jd | |jd t d	jd }|jd }| |jd | |jd
 | |j	d | |j
d | |jd | |jd t djd }|jd }| |jd | |jd | |j	d | |j
d | |jd | |jd d S )Nzfrom bar import yr      y      zfrom bar import **zfrom bar import y as zz   zimport bar as foobarfoo   )r*   ri   rl   r7   lennamesr0   rP   asnamer
   r   r   r   )r/   rs   aliasr   r   r   
test_aliasR  sB   



zAST_Tests.test_aliasc                 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*   Forr5   Namer4   r+   comprehensionZGtr/   r   r   r   test_base_classesx  s   zAST_Tests.test_base_classesc                 C   sR   t j D ]!\}}| ||r&|dkrq| }t|t jr&| t|jt	 qd S )NZIndex)
r*   r?   itemsr2   r   r+   r7   r,   r   r   )r/   r0   itemrE   r   r   r   test_field_attr_existence  s   z#AST_Tests.test_field_attr_existencec                 C   s   t  }| |jd | t |j W d    n1 sw   Y  | |j t jt	dd }| |jd | |jd d S )N)posonlyargsargsrB   
kwonlyargskw_defaultskwargdefaultsr{      r>      )
r*   	argumentsr7   r   r@   rA   r   rP   rB   rangerD   r   r   r   test_arguments  s   zAST_Tests.test_argumentsc                 C   s    t  }d|_| |jd d S )Ni  )r*   Numr   r7   rD   r   r   r   test_field_attr_writable  s   z"AST_Tests.test_field_attr_writablec                 C   s  t  }| |jd | t |j W d    n1 sw   Y  | t |j W d    n1 s6w   Y  t d}| |jd | |jd | t |j W d    n1 saw   Y  | t |j	 W d    n1 syw   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 sw   Y  | t
d t jddd W d    n	1 sw   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)r:   rX   r<   r>   r
   r   r{   r   )r   z(Num got multiple values for argument 'n'nz1Constant got multiple values for argument 'value'r:         @              @42   42TF.)r*   r   r7   r   r@   rA   r:   r   r
   r=   rC   Constantr   assertRaisesRegexStrsBytesassertIsNameConstantrD   r   r   r   test_classattrs  sf   
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)	r7   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                   @   rG   )z$AST_Tests.test_isinstance.<locals>.SNrH   r   r   r   r   S  s    r   )r   r   r*   r   r   r   r   r   r   assertFalser   )r/   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__r   )r/   r   kwargsr   r   r   r     s   
z-AST_Tests.test_subclasses.<locals>.N.__init__)r   r-   rI   r   __classcell__r   r   r   r   N  s    r   c                   @   rG   )z%AST_Tests.test_subclasses.<locals>.N2NrH   r   r   r   r   N2  rK   r   r<   r   r   )	r*   r   r7   r   r   r,   r   r   r   )r/   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   Moduler7   rl   )r/   rl   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*   BinOpr7   r   r   r   Addr   r   r   r
   r@   rC   )r/   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Subr7   r   rD   r   r   r   test_no_fieldsY  s   zAST_Tests.test_no_fieldsc           	   	   C   s   dd l }|g}zdd l}|| W n	 ty   Y nw g d}|D ]$}|D ]}dd tD D ]}||||}| t|t| q/q&q"d S )Nr   )r   r{   r>   c                 s   s    | ]
}t |d ddV  qdS )rW   rR   i   N)ra   )r   rd   r   r   r   	<genexpr>i  s    z*AST_Tests.test_pickling.<locals>.<genexpr>)	picklecPickler   ImportErrorrY   loadsdumpsr7   r   )	r/   r   Zmodsr   Z	protocolsry   protocolr*   ast2r   r   r   test_pickling^  s"   zAST_Tests.test_picklingc                 C   s   t ddd}ttjtjdi |fi |gg }| t}t|dd W d    n1 s0w   Y  | dt	|j
 d S )Nr>   r   r
   r   ru   rR   zbut got <ast.exprr   )dictr*   r   Exprr4   r@   rC   ra   assertInr   	exception)r/   posmcmr   r   r   test_invalid_summ  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 s+w   Y  | 	dt
|j d S )Nr<   ru   rR   zidentifier must be of type str)r*   r   r   r   Loadfix_missing_locationsr@   rC   ra   r   r   r   )r/   r   r   r   r   r   test_invalid_identifiert  s    
z!AST_Tests.test_invalid_identifierc              	   C   sx   t ddt ftddt ffD ],}tjt|d}t| | td t|dd W d    n1 s4w   Y  qd S )Nr{   r>   rl   zinvalid type in Constant: typeru   rT   )	r   	frozensetr*   
Expressionr   r   r   rC   ra   )r/   Zinvalid_constantr   r   r   r   test_invalid_constant{  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 s%w   Y  | dt|j	 d S )Nzdef f():
 yield from g()r   ru   rR   zfield 'value' is required)
r*   ri   rl   r:   r@   
ValueErrorra   r   r   r   )r/   Zempty_yield_fromr   r   r   r   test_empty_yield_from  s   
zAST_Tests.test_empty_yield_fromc                 C   sT   dd l }dd }t|d| | ttjd W d    d S 1 s#w   Y  d S )Nr   c                  W   s   d S r   r   r   r   r   r   bad_normalize  s   z0AST_Tests.test_issue31592.<locals>.bad_normalize	normalizeu   ϕ)unicodedatar   	swap_attrr@   rC   r*   ri   )r/   r   r   r   r   r   test_issue31592  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   r   z
4+5-\
 6-7r{   r   r>   )
r*   ri   rl   r:   r   r7   r   r   r
   r   )r/   rj   Zparent_binopZchild_binopZgrandchild_binopr   r   r    test_issue18374_binop_col_offset  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*   ri   rl   r3   r:   r7   r   )r/   rj   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   r1   r   r   r   r	     s    z5AST_Tests.test_ast_asdl_signature.<locals>.<listcomp>zexpr = r   
)r7   r*   withitemr   r   r   Zcmpopr4   __subclasses__ZassertCountEqualsplit)r/   Zexpressionsr   r   r   test_ast_asdl_signature  s   z!AST_Tests.test_ast_asdl_signaturec                 C   s  t jddd t jddd | t t jddd W d    n1 s%w   Y  | t t jddd W d    n1 sAw   Y  t jddd t jddd | t t jddd W d    n1 skw   Y  | t t jddd W d    d S 1 sw   Y  d S )Nzdef foo(x, /): ...r   r   Zfeature_versionzdef bar(x=1, /): ...r   r   zlambda x, /: ...zlambda x=1, /: ...r*   ri   r@   SyntaxErrorr   r   r   r   $test_positional_only_feature_version  s    "z.AST_Tests.test_positional_only_feature_versionc                 C   sf   t jddd t jddd | t t jddd W d    n1 s%w   Y  t jddd d S )Nz#with (CtxManager() as example): ...)r   
   r   )r   	   r   z!with CtxManager() as example: ...r   r   r   r   r   'test_parenthesized_with_feature_version  s   z1AST_Tests.test_parenthesized_with_feature_versionc                 C   L   t jddd | t t jddd W d    d S 1 sw   Y  d S )Nzf"{x=}"r   r   r   r   r   r   r   r   #test_debug_f_string_feature_version     "z-AST_Tests.test_debug_f_string_feature_versionc                 C   r   )Nz(x := 0)r   r   r   r   r   r   r   r   *test_assignment_expression_feature_version  r  z4AST_Tests.test_assignment_expression_feature_versionc              	   C   sn   dD ]2}t t |t  }t | | td| d t|dd W d    n1 s/w   Y  qd S )N)TrueFalser   z"identifier field can't represent 'z
' constantru   rT   )r*   r   r   r   r   r   r   ra   )r/   Zconstantr4   r   r   r   test_constant_as_name  s   
zAST_Tests.test_constant_as_nameN)(r   r-   rI   r2   r6   rF   rQ   rg   rk   rq   rt   rz   r   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   r   r   r)      sJ    &</,	
		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S ):ASTHelpers_TestNc                 C   s6   t d}tdddt j}| t |t | d S )Nz
foo(1 + 1)z	<unknown>rR   )r*   ri   ra   rb   r7   dump)r/   rL   br   r   r   
test_parse  s   
zASTHelpers_Test.test_parsec                 C   sf   zdd  W d S  t y2   | t}td W d    n1 s#w   Y  | |jj Y d S w )Nr{   r   z'\U')	Exceptionr@   r   r*   literal_evalZassertIsNotNoner   __context__r/   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*   ri   r7   r  r/   r1   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*   Raiser7   r  r   r   r  r   r   r   test_dump_incompleteN  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 + 1rT   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*   ri   copy_locationr   rl   r   r7   r  CallrP   r   r   r
   r   )r/   srcnewr   r   r   test_copy_locationk  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*   ri   rl   r   r   r&  r   r   r   r7   r   maxDiffr  r/   r'  r   r   r   test_fix_missing_locations{  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"  rT   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*   ri   r7   increment_linenor  rl   r&  r   r   r
   rP   r   r+  r   r   r   test_increment_lineno  s   z%ASTHelpers_Test.test_increment_linenoc                 C   s`   t jtddd}t j|dd | |jd jd | |jd jd	 | |jd jd
 d S )Nzb        a = 1
        b = 2 # type: ignore
        c = 3
        d = 4 # type: ignore@tag
        T)Ztype_commentsr   r   r   r   r{   r   z@tag)r*   ri   r   r0  r7   type_ignoresr
   tagr+  r   r   r   test_increment_lineno_on_module  s   
z/ASTHelpers_Test.test_increment_lineno_on_modulec                 C   sH   t jddd}tt |j}| |djd | |g g d d S )Nfoo()rT   r#  r.  r   )r/  r   )r*   ri   r   Ziter_fieldsrl   r7   popr  )r/   r1   dr   r   r   test_iter_fields  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')rT   r#  r   r      r<   z1keyword(arg='eggs', value=Constant(value='leek')))r*   ri   r7   r   r   Ziter_child_nodesrl   nextr  r:   r  )r/   r1   iteratorr   r   r   test_iter_child_nodes  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*   ri   r7   get_docstringrl   r  r   r   r   test_get_docstring  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")rP   r*   r=  ri   rl   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         )r*   ri   r7   rl   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   :   t d}|jd jd }| |jd | |jd d S )Nz if a:
    pass
elif b:
    pass
r   r   r*   ri   rl   orelser7   r
   r   r/   r1   Z	elif_stmtr   r   r   test_elif_stmt_start_position     
z-ASTHelpers_Test.test_elif_stmt_start_positionc                 C   rD  )Nz/if a:
    pass
elif b:
    pass
else:
    pass
r   r   rE  rG  r   r   r   'test_elif_stmt_start_position_with_else  rI  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*   ri   rl   r:   r   r7   r   r   )r/   r1   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()r5  6   z+6z-6iz3.25g      
@z+3.25z-3.25g      
z-0.0z++6z+Truez2+3)r7   r*   r  setr@   r   reprr   r   r   r   test_literal_eval  s"   z!ASTHelpers_Test.test_literal_evalc              	   C   s   t d: td | t}td W d    n1 s w   Y  | dt|j | dt|j W d    d S 1 sBw   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   )r/   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))r7   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  )r/   Z	malformedr   r   r   &test_literal_eval_malformed_dict_nodesA  s   &&z6ASTHelpers_Test.test_literal_eval_malformed_dict_nodesc                 C   sJ   |  tdd |  tdd |  tdd | ttjd d S )Nz    -1r   z		-1z 	 -1z
 -1)r7   r*   r  r@   IndentationErrorr   r   r   r   test_literal_eval_trailing_wsG  s   z-ASTHelpers_Test.test_literal_eval_trailing_wsc              	   C   s   d}|  t| td W d    n1 sw   Y  tt tt td}| t|dd  d}|  t| t| W d    d S 1 sPw   Y  d S )Nz#malformed node or string on line 3:z{'a': 1,
'b':2,
'c':++3,
'd':4}rN  r
   zmalformed node or string:)	r   r   r*   r  UnaryOpZUAddr   rP   r   )r/   msgr1   r   r   r   "test_literal_eval_malformed_linenoM  s   "z2ASTHelpers_Test.test_literal_eval_malformed_linenoc                 C   s<   |  td td W d    d S 1 sw   Y  d S )Nzunexpected indentz4
                \
                (\
            \ )r   r   r*   r  r   r   r   r   test_literal_eval_syntax_errorsY  s   "z/ASTHelpers_Test.test_literal_eval_syntax_errorsc                 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 s,w   Y  | dt|j	 d S )Ntimesleepr0   rr   r   levelr
   r   r-  rR   zinvalid integer value: None)
r*   rw   r   r   r@   r   ra   r   r   r   )r/   rl   ry   r   r   r   r   test_bad_integer`  s   z ASTHelpers_Test.test_bad_integerc                 C   sZ   t jdt jddddgd dddg}t |g }t|dd}i }t|| | d| d S )Nr^  r_  r   )r0   r
   r   ra  r-  rR   )r*   rw   r   r   ra   rR   r   )r/   rl   ry   codensr   r   r   test_level_as_nonek  s   
z"ASTHelpers_Test.test_level_as_nonec              	   C   s   t jt  ddd}||_| t. t  tt 	|dd W d    n1 s+w   Y  W d    d S W d    d S 1 sCw   Y  d S Nr   )r   r
   r   ru   rT   
r*   rZ  Notoperandr@   RecursionErrorr   Zinfinite_recursionra   r   r  r   r   r   test_recursion_directw  s   
"z%ASTHelpers_Test.test_recursion_directc              	   C   s   t jt  ddd}t jt  ddd}||_||_| t. t  tt 	|dd W d    n1 s8w   Y  W d    d S W d    d S 1 sPw   Y  d S rg  rh  )r/   r   r   r   r   r   test_recursion_indirect~  s   
"z'ASTHelpers_Test.test_recursion_indirect) r   r-   rI   r*  r
  r  r  r  r!  r)  r,  r1  r4  r8  r<  r>  r@  rC  rH  rJ  rK  rQ  rR  rS  rW  rY  r\  r]  rc  rf  rl  rm  r   r   r   r   r    s<    =r  c                   @   s  e Zd ZdtedddZduedddZdud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_ Z1e23d`Z4e25e4Z6e23daZ7e25e7Z8e23dbZ9e2:dbZ;e2<dce2= Z>e25e2?e2?e2<dae2@ dde2= dee2= e25e2?e2?e2<dae2= dde2@ dee2= e25e23dfe25e23dbe25e23dge2:dhe2Ae2:dhge2Ae2Ae2:dhgge2Be4e9ge8ge2jBe9e4ge8e6gdidje2jBe9e2Ce2<dke2= e2= ge8e6gdldje2jDe2?e2?e7dde2= dee2= g g g dme2jDe>g dige6gdme2jDe>g g e6gdme2jDe>e2:dhgg g dme2jDe>e2E gg g dme2jDe>g g e2E gdme2Ae2Edige2jFdndoe2Gg e2Ge6ge2Ge6e8e2:dpge2jFdqdoe2jEdadoe2Ae2Edqge2jBg g dqdjgZHdrds ZIdS )vASTValidatorTestsNrR   r  c                C   sz   d |_ |_t| |d u rt|d| d S | |}t|d| W d    n1 s-w   Y  | |t|j d S )Nr   ru   )	r
   r   r*   r   ra   r@   r   r   r   )r/   ry   r[  r$  r  r   r   r   r   ry     s   
zASTValidatorTests.modc                C   s(   t t |gg }| j|||d d S )Nro  )r*   r   r   ry   )r/   r1   r[  r  ry   r   r   r   r4     s   zASTValidatorTests.exprc                 C   s   t |gg }| || d S r   )r*   r   ry   )r/   r5   r[  ry   r   r   r   r5     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 contextrS   rT   )r*   Interactiver   r   Storery   r   )r/   r   r   r   r   r     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 rg }|d u rg }t | ||||||}  | S r   )r*   r   )r   r   rB   r   r   r   r   facr   r   r     s   z5ASTValidatorTests._check_arguments.<locals>.argumentsrE   r   rp  )r   )r   r   )r   z"more positional defaults than argsr   )r   z3length of kwonlyargs is not the same as kw_defaults)r   r   rL   r	  r|   )r   r   )NNNNNNN)r*   argr   rr  r   r   )r/   rt  checkr   r   r   rs  r   _check_arguments  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 FunctionDefrp  c                 S   s   t d| t  gg d S NrE   )r*   FunctionDefPassr   r   r   r   rt       z+ASTValidatorTests.test_funcdef.<locals>.fac)r*   r   ry  r5   rz  r   rr  rw  )r/   rL   r   rt  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 rg }t d| |||S )NZmyclass)r*   rz  ClassDef)basesr/  rl   r3   r   r   r   cls  s   

z,ASTValidatorTests.test_classdef.<locals>.clsrE   )r~  rp  )r/  r   zempty body on ClassDefNone disallowed)r3   )NNNN)r5   r*   r   rr  keyword)r/   r  r   r   r   test_classdef  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 Deleter  rE   zmust have Del context)r5   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 Assignr  rE   must have Store contextr|   rp  )r5   r*   Assignr   r   r   rr  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   r|   r  rp  )r*   	AugAssignr   r   r   r5   rr  )r/   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   r|   zempty body on Forr  rp  )r*   r   rr  r   rz  r5   r   r   )r/   rE   r|   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   rp  )r5   r*   Whiler   r   rr  rz  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   rp  )r5   r*   Ifr   r   rr  rz  r   )r/   rd   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   rp  r  )	r*   rz  r5   Withr   r   r   rr  r   )r/   r  rd   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   rp  r   )r*   r   r   r5   r   rr  )r/   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   rp  z-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlerszempty body on ExceptHandlerr|   )r*   rz  Tryr5   r   r   rr  ExceptHandler)r/   r  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   rp  r|   )r5   r*   Assertr   rr  r   )r/   Zassrtr   r   r   test_assertC  s   zASTValidatorTests.test_assertc                 C      |  tg d d S )Nzempty names on Import)r5   r*   Importr   r   r   r   test_importJ     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*   rw   r   r5   )r/   impr   r   r   test_importfromM  s   z!ASTValidatorTests.test_importfromc                 C   r  )Nzempty names on Global)r5   r*   Globalr   r   r   r   test_globalR  r  zASTValidatorTests.test_globalc                 C   r  )Nzempty names on Nonlocal)r5   r*   ZNonlocalr   r   r   r   test_nonlocalU  r  zASTValidatorTests.test_nonlocalc                 C   s&   t t dt  }| |d d S NrE   rp  )r*   r   r   rr  r5   r  r   r   r   	test_exprX  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   r  rE   rp  )r*   BoolOpAndr4   r   r   rr  )r/   r	  r   r   r   test_boolop\  s   &zASTValidatorTests.test_boolopc                 C   s,   t t  t dt  }| |d d S r  )r*   rZ  ri  r   rr  r4   )r/   ur   r   r   test_unaryopf  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   rp  c                 S   s   t | t dt  S rx  )r*   Lambdar   r   r   r   r   r   rt  n  r{  z*ASTValidatorTests.test_lambda.<locals>.fac)r*   r   r4   r  r   rr  rw  )r/   rL   rt  r   r   r   test_lambdaj  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   r|   rp  )r*   r   r   rr  r4   ZIfExp)r/   lr   r   r   r   r   
test_ifexpr  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 valuesr  )r*   rV  r   r   r4   )r/   r7  r   r   r   	test_dictx  s   zASTValidatorTests.test_dictc                 C   s<   |  td gd ttdt g}|  |d d S Nr  rE   rp  )r4   r*   Setr   rr  r/   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   r  rp  r|   r  )r4   r*   r   r   r   rr  )r/   rt  grE   r|   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   rp  c                    s    t dt  | S rx  )r*   r   rr  )Zgensrs  r   r   wrap  r  z,ASTValidatorTests._simple_comp.<locals>.wrap)r*   r   r   rr  r   r4   r  )r/   rt  r  r  r   rs  r   _simple_comp  s   zASTValidatorTests._simple_compc                 C      |  tj d S r   )r  r*   ListCompr   r   r   r   test_listcomp     zASTValidatorTests.test_listcompc                 C   r  r   )r  r*   SetCompr   r   r   r   test_setcomp  r  zASTValidatorTests.test_setcompc                 C   r  r   )r  r*   GeneratorExpr   r   r   r   test_generatorexp  r  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 )Nr|   r  r   rE   rp  c                 S   s.   t dt  }t dt  }t ||| S )NrE   r|   )r*   r   r   DictComp)compskr'   r   r   r   factory  s   z0ASTValidatorTests.test_dictcomp.<locals>.factory)r*   r   r   rr  r   r  r4   r  )r/   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)r4   r*   ZYieldr   rr  Z	YieldFromr   r   r   r   
test_yield  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Inr4   r   )r/   r   compr   r   r   test_compare  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   r|   wr   rp  r  )r*   r   r   r  r&  rr  r4   )r/   r.  r   r/  callZbad_keywordsr   r   r   	test_call  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| q| | | fD ]}| jt|dtd	 q-d S )
Nc                   @   rG   )z*ASTValidatorTests.test_num.<locals>.subintNrH   r   r   r   r   subint  rK   r  c                   @   rG   )z,ASTValidatorTests.test_num.<locals>.subfloatNrH   r   r   r   r   subfloat  rK   r  c                   @   rG   )z.ASTValidatorTests.test_num.<locals>.subcomplexNrH   r   r   r   r   
subcomplex  rK   r  )0Zhellozinvalid typero  )r   floatr   r4   r*   r   rC   )r/   r  r  r  objr   r   r   test_num  s   zASTValidatorTests.test_numc                 C   s.   t t dt  dt  }| |d d S r  )r*   	Attributer   rr  r   r4   )r/   attrr   r   r   test_attribute  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 qKt g t  }| t ||t   t |gt  }| t ||t  d d S )NrE   r   rp  r|   )	r*   	Subscriptr   rr  r   r   r4   SliceTuple)r/   subrE   r   r   slr   r   r   test_subscript  s&    
z ASTValidatorTests.test_subscriptc              	   C   sN   t t t dt  t  gt  }t |gt d}| |d d S )NrE   r   r  )	r*   ListStarredr   r   rr  r  r   r5   )r/   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  )r4   r*   r   r   rr  )r/   rt  r   r   r   	_sequence  s   zASTValidatorTests._sequencec                 C   r  r   )r  r*   r  r   r   r   r   	test_list  r  zASTValidatorTests.test_listc                 C   r  r   )r  r*   r  r   r   r   r   
test_tuple  r  zASTValidatorTests.test_tuplec                 C   s   |  td d S )Nr   )r4   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 ]E}| |6 t j||}t	|ddd}|
 }W d    n1 s?w   Y  t||}t||d W d    n1 sZw   Y  qd S )	Nc                 S   s   g | ]	}| d r|qS )z.py)endswith)r   fnr   r   r   r	     s    z;ASTValidatorTests.test_stdlib_validates.<locals>.<listcomp>ztest/test_grammar.pyztest/test_unpack_ex.pyr  zutf-8)encodingrR   )ospathdirnamer*   __file__listdirextendr`   joinopenreadri   ra   )r/   Zstdlibtestsrr   r  fpsourcery   r   r   r   test_stdlib_validates  s   
z'ASTValidatorTests.test_stdlib_validatesr{   rE   TZcarterr|   r   .rL  stringr  )restZlolZlegit)patterns	kwd_attrskwd_patternsr  r`  Zxxx_c              
   C   s   t dt  }| jD ]S}| t j|dd? t j|t j|t  gdgd}t 	|}t 
|gg }| t t|dd W d    n1 sJw   Y  W d    n1 sYw   Y  qd S )NrE   r   r  )patternrl   )subjectcasesru   rR   )r*   r   r   _MATCH_PATTERNSr`   r  MatchZ
match_caserz  r   r   r@   r   ra   )r/   Zname_xr  r1   rr   r   r   r   test_match_validation_pattern  s(   

	z/ASTValidatorTests.test_match_validation_pattern)NrR   r   )Jr   r-   rI   r   ry   r4   r5   r   rw  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  r  r  r  r  r  r*   r   Z
constant_1Z
MatchValueZ	pattern_1Z
constant_xZ	pattern_xZconstant_trueZMatchSingletonZpattern_truer   r   Zname_carterr  rr  ZMatchSequenceZMatchMappingr  Z
MatchClassZ	MatchStarZMatchAsZMatchOrr  r  r   r   r   r   rn    sP   

"	


	





			


trn  c                   @   sd   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	e
jdd Zdd Zdd ZdS )ConstantTestsc                 C   s\   t d}|jd j}t j|d}t || ||jd _t|dd}i }t|| |d S )Nzx = 123r   r   rh   rR   rE   )r*   ri   rl   r:   r   r%  ra   rR   )r/   r:   rj   r1   new_noderd  re  r   r   r   compile_constant  s   

zConstantTests.compile_constantc                 C   sN   |  t}| g d W d    n1 sw   Y  | t|jd d S )NrL  z%got an invalid type in Constant: list)r@   rC   r  r7   r   r   )r/   r   r   r   r   test_validation  s   zConstantTests.test_validationc              	   C   s^   d ddt dt fD ]#}| j|d | |}| || W d    n1 s'w   Y  q	d S )NFT    )const)r   r   r`   r  r   )r/   r  r:   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 ]#}| j|d | |}| || W d    n1 sGw   Y  q)d S )N)r{   r{   r   r>   {   g     ^@y             ^@unicode   bytesr   r   r   )r   r   r   r`   r  r7   )r/   Znested_tupleZnested_frozensetrb  rU  r:   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 s7w   Y  | 	t
|jd d S )Nx = 1r   r{   r   r  rR   z6expression which can't be assigned to in Store context)r*   ri   rl   targetsr   r%  r@   r   ra   r7   r   r   )r/   rj   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*   ri   r7   r=  )r/   rj   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 )Nrh   rR   Z
LOAD_CONST)ra   disZget_instructionsopnamer   Zargval)r/   rj   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 ||_q-| | || d S )N)	NTF|   g       @y              @r  r	  rL  r   c                 S   s   g | ]}d  |qS )zx={!r})format)r   r  r   r   r   r	         z1ConstantTests.test_load_const.<locals>.<listcomp>z
x = ...r   )r  r  r   r*   ri   r7   r  r_   rl   r   r%  r:   )r/   r  rd  rj   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   r   y              4@y      $@      4@)
r*   ri   rl   r:   r   r%  r   r   r7   r  )r/   rj   binopZnew_leftZ	new_rightr   r   r   rQ    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"rT   r#  rE   zu"x"r  zr"x"zb"x"   x)r*   ri   rl   r7   r:   rX   )r/   r  r   r   r   test_string_kind  s   zConstantTests.test_string_kindN)r   r-   rI   r  r  r  r
  r  r>  r  r   r  r  rQ  r  r   r   r   r   r     s    

r   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d3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=S )>EndPositionTestsc                 C   s    |  |j| |  |j| d S r   )r7   r   r   )r/   r9   r   r   r   r   r   _check_end_pos-  s   zEndPositionTests._check_end_posc                 C   s   |  t||| d S r   )r7   r*   get_source_segment)r/   r  r9   Zcontentr   r   r   _check_content1  r{  zEndPositionTests._check_contentc                 C   s   t |jd jS )Nr   )r*   ri   rl   r:   r  r   r   r   _parse_value4  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   r|   )r   r  rl   r   rB   )r/   r   Zlamr   r   r   r  9  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: AnyZAny)
r   rx   r*   ri   rl   r  r  r   
annotationr   r/   r   Zfdefr   r   r   test_func_def@  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/  r:   r/   r   r  r   r   r   r  P  s
   
zEndPositionTests.test_callc                 C   s0   d}|  |}| ||jd | |dd d S )Nzx[0]()zx[0]r{   rN  )r   r  r.  r  r'  r   r   r   test_call_noargsW  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   rx   r*   ri   rl   r  r  r~  r/   r   cdefr   r   r   test_class_def]  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*   ri   rl   r  r/  r:   r+  r   r   r   test_class_kwg  s   zEndPositionTests.test_class_kwc                 C   >   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   rx   r*   ri   rl   r  r:   r/   r   r  r   r   r   test_multi_line_strl  s   z$EndPositionTests.test_multi_line_strc                 C   r/  )NzB
            x = "first part" \
            "second part"
        r   r>   rB  r1  r2  r   r   r   test_continued_strv  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~      r  zx = Nonezother()x, yzraise RuntimeErrorrC   )r   rx   r*   ri   rl   r  r  r-  rF  r  handlersr,   )r/   r   ry   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   rU  r:   r  r/   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   rx   r   rU  r:   r  r  r   r   r:  r   r   r   test_fstring_multi_line  s   
	z(EndPositionTests.test_fstring_multi_linec                 C   sB   t d }t|jd }| |dd | |jd dd d S )NzT
            from x.y.z import (
                a, b, c as c
            )
        r   r   r{   r>   r}   )r   rx   r*   ri   rl   r  r   )r/   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   rx   mapr   r  r:   rm   ro   rn   eltsr  )r/   s1s2smZi1Zi2rs   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>   rN  4z1 * 2 + (3 )3)r   rx   r   r  r  r   r   )r/   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   rx   r*   ri   rl   r-  r  r  rU  )r/   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   rx   r@  r   r  r  )	r/   rB  rC  Zs3rD  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*   ri   rl   r:   r7   r,   r   r  )r/   r   r'   rC  r   r   r   test_redundant_parenthesis  s   z+EndPositionTests.test_redundant_parenthesisc              	   C   s   d}|D ]P\}}|  |? t|jd j}| t|j| | ||| d| }t|jd jj}| t|j| | ||| W d    n1 sOw   Y  qd S )N))z( ( ( a ) ) ) ( )r&  )z( ( ( a ) ) ) ( b )r&  )z( ( ( a ) ) ) [ b ]r  )z( ( ( a ) ) ) . br  r   rN  )	r`   r*   ri   rl   r:   r7   r,   r   r  )r/   r  r   r   r'   rC  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  rA  rT  rU  )r/   rB  rC  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.xr7  )
r   rx   r   r  r  
generatorsitereltifsr  )r/   r   cmpr   r   r   test_comprehensions.  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   rx   r*   ri   rl   r  r:   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   rx   r   r7   r*   r  r   )r/   s_origZs_tupler  r   r   r   test_source_segment_multiD  s   
z*EndPositionTests.test_source_segment_multic                 C   B   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   rx   r*   ri   rl   r7   r  )r/   r]  s_methodr,  r   r   r   test_source_segment_paddedR  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*   ri   rl   r  )r/   r   r'   r  rE   r|   r   r   r   r   test_source_segment_endings^  s   z,EndPositionTests.test_source_segment_endingsc                 C   r_  )Nzb
            class C:
              	  def fun(self) -> None:
              	      pass
        z+  	  def fun(self) -> None:
  	      passr   Tr`  ra  )r/   r   rb  r,  r   r   r   test_source_segment_tabsg  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*   ri   rl   r
   r   r   r   rP   r  )r/   r   r'   r  rE   r|   r   r   r    test_source_segment_missing_infos  s   z1EndPositionTests.test_source_segment_missing_infoN)!r   r-   rI   r  r  r   r  r$  r  r(  r-  r.  r3  r4  r9  r;  r<  r=  rE  rH  r  rL  rM  rO  rP  rS  r[  r\  r^  rc  rd  re  rf  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 s4w   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                         |jd|jf d S )Nr   )r   r
   r   r  logr   r   	visit_Num  r{  zCNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_Numc                    rh  )Nr   r   r
   r   r  ri  r   r   	visit_Str  r{  zCNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_Strc                    rh  )Nr   rl  r  ri  r   r   visit_Bytes  r{  zENodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_Bytesc                    rh  )Nr   )r   r
   r:   r  ri  r   r   visit_NameConstant  r{  zLNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_NameConstantc                    s     |jddf d S )Nr   .)r   r
   r  ri  r   r   visit_Ellipsis  r  zHNodeVisitorTests.test_old_constant_nodes.<locals>.Visitor.visit_EllipsisN)r   r-   rI   rk  rm  rn  ro  rp  r   ri  r   r   Visitor  s    rq  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	  )rN  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_Constantru  ru  z+visit_Str is deprecated; add visit_Constantz-visit_Bytes is deprecated; add visit_Constant4visit_NameConstant is deprecated; add visit_Constantrv  z0visit_Ellipsis is deprecated; add visit_Constant)
r*   ZNodeVisitorri   r   warningscatch_warningsfilterwarningsDeprecationWarningZvisitr7   )r/   rq  ry   ZvisitorZwlogr   ri  r   test_old_constant_nodes  s   

z(NodeVisitorTests.test_old_constant_nodesN)r   r-   rI   r{  r   r   r   r   rg    s    rg  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 + 1rh   rT   )flags)ra   r*   rb   rv   typesCodeType)r/   rd  filenamer$  rf   r   r   r   check_ast_module  s   z!ModuleStateTests.check_ast_modulec                 C   sp   t tjdd  tjd= dd l}tjd= dd l}|   W d    n1 s'w   Y  ~~t   |   d S )N_astr   )r   	swap_itemsysmodulesr  r  rO   )r/   Zast1r   r   r   r   test_reload_module  s   

z#ModuleStateTests.test_reload_modulec              	      s   t    fdd}ttjdd A tjd= ttd| |   | dtj dd l	}| 
|  W d    n1 s=w   Y  W d    d S W d    d S 1 sUw   Y  d S )Nc                    s    t j| <  S r   )r  r  )r0   r   r&  Zlazy_modr   r   	my_import  s   
z4ModuleStateTests.test_sys_modules.<locals>.my_importr  
__import__r   )objectr   r  r  r  r   builtinsr  ZassertNotInr  r   )r/   r  r  r   r  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_subinterpr7   )r/   rd  resr   r   r   test_subinterpreter  s   
z$ModuleStateTests.test_subinterpreterN)r   r-   rI   r  r  r  r  r   r   r   r   r|    s
    r|  c                  C   s   t dkrd S tjdd  dgkrEtdftdftdffD ]#\} }t|d  | D ]}t|d|}td	t	|f  q'td
 qtd t
t  d S )N__main__r{   z-grR   rS   rT   z_results = [rW   z%r,]zmain())r   r  argvrY   r[   r]   printr*   ri   r   
SystemExitunittestmain)Z
statementsrX   Z	statementrj   r   r   r   r  	  s   
r  r   )r   r{   r   r{   r   r   r  NN)r   r{   r   r{      )r   r  zmodule docstringNry  )r{   r   r{   rB  r   r   )rz  )r{   r   r{   rB  )r{   r   r{      )r   r{   r   r{   r  )r   r  zfunction docstringN)r{   r   r{   r)  ru  r{   rN  r{   r   rL   NN)rz  )r{   r   r{   r)  )r{   r   r{   r}   )r   r{   r   r{   r   r   N)rz  )r{   r5  r{   r}   r  )ru  r{   r   r{   rA  r   NN)rz  )r{   r)  r{   r  )r{   r   r{      )ru  r{   r   r{   r)  r   NN)rz  )r{   r~   r{   r  )r{   r   r{   G   )r  )ru  r{   r   r{   r   r	  NN)ru  r{   r)  r{   r!  r  NN)ru  r{   r   r{   r9  r7  NN)ru  )r{      r{   r  r   NN)ru  r{   #   r{   '   r   NN)ru  )r{   )   r{   r<   r   NN)r   )r{   +   r{   -   r<   N)ru  )r{   1   r{   7   r   NN)r   r{   rA  r{   r5  r{   N)r   r{   r}   r{      NNr  )r{      r{      r   rV  )r{      r{       )r   r{   :   r{   r  )r   r  zdoc for f()Nr}  )r{   r   r{   r5  C)rz  )r{   r   r{   r5  )r{   r   r{   r  )r   r{   r   r{   r  )r   r  zdocstring for class CN)r   r  r  r  )ZReturnr{   r   r{   r}   )r   r{   r!  r{   r}   r{   Nr  r{   r   r{   r   )r   r{   r   r{   r   r'   )ZDelr  r   r{   r   r{   r{   r'   rr  )r   r  r{   Nr{   r   r{   r   r  r{   r   r{   r   )r   r  rL   r  )r   r{   r>   r{   r   r	  r  r  )r   r  r  r  )r{   r   r{   r   r   r{   r{   r{   r>   rL   r  )r   r{   r   r{   r   r	  r  )r   r  r  r  )r  r{   r   r{   rN  r  r   )r   r{   r   r{   rN  r{   Nr   )r{   r   r{   r!  )r   r  r'   r  )r   r  r'   r  )rz  )r{   rA  r{   r!  r  )r   r  r'   r  r  )r   r  r'   r  )rz  )r{   r   r{   r   )r{   r   r   rN  )r   r  rL   r  )rz  )r>   r>   r>   rN  )r   r   r   rN  )r   )r   r   r   rN  r	  r  )rz  )r   r>   r   rN  )r{   r   rN  rN  )r   r   rN  rN  )rz  )rN  r>   rN  rN  r  )r{   r   r{   r~   )r   )r   r  rE   r  )r   r{   r   r{   rA  r|   r  )rz  )r{   rB  r{   r~   )r{   r   r{      )r   )r   r{   rB  r{   r)  r   r  )r   r{   r  r{   r6  qr  )rz  )r{   r  r{   r  r   r&  )r{   rN  r{   r  )r   )r{   rN  r{   r!  r  r  )r   )r{   r}   r{   r  r  Nr  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{   r   r  Nrw   r  )r   r{   r}   r{   r~   r'   Nr  r  r'   )r   r  r   r  r{   N)rz  r  )ZBreakr{   rA  r{   r}   )r{   r   r{   r6  )ZContinue)r{   rA  r{   r6  )r{   r   r{   r   )r   r  rL   r  )r   r  r	  r  )r   r  r  r  )r{   r   r{   r  )r{   r   r{   r   )r   r  rL   r  )r   r  r	  r  )r   r  r  r  )rz  r  r   )r{   r   rA  r   r  )r>   r   rN  r   )r   )r   r   r   rN  Aar  )r   )r   r   r   r   Bbr  r   )r   r   r   rN  )r   )r   r   r   rN  r  r  )r   )r   r   r   rN  r  r  )r   )r   r   r   r5  ZCcr  )r{   r   r{   "   r  r   r  rL   r  )r   r  r	  r  )r   r  r  r  )r   r  rE   r  )r   r  r   r  )r   )r{      r{   r  r  r  )r   )r{   r  r{   !   r  r  )r{   rA  r{   r)  )r   r  r'   r  )r   r  r  r  )r   r  rE   r  r  )r   r  r  r  )r   r  r  r  )r   r{   r5  r{   rB  rE   r  )r   r{   r~   r{   r  r  r  r  )r   r  r   r  )r   r  rE   r  ZAsyncFunctionDef)r{   r   r   r  )r   r>   r{   r>   r~   )r   r  zasync functionN)r   r{   r   r  ZAwait)r   r   r   r  )r   r  Z	somethingr  )r{   r   r   r   ZAsyncFor)r>   r{   r   r   )r   )r>   rA  r>   r5  r   r  )r   )r>   r}   r>   r~   rd   r  )r   r>   r6  r>   r  )r   r  r{   N)r   r   r   r   r   )r   r  r>   N)r{   r   r>   r  Z	AsyncWith)r>   r{   r>   r  )r   )r   )r>   r5  r>   rB  rL   r  )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   rd   r  )r   )r>   r)  r>   r!  r	  r  )r   r  r  r  r{   )r   r   r   rB  )rz  )r   r   r   rB  )r   r{   r{   r{   rN  Zdeco1r  )r>   r{   r>   r   )r   )r>   r{   r>   rN  Zdeco2r  )r   r{   r   r   )r   )r   r{   r   rN  Zdeco3r  )r   r  r{   N)r   r   r   r6  )rz  )r   r!  r   r6  )r>   r   r>   rB  )rz  )r>   r   r>   rB  )r{   r{   r{   r6  )r   r{   r{   r{   r   Zdecor  )r{   r   r{   r6  )r   r  rL   r  )r   r  rL   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   r  r{   N)r{   r   r{   r  )ru  r  r  NN)ru  r  r7  NN)ru  r  r   NN)rz  )r{   r   r{   r  r  )ru  r  r7  NN)ru  r{   r  r{   r   r   NN)rz  )r{   r  r{   r  )r{   r   r{   r  )ru  )r{   r  r{   r  r   NN)rz  r  r   r  r{   N)ru  r  r	  NN)ru  )r{   r6  r{   r  r  NN)r  r   r  r>   N)r   r  r   N)ru  r  r  NN)r   )r{   r  r{   r  r   Nr  )rz  )r{   r  r{   r  )r{   r   r{   r  )rz  )r{   r  r{   r  )r{   r   r{   r<   )ru  )r{   r  r{   r  r   NN)rz  )r{   &   r{   r<   )r{   r   r{   r0  )ru  )r{   r  r{   r  r   NN)rz  )r{   $   r{   r0  rq  )r   r  )r   r  r  r  r   r  r>   N)r   r  r   r  )r  r   r  rL   r  )r   r  r	  r  )r   )r   r  r  r  r   r  r	  r  )r   )rZ  r  )ri  )r   r  r'   r  r  )r{   r   r{   rA  )r   r  NNr   r  r{   Nr   r  r>   Nr{   r   r{   r>   )r   r  NN)r{   r   r   rN  )r   )r>   rN  r>   r   r{   N)r   )r   r   r   rA  r>   N)r   r  r  r  )r   r  r7  r  r  )r   r  rL   r  r  )r   r  rL   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Ltr   r  r   N)r   r  r   r  )r  r  )r  )r{   r   r{   r5  )r   r  r7  r  r  )r  )r{   rN  r{   r   r  r  )r  )r{   rB  r{   r}   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   r  rL   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  r7  r  )r  r  )r  )r{   r   r{   rA  )r   r  rL   r  r	  r  )r  )r{   r5  r{   r!  )r   r  r{   N)r   r  r>   NNr  )r*   r  r  r  r  r~  r  rw  rM   textwrapr   r-  r   r   rY   r[   r]   ZTestCaser)   r  rn  r   r  rg  r  r|  r  rZ   r\   r^   r   r   r   r   <module>   s    
K   u          Z2Q

,,.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 !"#
%