
    7bhO                       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	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d d	lmZmZmZmZmZm Z   G d
 de	jB                        Z" G d de	jB                        Z# G d de	jB                        Z$ G d de	jB                        Z% G d de	jB                        Z& G d d      Z' G d de'e	jB                        Z( G d dee'e	jB                        Z)ejT                   G d de	jB                               Z+ G d de	jB                        Z,y)    N)partial)dedent)support)import_fresh_module)	os_helperscript_helper)ASTTestMixin)to_tuple)
eval_testseval_results
exec_testsexec_resultssingle_testssingle_resultsc                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&e'jP                  d%        Z)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2d/ Z3d0 Z4 e5jl                  e'jn                  d1      e'jP                  d2               Z8d3 Z9d4e:e;jx                     d5e=d6e=d7dfd8Z>d:d9Z?y);	AST_TestsNc                 v    t        |t              syd|j                  vry|dk7  xr |d   j                         S )NFastASTr   )
isinstancetype
__module__isupper)selfnamenodes      @/opt/python-3.12.12/usr/lib/python3.12/test/test_ast/test_ast.py_is_ast_nodezAST_Tests._is_ast_node   s8    $%'u}2a!22    c                    t        |t        j                        r|j                  y t        |t        j                  t        j
                  t        j                  f      rB|j                  |j                  f}| j                  ||       |j                  |j                  f}|j                  D ]t  }t        ||      }t        |t              rA|}|r#|dk(  r|d   j                  |d   j                  f}|D ]  }| j                  ||        `|c| j                  ||       v | j                  |j                  |j                         y )Ndecorator_listr   )r   r   r   _fieldsexprstmtexcepthandlerlineno
col_offsetassertGreaterEqualgetattrlist_assertTrueorderassertEqual__match_args__)r   ast_node
parent_posnode_posr   value	first_poschilds           r   r+   zAST_Tests._assertTrueorder$   s   (CGG,0@0@0Hh388S5F5F GH )<)<=H##Hj9"//8+>+>?J$$DHd+E%&&	T%55!&q%(2E2E FI"E))%; #"%%eZ8 % 	))8+B+BCr   c                    t        j                         }| j                  |j                  d       d|_        | j                  |j                  d       | j                  |j
                  d   d       | j                  t              5  |j                   d d d        | j                  t              5  t        j                  d       d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY w)N *   foobar   )
r   r   r,   r"   r7   __dict__assertRaisesAttributeErrorvararg	TypeErrorr   xs     r   test_AST_objectszAST_Tests.test_AST_objects7   s    GGIB'2&H-r2~.HH / y)GGAJ *) /. *)s   C2CCC&c                    t         j                  j                  fd}| j                  |       t         j                  `d}| j	                  t
        |      5  t        j                  d       d d d        | j	                  t
        |      5  t        j                          d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY w)Nc                  0     t         j                  _        y N)r   r   r"   )	old_values   r   cleanupz5AST_Tests.test_AST_fields_NULL_check.<locals>.cleanupI   s    'CGGOr   z0type object 'ast.AST' has no attribute '_fields'{   )arg1)r   r   r"   
addCleanupassertRaisesRegexr;   )r   rE   msgrD   s      @r   test_AST_fields_NULL_checkz$AST_Tests.test_AST_fields_NULL_checkE   s    GGOO		( GGO@##NC8GG 9##NC8GGI 98 9888s   B-B9-B69Cc                     G d d      }t        j                         } |       |_        ||j                  _        t	        j
                  |j                        }~t        j                          | j                   |              y )Nc                       e Zd Zy)0AST_Tests.test_AST_garbage_collection.<locals>.XN__name__r   __qualname__r5   r   r   XrN   W       r   rR   )	r   r   r?   aweakrefrefr   
gc_collectassertIsNone)r   rR   rT   rV   s       r   test_AST_garbage_collectionz%AST_Tests.test_AST_garbage_collectionV   s^    	 	 GGIckk!###% r   c           	         t         t        dft        t        dft        t
        dffD ]  \  }}}t        ||      D ]  \  }}| j                  d|      5  t        |d|t        j                        }| j                  t        |      |       | j                  |d       d d d        | j                  d||	      5  t        d|       d d d          y # 1 sw Y   8xY w# 1 sw Y   xY w)
Nexecsingleevalparsing)actioninput?)r   r   	compiling)r_   r`   kind)r   r   r   r   r   r   zipsubTestcompiler   PyCF_ONLY_ASTr,   r
   r+   )r   r`   outputrc   ioast_trees          r   test_snippetszAST_Tests.test_snippetsb   s    v.>84v.$
E64
 E6*1\\!\<&q#tS5F5FGH$$Xh%7;))(F; = \\AD\IHc40 JI +$
 =< JIs   A
C9C C C)c                 ~    t         t        z   t        z   }|D ]$  }t        j                  |      }t        |dd       & y )N<string>r[   )r   r   r   r   parserf   )r   snippets_to_validatesnippettrees       r   test_ast_validationzAST_Tests.test_ast_validationp   s6    )L8:E+G99W%DD*f- ,r   c                    g d}|D ]  \  }}| j                  d| d|       5  d}t        j                  |      }||j                  d   _        ||j                  d   _        | j                  t              5  t        |dd       d d d        d d d         g d}|D ]  \  }}| j                  d| d|       5  d}t        j                  |      }||j                  d   _	        ||j                  d   _
        | j                  t              5  t        |dd       d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   AxY w# 1 sw Y   -xY w# 1 sw Y   xY w)	N))
      )i)ru   rw   ))rx   rv   zCheck invalid linenos :za = 1r   rn   r[   zCheck invalid col_offset )re   r   ro   bodyr&   
end_linenor:   
ValueErrorrf   r'   end_col_offset)	r   invalid_linenosr&   r|   rq   rr   invalid_col_offsetsr'   r~   s	            r   !test_invalid_position_informationz+AST_Tests.test_invalid_position_informationw   sE   M"1FJ 6vha
|LM!yy)&,		!#*4		!'&&z2D*f5 3 NM #2 R*=&J+J<q8HI "yy)*4		!'.<		!+&&z2D*f5 3  +>	 32 NM" 32 sI   AD>9D2D><AEEE2D;7D>>E	EEE 	c           
         t        j                  t        j                  t        j                  ddd      gdd      t        j                  t        j                  ddd      gdd      gg       }t	        |dd	       y )
Nbuiltinsrv   r   r   r&   r'   )namesr&   r'   	tracebackr{   type_ignoresrn   r[   )r   ModuleImportaliasrf   r   rr   s     r   >test_compilation_of_ast_nodes_with_default_end_position_valueszHAST_Tests.test_compilation_of_ast_nodes_with_default_end_position_values   st    zz

99*Q1MN 
 

99+aANO  
" 	j&)r   c           	      *   t        j                  ddd      }ddddddddddddddfD ]X  }| j                  |      5  t        j                  t        j                  dd	|gi|gg 
      }t        |dd       d d d        Z y # 1 sw Y   exY w)Nr   r   r   ry   r&   r'   )r&   r'   r~   )r&   r|   r'   )attrsr   r   rn   r[   r5   )r   r   re   r   r   rf   )r   r   r   rr   s       r   #test_negative_locations_for_compilez-AST_Tests.test_negative_locations_for_compile   s    		{1C++bA1=	
E E*zzJJ6eW66( "$
 j&1 +*
 +*s   <B		B	c                    t        j                  d      j                  d   j                  j                  }| j                  |j                         | j                  |j                         | j                  |j                         y )Nzx[::]r   )	r   ro   r{   r1   slicerX   upperlowerstep)r   slcs     r   
test_slicezAST_Tests.test_slice   s]    ii %%a(..44#))$#))$#((#r   c                 ~    t        j                  d      j                  d   }| j                  |j                         y )Nzfrom . import yr   )r   ro   r{   rX   module)r   ims     r   test_from_importzAST_Tests.test_from_import   s.    YY()..q1"))$r   c                     t        j                  d      }| j                  |j                  d   t         j                         dj                         |j                  d   _        t        |dd       y )Nzfrom __future__ import divisionr   z __future__ <test>r[   )r   ro   assertIsInstancer{   
ImportFromstripr   rf   )r   mods     r   !test_non_interned_future_from_astz+AST_Tests.test_non_interned_future_from_ast   sR    ii9:chhqk3>>:+113Xv&r   c                    t        j                  d      j                  d   }| j                  t	        |j
                        d       |j
                  d   }| j                  |j                  d       | j                  |j                         | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  d      j                  d   }|j
                  d   }| j                  |j                  d       | j                  |j                         | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  d	      j                  d   }|j
                  d   }| j                  |j                  d       | j                  |j                  d
       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  d      j                  d   }|j
                  d   }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       y )Nzfrom bar import yr   rv   y      zfrom bar import **zfrom bar import y as zz   zimport bar as foobarfoo   )r   ro   r{   r,   lenr   r   rX   asnamer&   r|   r'   r~   )r   r   r   s      r   
test_aliaszAST_Tests.test_alias   s   YY*+003RXX*S)%,,'q)))1-))2.--r2YY*+003S)%,,'q)))1-))2.--r2YY/055a8S)s+q)))1-))2.--r2YY*+003U+u-q)))1-))1---r2r   c                    | j                  t        t        j                  t        j                               | j                  t        t        j
                  t        j                               | j                  t        t        j                  t        j                               | j                  t        t        j                  t        j                               | j                  t        t        j                  t        j                               | j                  t        t        j                  t        j                               y rC   )

assertTrue
issubclassr   Forr$   Namer#   r   comprehensionGtr   s    r   test_base_classeszAST_Tests.test_base_classes   s    
377CHH56
388SXX67
388SWW56
388SWW56
3#4#4cgg>?
36637734r   c                     t        d      }d}dD ]<  }| j                  t        |j                  |            5  t	        ||       d d d        > y # 1 sw Y   IxY w)Nr   zSast\.{} is deprecated and will be removed in Python 3.14; use ast\.Constant insteadNumStrBytesNameConstantEllipsis)r   assertWarnsRegexDeprecationWarningformatr)   )r   r   
depr_regexr   s       r   test_import_deprecatedz AST_Tests.test_import_deprecated   sZ    !%() 	 FD&&'9:;L;LT;RST" TS FSSs   AA	c                 2   t        j                         5  t        j                  ddt               ddlm}m}m}m}m	} d d d        dD ]  }t        t        |      }| j                  ||      s&| j                  |      5  | j                  t              5   |       }d d d        d d d        t        t        j                        s| j!                  t#        |j$                        t&                y # 1 sw Y   xY w# 1 sw Y   dxY w# 1 sw Y   hxY w)Nignore r   r   )warningscatch_warningsfilterwarningsr   r   r   r   r   r   r   r)   r   re   assertWarnsr   r   assertIsr   r"   tuple)	r   r   r   r   r   r   r   itemr?   s	            r   $test_field_attr_existence_deprecatedz.AST_Tests.test_field_attr_existence_deprecated   s    $$&##Hb2DECC ' HD3%D  t,\\$'))*<= F > ( a)MM$qyy/59 H	 '& >= ('s/   *C5 DDD5C>D
DD	c                 "   t         j                  j                         D ]n  \  }}|dv r|dk(  r| j                  ||      s$ |       }t	        |t         j
                        sF| j                  t        |j                        t               p y )N>   r   r   r   r   r   Index)
r   r9   itemsr   r   r   r   r   r"   r   )r   r   r   r?   s       r   test_field_attr_existencez#AST_Tests.test_field_attr_existence
  sn    ,,,,.JD$JJw  t,Fa)MM$qyy/59 /r   c                    t        j                         }| j                  |j                  d       | j	                  t
              5  |j                   d d d        | j                  |j                         t        j                  t        dd       }| j                  |j                  d       | j                  |j                  d       y # 1 sw Y   yxY w)N)posonlyargsargsr<   
kwonlyargskw_defaultskwargdefaultsrv      r8      )
r   	argumentsr,   r"   r:   r;   r   rX   r<   ranger>   s     r   test_argumentszAST_Tests.test_arguments  s    MMOII	
 ~.FF /!((#MM5A;'#1% /.s   CCc                     t        j                         5  t        j                  ddt               t	        j
                         }d d d        d_        | j                  |j                  d       y # 1 sw Y   -xY w)Nr   r     )r   r   r   r   r   r   r"   r,   r>   s     r   #test_field_attr_writable_deprecatedz-AST_Tests.test_field_attr_writable_deprecated.  sW    $$&##Hb2DE	A ' 	C( '&s   0A11A:c                 r    t        j                         }d|_        | j                  |j                  d       y )Nr   )r   Constantr"   r,   r>   s     r   test_field_attr_writablez"AST_Tests.test_field_attr_writable6  s(    LLN	C(r   c           	      F
   t        j                         5  t        j                  ddt               ddlm}m}m}m}m	} d d d        t        j                  d      5 }t        j                  ddt               t	        j
                         }| j                  |j                  d       | j                  t              5  |j                   d d d        | j                  t              5  |j                   d d d        t	        j
                  d	      }| j                  |j                  d	       | j                  |j                  d	       | j                  t              5  |j                    d d d        | j                  t              5  |j"                   d d d        t	        j
                  d
      }| j                  |j                   d
       t	        j
                  d	d      }| j                  |j                   d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d	       | j                  t$        t        j
                  dd d
       | j                  t$        t        j
                  dd d
d       | j                  t	        j
                  dd      j&                  d       | j)                  t$        d      5  t	        j
                  dd
       d d d        | j                  t	        j
                  d	      j                  d	       | j                  t	        j
                  d      j                  d       | j                  t	        j
                  d      j                  d       | j                  t	        j                  d      j*                  d       | j                  t	        j                  d      j*                  d       | j-                  t	        j                  d      j                  d       | j-                  t	        j                  d      j                  d       | j-                  t	        j                  d       j                  d        d d d        | j                  D cg c]  }t/        |j0                         c}g d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   dxY w# 1 sw Y   xY w# 1 sw Y   xY wc c}w )Nr   r   r   r   Trecordalwaysr1   rc   r6   r8   r&   rv   r   r   z(Num got multiple values for argument 'n'n      @              @42   42F)Rast.Num is deprecated and will be removed in Python 3.14; use ast.Constant insteadOAttribute n is deprecated and will be removed in Python 3.14; use value insteadr   r   r   r   r   r   r   r   r   r   r   r   r   r   Rast.Str is deprecated and will be removed in Python 3.14; use ast.Constant insteadOAttribute s is deprecated and will be removed in Python 3.14; use value insteadTast.Bytes is deprecated and will be removed in Python 3.14; use ast.Constant insteadr   [ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant insteadr   r   )r   r   r   r   r   r   r   r   r   r   r,   r"   r:   r;   r1   r   r&   r7   r=   r   rI   sr   strmessage)	r   r   r   r   r   r   wlogr?   ws	            r   test_classattrs_deprecatedz$AST_Tests.test_classattrs_deprecated<  s   $$&##Hb2DECC ' $$D1T##Hb2DE	AQYY(9:"">2 3 "">2 3 AQWWb)QSS"%"">2 3 "">2 3 q!AQXXq)1%AQXXq)QYY(9:QWWb)QSS"%i!T1=i!T1QG SWWQE266>''E Q
 SWWR[]]B/SWWT]__d3SWWU^--u5SWWT]__d3SYYu-//7MM#**4066=MM#**5177?MM#**4066=a 2d 	%)*TS^T*	
m '& 32 32 32 32$ I 21f +s   *SA!T>ST(S5A*TS+,T	S8ET.TF TTSS	TS(	#T+S5	0T8T	=TT	
TTc                     t        j                         }| j                  |j                  d       | j	                  t
              5  |j                   d d d        t        j                  d      }| j                  |j                  d       | j	                  t
              5  |j                   d d d        | j	                  t
              5  |j                   d d d        t        j                  d      }| j                  |j                  d       t        j                  dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j	                  t        t         j                  dd d       | j	                  t        t         j                  dd dd       | j                  t        j                  dd      j                  d       | j                  t        d	      5  t        j                  dd
       d d d        | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d       j                  d        | j                  t        j                  d      j                  d       y # 1 sw Y   xY w# 1 sw Y   =xY w# 1 sw Y    xY w# 1 sw Y   xY w)Nr   r6   r8   r   r   rv   r   r   z1Constant got multiple values for argument 'value'r1   r   r   r   r   TF.)r   r   r,   r"   r:   r;   r1   r&   r7   r=   r   rI   r   r>   s     r   test_classattrszAST_Tests.test_classattrs  s   LLN$56~.GG / LL"%~.HH / ~.HH / LL"1%LLA&1%$56"%)S\\1dA>)S\\1dAaH 	aU377?##J
 LL!$

 	b)//4d+1148e,22E:d+1148e,22E:cll4(..5cll5)//7cll4(..5cll3'--s3O /. /. /."
 
s0   O!O)O6PO&)O36P Pc                    t        j                         5  t        j                  ddt               ddlm}m}m}m}m	} d d d        t        j                  d      5 }t        j                  ddt               | j                  t        t	        j
                  d            t        j                         | j                  t        t	        j
                  d	            t        j                         | j                  t        t	        j
                  d
            t        j                         | j                  t        t	        j                  d            t        j                         | j                  t        t	        j                  d            t        j                         | j                  t        t	        j                  d            t        j                         | j                  t        t	        j                  d            t        j                         | j                  t        t	        j                  d             t        j                         | j                  t        t	        j                               t        j                         d d d        | j                  D cg c]  }t        |j                         c}g d       y # 1 sw Y   xY w# 1 sw Y   LxY wc c}w )Nr   r   r   r   Tr   r   r6   r   r   r   r   F)	r   r   r   r   r   r   r   r   zWast.Ellipsis is deprecated and will be removed in Python 3.14; use ast.Constant instead)r   r   r   r   r   r   r   r   r   r   r   r   r   r,   r   r   )r   r   r   r   r   r   r   r   s           r   test_realtypezAST_Tests.test_realtype  s   $$&##Hb2DECC ' $$D1T##Hb2DEMM$swwr{+S\\:MM$swwt}-s||<MM$swwu~.=MM$swwt}-s||<MM$syy/0#,,?MM$s//56EMM$s//67FMM$s//56EMM$s||~.= 2 	%)*TS^T*
	
! '& 21 +s   *KH7K+K+KK(c                 t   ddl m} t        j                         5  t        j                  ddt
               ddl m}m}m}m	}m
} d d d        d}t        | j                  t
        |j                  d            }t        | j                  t
        |j                  d            }	t        | j                  t
        |j                  d	            }
t        | j                  t
        |j                  d
            }t        | j                  t
        |j                  d            }dD ]W  }| j                  |      5   |       5   |      }d d d         |       5  | j                         d d d        d d d        Y  |	       5   d      }d d d         |	       5  | j                         d d d         |
       5   d      }d d d         |
       5  | j                         d d d        dD ]W  }| j                  |      5   |       5   |      }d d d         |       5  | j                         d d d        d d d        Y  |       5          }d d d         |       5  | j                         d d d        dD ]E  }| j                  |      5   |       5  | j                   ||             d d d        d d d        G  |	       5  | j                   |d             d d d         |
       5  | j                   |d             d d d        dD ]E  }| j                  |      5   |       5  | j                   ||             d d d        d d d        G  |       5  | j                   |d             d d d         |	       5   d      }d d d         || j                           |
| j                   |        |       5   |d      }d d d         |	| j                           || j                   |        || j                   |        |       5   |d      }d d d         |       5  | j!                  ||       d d d         |       5   |d      }d d d         |       5  | j!                  ||       d d d        dD ]E  }| j                  |      5   |       5  | j!                   ||      |       d d d        d d d        G  |	| j                    |d      |        |
| j                    |d      |        || j                    |d      |        || j                    |d      |        || j                    |       |        |	| j                    |       |        |
| j                    |       |        || j                    |       |        || j                    |       |        G d dt"              } |	       5  | j                   | |d            |       d d d         |       5  | j!                   | |d            |       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   CxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   qxY w# 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   UxY w# 1 sw Y   "xY w# 1 sw Y   mxY w# 1 sw Y   
xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   fxY w# 1 sw Y   xY w# 1 sw Y   
xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   )r   r   r   r   zQast.{} is deprecated and will be removed in Python 3.14; use ast.Constant insteadr   r   r   r   r   )r6   g@y        @)argr   r   TFN.r6   TF)r   TFc                       e Zd Zy)$AST_Tests.test_isinstance.<locals>.SNrO   r5   r   r   Sr	  Q  rS   r   r
  )r   r   r   r   r   r   r   r   r   r   r   r   r   r   re   r   assertNotIsInstancer   )r   r   r   r   r   r   r   cls_depr_msgassertNumDeprecatedassertStrDeprecatedassertBytesDeprecatedassertNameConstantDeprecatedassertEllipsisDeprecatedr  r   r   ber
  s                      r   test_isinstancezAST_Tests.test_isinstance  sS    $$&##Hb2DECC '
' 	
 &!!#5|7J7J57Q
 &!!#5|7J7J57Q
 !(!!#5|7J7J77S!
 (/!!/(
$
 $+!!#5|7J7J:7V$
  !C#&(*CA +(*))!S1 + '& ! !"D	A # "!!!S) # #$eA %"$!!!U+ % %C#&13$S)A 413))!\: 4 '& % &'
A (%'!!!X. ( !C#&(*))(3-= + '& !
 !"!!(4.#6 # #$!!(5/59 % %C#&13))(3-F 4 '& %
 &'!!(3-: ( !"D	A #D44a=d665A "BA #D44a=$T%=%=q,O !9!91hG)+T"A , "$$Q, # *+U#A , "$$Q, # %C#&(*,,Xc]C@ + '& %
 	D44hrlCHd66N$$$hrlL	
 	!!9!98B<RD44hj#FD44hj#Fd66
EJ$T%=%=xz<X !9!98:xP	 	 !"!!(1T7"3S9 # "$$Xag%6< #"m '&: +*** '& #""" %$$$
 4333 '& ('''
 +* '& #" %$
 43 '& (' #"
 #" ,+"" ,+""
 +* '&& #"""s  *X58Y 	Y	YY+Y	Y)Y6>	ZZZ7	ZZ7(Z*;Z7[+[[+%[>[+[8?\7\?\\1\,	\9	]-	]] '	]-?]:1^9^^^!^.5X?YYYYY&	)Y36Z ZZZ'"Z7*Z4/Z77[	[[[(#[++[5	8\\\\\)	,\69]]] ]*-]7:^^^^	!^+.^7c                    t        j                         5  t        j                  ddt               ddlm} d d d        t        j                  d      5 }t        j                  ddt                G d d	t        j
                        } G d
 dt        j
                        } |d      }| j                  |j                  d       | j                  |j                  d       | j                  t        |      |       | j                  ||       | j                  |t        j
                         | j                  ||       | j                  t	        j
                  d      |        |d      }| j                  |j                  d       | j                  t        |      |       d d d        | j                  D cg c]  }t        |j                         c}g d       y # 1 sw Y   xY w# 1 sw Y   LxY wc c}w )Nr   r   r   r   Tr   r   c                        e Zd Z fdZ xZS )8AST_Tests.test_constant_subclasses_deprecated.<locals>.Nc                 2    t        |   |i | d| _        y Nspamsuper__init__r   r   r   kwargs	__class__s      r   r  zAAST_Tests.test_constant_subclasses_deprecated.<locals>.N.__init__b  s    G$d5f5#DFr   rP   r   rQ   r  __classcell__r!  s   @r   Nr  a  s    $ $r   r%  c                       e Zd Zy)9AST_Tests.test_constant_subclasses_deprecated.<locals>.N2NrO   r5   r   r   N2r'  f      r   r(  r6   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   s          r   #test_constant_subclasses_deprecatedz-AST_Tests.test_constant_subclasses_deprecatedY  sx   $$&##Hb2DE ' $$D1T##Hb2DE$CGG $
SWW  "AQSS"%QSS&)MM$q'1%!!!Q'!!!SWW-$$Q+$$SWWR[!4BAQSS"%MM$q'1%+ 2. 	%)*TS^T*
	
7 '& 210 +s   "G%EG2>G>%G/2G;c                     G d dt         j                        } G d dt         j                        } |d      }| j                  |j                  d       | j                  |j                  d       | j                  t        |      |       | j                  t        ||             | j                  t        |t         j                               | j                  t        ||             | j                  t        t        j                  d      |              |d      }| j                  |j                  d       | j                  t        |      |       y )Nc                        e Zd Z fdZ xZS )-AST_Tests.test_constant_subclasses.<locals>.Nc                 2    t        |   |i | d| _        y r  r  r  s      r   r  z6AST_Tests.test_constant_subclasses.<locals>.N.__init__  s     $1&1r   r"  r$  s   @r   r%  r-    s       r   r%  c                       e Zd Zy).AST_Tests.test_constant_subclasses.<locals>.N2NrO   r5   r   r   r(  r0    rS   r   r(  r6   r  r  )	r   r   r,   r1   r   r   r   r   assertFalse)r   r%  r(  r   s       r   test_constant_subclassesz"AST_Tests.test_constant_subclasses  s    	  	 
	 	 bE"%f%a!$
1a()
1cll34Ar*+CLL$4a89BK"%a!$r   c                     t        j                  d      g}t        j                  |g       }| j                  |j                  |       y )Nr6   )r   r   r   r,   r{   )r   r{   r?   s      r   test_modulezAST_Tests.test_module  s7    R !JJtR &r   c           	         t        j                         }| j                  |j                  d       d|_        | j                  |j                  d       t        j
                  d      }t        j
                  d      }t        j                         }t        j                  |||      }| j                  |j                  |       | j                  |j                  |       | j                  |j                  |       t        j                  ddd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  dddd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  t        t         j                  dddd       | j                  t        t         j                  ddddd       t        j                  dddd	      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  dddd
      }| j                  |j                  d
       y )N)leftopright   rv   r   r8   r   r      )r6  r7  r8  r&   r6   )	foobarbaz)r   BinOpr,   r"   r;  r   Addr6  r7  r8  r&   r:   r=   )r   r?   n1n3addops        r   test_nodeclasseszAST_Tests.test_nodeclasses  s3   IIK$;< a(\\!_\\!_	IIb%$$u%"%IIaA#q!!$IIaAa(#q!!$1% 	)SYY1a;)SYY1a1E II1!A6#q!!$1% IIaA,b)r   c                 d    t        j                         }| j                  |j                  d       y )Nr5   )r   Subr,   r"   r>   s     r   test_no_fieldszAST_Tests.test_no_fields  s!    GGIB'r   c                     dd l }t        |j                  dz         D ]Y  }d t        D        D ]G  }|j	                  |j                  ||            }| j                  t        |      t        |             I [ y )Nr   rv   c              3   8   K   | ]  }t        |d dd        yw)ra   r[   i   N)rf   ).0ri   s     r   	<genexpr>z*AST_Tests.test_pickling.<locals>.<genexpr>  s     K
136
s   )pickler   HIGHEST_PROTOCOLr   loadsdumpsr,   r
   )r   rI  protocolr   ast2s        r   test_picklingzAST_Tests.test_pickling  s`    f559:HK
K||FLLh$?@  $#? L ;r   c           	      R   t        dd      }t        j                  t        j                  t        j                  di |fi |gg       }| j                  t              5 }t        |dd       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Nr8   r   r   r   r[   zbut got <ast.exprr5   )dictr   r   Exprr#   r:   r=   rf   assertInr   	exception)r   posmcms       r   test_invalid_sumzAST_Tests.test_invalid_sum  s{    !*JJC8C892>y)RAx( *)3r||+<= *)s   !BB&c           	         t        j                  t        j                  t        j                  dt        j                                     gg       }t        j
                  |       | j                  t              5 }t        |dd       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Nr6   r   r[   zidentifier must be of type str)r   r   rR  r   Loadfix_missing_locationsr:   r=   rf   rS  r   rT  )r   rV  rW  s      r   test_invalid_identifierz!AST_Tests.test_invalid_identifier  s    JJ"chhj!9:;R@!!!$y)RAx( *6BLL8IJ *)s   ;B77C c                 :   t         ddt         ft        ddt         f      fD ]l  }t        j                  t        j                  |            }t        j
                  |       | j                  t        d      5  t        |dd       d d d        n y # 1 sw Y   yxY w)Nrv   r8   r{   zinvalid type in Constant: typer   r]   )	int	frozensetr   
Expressionr   r[  rI   r=   rf   )r   invalid_constantr  s      r   test_invalid_constantzAST_Tests.test_invalid_constant  s|     #aC[)Q3K2H HCLL1A$BCA%%a(''	3ST8V, UT !I UTs   8BB	c                 <   t        j                  d      }d |j                  d   j                  d   j                  _        | j	                  t
              5 }t        |dd       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Nzdef f():
 yield from g()r   r   r[   zfield 'value' is required)
r   ro   r{   r1   r:   r}   rf   rS  r   rT  )r   empty_yield_fromrW  s      r   test_empty_yield_fromzAST_Tests.test_empty_yield_from  sz    99%@A7;a %%a(..4z*b$h7 +13r||3DE +*s   BBc                     dd l }d }t        j                  |d|      5  | j                  t        t
        j                  d       d d d        y # 1 sw Y   y xY w)Nr   c                       y rC   r5   r   s    r   bad_normalizez0AST_Tests.test_issue31592.<locals>.bad_normalize  s    r   	normalizeu   ϕ)unicodedatar   	swap_attrr:   r=   r   ro   )r   rl  rj  s      r   test_issue31592zAST_Tests.test_issue31592  sC     		 {KGiH= HGGs   &AAc                    t        j                  d      }|j                  d   j                  }|j                  }|j                  }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  d      }|j                  d   j                  }|j                  }|j                  }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d	       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       y )
Nz4+5+6+7r   r   r9  r   z
4+5-\
 6-7rv   r:  r8   )
r   ro   r{   r1   r6  r,   r'   r~   r&   r|   )r   rr   parent_binopchild_binopgrandchild_binops        r    test_issue18374_binop_col_offsetz*AST_Tests.test_issue18374_binop_col_offset  s   yy#yy|))"''&++00!444a8//333Q7)44a8)88!<yy(yy|))"''&++00!4,,a044a800!4//3++Q/33Q7//3)44a8)00!4)88!<)44a8r   c                     t        j                  d      }|j                  d   j                  d   j                  }| j                  |j                  d       y )Nz@a.b.c
def f(): passr   r:  )r   ro   r{   r!   r1   r,   r~   )r   rr   attr_bs      r   *test_issue39579_dotted_name_end_col_offsetz4AST_Tests.test_issue39579_dotted_name_end_col_offset  sE    yy011,,Q/55..2r   c                    | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j
                  j                  d       | j                  t        j                  j                  d       t        j                  j                         D cg c]  }d|j                    }}dt        j                  j                         d   j                   |d<   | j                  t        j                  j                  j                  d      |       y c c}w )	Nz0withitem(expr context_expr, expr? optional_vars)GtEz%Name(identifier id, expr_context ctx)zBcmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotInz     | zexpr = r   
)r,   r   withitem__doc__rx  r   cmpopr#   __subclasses__assertCountEqualsplit)r   r   expressionss      r   test_ast_asdl_signaturez!AST_Tests.test_ast_asdl_signature!  s    LL  "T	
 	%0))+RSIIP	
 =@HH<S<S<UV<UD/<UV"388#:#:#<Q#?#G#G"HIAchh..44T:KH Ws   	Ec                    t        j                  dd       t        j                  dd       | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd       d d d        t        j                  dd       t        j                  dd       | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   WxY w# 1 sw Y   y xY w)Nzdef foo(x, /): ...r   r   feature_versionzdef bar(x=1, /): ...r   r   zlambda x, /: ...zlambda x=1, /: ...r   ro   r:   SyntaxErrorr   s    r   $test_positional_only_feature_versionz.AST_Tests.test_positional_only_feature_version/  s    		&?		(&A{+II*FC ,{+II,fE , 			$f=		&?{+II(&A ,{+II*FC ,+ ,+++
 ,+++s0   D29D>E
E2D;>E
EEc                     t        j                  dd       | j                  t              5  t        j                  dd       d d d        y # 1 sw Y   y xY w)Nz(x := 0)r  r  r  r  r   s    r   *test_assignment_expression_feature_versionz4AST_Tests.test_assignment_expression_feature_version>  s8    		*f5{+IIj&9 ,++s   AAc                 2    t        j                  dd       y )Nzwith (x() if y else z()): ...r  r  )r   ro   r   s    r   @test_conditional_context_managers_parse_with_low_feature_versionzJAST_Tests.test_conditional_context_managers_parse_with_low_feature_versionC  s    		16Jr   c                     t        d      }t        j                  |       | j                  t              5  t        j                  |d       d d d        y # 1 sw Y   y xY w)Nz9
        try: ...
        except* Exception: ...
        )r   ru   r  )r   r   ro   r:   r  )r   codes     r   %test_exception_groups_feature_versionz/AST_Tests.test_exception_groups_feature_versionG  sF       			${+IIdG4 ,++s   AA c                    g d}|D ]f  }| j                  |      5  t        j                  |       | j                  t              5  t        j                  |d       d d d        d d d        h y # 1 sw Y   xY w# 1 sw Y   xY w)N)ztype X = intzclass X[T]: passzdef f[T](): pass)r      r  )re   r   ro   r:   r  )r   samplessamples      r    test_type_params_feature_versionz*AST_Tests.test_type_params_feature_versionP  sh    

 Ff%		&!&&{3IIfg> 4 &%  43 &%s#   +A=A1A=1A:6A==B	c                    | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd       d d d        y # 1 sw Y   ?xY w# 1 sw Y   y xY w)Npass)r8   r   r  )r:  r   )r:   r}   r   ro   r   s    r   "test_invalid_major_feature_versionz,AST_Tests.test_invalid_major_feature_version\  sW    z*IIff5 +z*IIff5 +* +***s   A,A8,A58Bc                 *   dD ]  }t        j                  t        j                  |t        j                                     }t        j                  |       | j                  t        d| d      5  t        |dd       d d d         y # 1 sw Y   xY w)N)TrueFalseNonez"identifier field can't represent 'z
' constantr   r]   )r   ra  r   rZ  r[  rI   r}   rf   )r   constantr#   s      r   test_constant_as_namezAST_Tests.test_constant_as_nameb  sy    /H>>#((8SXXZ"@AD%%d+''@
*U h/  0 s   0B		B	c                 ~     G d dt         j                        }t        j                  |t        j                         y )Nc                   ~   e Zd ZdZ ej
                         Z ej
                         Z ej
                         Z ej
                         Z	 ej
                         Z
 ej
                         Z ej
                         Z ej
                         Z ej
                         ZeZ ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Zd Zy)3AST_Tests.test_precedence_enum.<locals>._Precedencez5Precedence table that originated from python grammar.c                 N    	 | j                  | dz         S # t        $ r | cY S w xY w)Nrv   )r!  r}   r   s    r   nextz8AST_Tests.test_precedence_enum.<locals>._Precedence.next  s.     >>$(33!  K s    $$N)rP   r   rQ   r{  enumauto
NAMED_EXPRTUPLEYIELDTESTORANDNOTCMPEXPRBORBXORBANDSHIFTARITHTERMFACTORPOWERAWAITATOMr  r5   r   r   _Precedencer  l  s    G"JDIIKEDIIKE499;DB$))+C$))+C$))+C499;DC499;D499;DDIIKEDIIKE499;DTYY[FDIIKEDIIKE499;D r   r  )r  IntEnum_test_simple_enumr   r  )r   r  s     r   test_precedence_enumzAST_Tests.test_precedence_enumk  s(    	 $,, 	 < 	{COO<r   zexhausts limited stack on WASIc                      t         j                  dz   dt        t         j                  dz         fd} |dd        |dd        |dd        |dd	       y )
Nrv   i g?c                 \   | |	z  z   }t        j                  |       fD ]o  }| ||z  z   }dj                  | ||      }j                  t        |      5  t        j                         5  t        j                  |       d d d        d d d        q y # 1 sw Y   xY w# 1 sw Y   xY w)NzCompiling ({!r} + {!r} * {})rJ   )r   ro   r   r:   RecursionErrorr   infinite_recursion)
prefixrepeated	expect_okdepthbrokendetailscrash_depth
fail_depthr   success_depths
         r   check_limitz7AST_Tests.test_ast_recursion_limit.<locals>.check_limit  s    M!99IIIi $k2(U"228??RWX&&~7&C 335		&) 6 DC 3 65 DCs$   B"-BB"BB""B+	rT   ()z.bz[0]z*a)r   C_RECURSION_LIMITr_  )r   r  r  r  r  s   ` @@@r   test_ast_recursion_limitz"AST_Tests.test_ast_recursion_limit  s^     ..2
G55;<	* 	CCCCr   c                     | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   y xY w)Nz,source code string cannot contain null bytesr  za b)r:   r  r   ro   r   s    r   test_null_byteszAST_Tests.test_null_bytes  s9    K  
 IIf
 
 
s	   7A r   attrsourcereturnc                    | j                  |j                   d|       5  t        j                  |      }d}t        j                  |      D ]!  }t        ||      st        ||d        |dz  }# | j                  |d       t        j                  d| d|j                         }| j                  t        d| d      5  t        |dd	       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)
N.r   rv   zfield 'z' is required for ^$r   r[   )re   rP   r   ro   walkr   setattrr,   reescaperI   r}   rf   )r   r   r  r  rr   foundr3   r  s           r   assert_none_checkzAST_Tests.assert_none_check  s    \\T]]O1TF3499V$DE$eT*E4.QJE ( UA&		GD6);DMM?KLA''
as!H=h/ > 54 >= 54s*   <C.A%C.C"C."C+	'C..C7c           	      @   t         j                  ddft         j                  ddft         j                  ddft         j                  ddft         j                  d	d
ft         j
                  ddft         j                  ddfg}|D ]  \  }}}| j                  |||        y )Nr   zimport spam as SPAMr  zdef spam(SPAM): spamtargetz[spam for SPAM in spam]iterz[spam for spam in SPAM]r1   zspam(**SPAM)patternzmatch spam:
 case SPAM: spamcontext_exprzwith SPAM: spam)r   r   r  r   keyword
match_caserz  r  )r   testsr   r  r  s        r   test_none_checkszAST_Tests.test_none_checks  s    YY 56WWe34*CD(AB[['>2^^Y(GH\\>+<=
 #(D$""4v6 #(r   )r  N)@rP   r   rQ   maxDiffr   r+   r@   rK   rY   rl   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r*  r2  r4  rA  rD  rO  rX  r\  rc  rf  r   cpython_onlyrn  rs  rv  r  r  r  r  r  r  r  r  r  unittestskipIfis_wasir  r  r   r   r   r   r  r  r5   r   r   r   r      s   G3D&"
!1.60*(2"$%'$3L5#::&.))R
h+4Z
@z=x&
P%*'
**X(
@>K-F 	> 	>9>3
ID:
K5
?60=B X__W__&FG  H(0d377m 03 0 0PT 07r   r   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)ASTHelpers_TestNc                     t        j                  d      }t        dddt         j                        }| j	                  t        j
                  |      t        j
                  |             y )Nz
foo(1 + 1)z	<unknown>r[   )r   ro   rf   rg   r,   dump)r   rT   r  s      r   
test_parsezASTHelpers_Test.test_parse  sF    IIl#L+vs7H7HI!chhqk2r   c                     	 ddz   y # t         $ rh | j                  t              5 }t        j                  d       d d d        n# 1 sw Y   nxY w| j                  j                  j                         Y y w xY w)Nrv   r   z'\U')	Exceptionr:   r  r   literal_evalassertIsNotNonerT  __context__r   r  s     r   test_parse_in_errorz#ASTHelpers_Test.test_parse_in_error  s_    	:E 	:"";/1  ) 0//  !8!89	:s%    A9A	A9A	
,A98A9c                    t        j                  d      }| j                  t        j                  |      d       | j                  t        j                  |d      d       | j                  t        j                  |d      d       y )	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   ro   r,   r  r   r   s     r   	test_dumpzASTHelpers_Test.test_dump  sv    yy34HHTN/	
 	HHT512	

 	HHTd3Z		
r   c                    t        j                  d      }| j                  t        j                  |d      d       | j                  t        j                  |dd      d       | j                  t        j                  |d	d
      d       y )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  s     r   test_dump_indentz ASTHelpers_Test.test_dump_indent  s|    yy34HHT!$
	
 	HHT5>
		
 	HHTd1=#&	
r   c                    t        j                  dd      }| j                  t        j                  |      d       | j                  t        j                  |d      d       t        j                  t        j                  dt        j
                         	      dd
      }| j                  t        j                  |      d       | j                  t        j                  |d      d       | j                  t        j                  |d      d       | j                  t        j                  |dd      d       t        j                  t        j                  dt        j
                         	            }| j                  t        j                  |      d       | j                  t        j                  |d      d       y )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   rZ  r  s     r   test_dump_incompletez$ASTHelpers_Test.test_dump_incomplete1  sD   yya0$3HHTd35T	
 yySXX#((*=aTUV$)NOHHT513M	
 	HHTd3I	
 	HHT5TJ>	
 yysxx3CHHJ?@$)PQHHT513S	
r   c                 |   t        j                  dd      }t        j                  t        j                  d      |j                  j
                        |j                  _        | j                  t        j                  |d      d       t        j                  dddd	      }t        j                  |t        j                  d d 
            }| j                  |j                         | j                  |j                         | j                  |j                  d       | j                  |j                  d       y )N1 + 1r]   moder8   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))rv   )r'   r&   r|   r~   )r'   r&   )r   ro   copy_locationr   r{   r8  r,   r  CallrX   r|   r~   r&   r'   )r   srcnews      r   test_copy_locationz"ASTHelpers_Test.test_copy_locationJ  s    iif-**3<<?CHHNNKHHST2=	
 hh!A!ANSXXd%KL#..)#,,-Q'+r   c                    t        j                  d      }|j                  j                  t        j                  t        j
                  t        j                  dt        j                               t        j                  d      gg                    | j                  |t        j                  |             d | _        | j                  t        j                  |d      d       y )Nzwrite("spam")r  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   ro   r{   appendrR  r  r   rZ  r   r,   r[  r  r  r   r  s     r   test_fix_missing_locationsz*ASTHelpers_Test.test_fix_missing_locations[  s    ii(HHSXXchhvsxxz:S\\&=Q<RTVWX	
 	c77<=HHST2
	
r   c                    t        j                  dd      }| j                  t        j                  |d      |       | j                  t        j                  |d      d       t        j                  dd      }| j                  t        j                  |j
                  d      |j
                         | j                  t        j                  |d      d       t        j                  t        j                  d	t        j                               g g d
      }| j                  t        j                  |      j                  d       | j                  t        j                  |      j                         y )Nr  r]   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))testrv   )funcr   keywordsr&   r8   )r   ro   r,   increment_linenor  r{   r  r   rZ  r&   rX   r|   r  s     r   test_increment_linenoz%ASTHelpers_Test.test_increment_linenoq  s   iif---cQ7=HHST2=	
 iif---chh!<chhGHHST2=	
 hh&#((*-BA
 	--c2991=#..s3>>?r   c                 h   t        j                  t        d      d      }t        j                  |d       | j	                  |j
                  d   j                  d       | j	                  |j
                  d   j                  d	       | j	                  |j
                  d   j                  d
       y )Nzb        a = 1
        b = 2 # type: ignore
        c = 3
        d = 4 # type: ignore@tag
        T)type_commentsr9  r   r   r   rv   	   z@tag)r   ro   r   r  r,   r   r&   tagr  s     r   test_increment_lineno_on_modulez/ASTHelpers_Test.test_increment_lineno_on_module  s    ii   
 	SA&))!,33Q7))!,33Q7))!,00&9r   c                    t        j                  dd      }t        t        j                  |j                              }| j                  |j                  d      j                  d       | j                  |g g d       y )Nfoo()r]   r  r  r   )r  r   )r   ro   rQ  iter_fieldsr{   r,   popr  )r   r   ds      r   test_iter_fieldsz ASTHelpers_Test.test_iter_fields  s\    yyv.+,v))51R89r   c           	      ,   t        j                  dd      }| j                  t        t	        t        j
                  |j                                    d       t        j
                  |j                        }| j                  t        |      j                  d       | j                  t        |      j                  d       | j                  t        |      j                  d       | j                  t        j                  t        |            d       y )	Nzspam(23, 42, eggs='leek')r]   r  r:  r     r6   z1keyword(arg='eggs', value=Constant(value='leek')))r   ro   r,   r   r*   iter_child_nodesr{   r  r  r1   r  )r   r   iterators      r   test_iter_child_nodesz%ASTHelpers_Test.test_iter_child_nodes  s    yy46BT#"6"6tyy"ABCQG''		2h**F3h--r2h--r2HHT(^$?	
r   c                 B   t        j                  d      }| j                  t        j                  |      d       t        j                  d      }| j                  t        j                  |j                  d         d       t        j                  d      }| j                  t        j                  |j                  d         d       t        j                  d      }| j                  t        j                  |j                  d         d       t        j                  d      }| j                  t        j                  |j                  d   d	      d
       t        j                  d      }| j                  t        t         j                  |j                  d          y )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
hamF)cleanz
spam
  hamr?   )r   ro   r,   get_docstringr{   r:   r=   r  s     r   test_get_docstringz"ASTHelpers_Test.test_get_docstring  s&   yy56**402FGyyCD**499Q<8:NOyyCD**499Q<8:NOyy@A**499Q<8+Fyy@A**499Q<uE}Uyy~)S%6%6		!Er   c                    | j                  t        j                  t        j                  d                   t        j                  d      }| j                  t        j                  |             t        j                  d      }| j                  t        j                  |             t        j                  d      }| j                  t        j                  |j                  d                t        j                  d      }| j                  t        j                  |j                  d                t        j                  d      }| j                  t        j                  |j                  d                t        j                  d      }| j                  t        j                  |j                  d                t        j                  d      }| j                  t        j                  |j                  d                t        j                  d	      }| j                  t        j                  |j                  d                t        j                  d
      }| j                  t        j                  |j                  d                t        j                  d      }| j                  t        j                  |j                  d                y )Nr   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"zasync def foo():
  42)rX   r   r3  ro   r{   r  s     r   test_get_docstring_nonez'ASTHelpers_Test.test_get_docstring_none  s   #++CIIbM:;yy./#++D12yy-.#++D12yy-.#++DIIaL9:yy<=#++DIIaL9:yy<=#++DIIaL9:yy-.#++DIIaL9:yy<=#++DIIaL9:yy34#++DIIaL9:yyBC#++DIIaL9:yy12#++DIIaL9:r   c                 2   t        j                  d      }| j                  |j                  d   j                  d       | j                  |j                  d   j
                  d       | j                  |j                  d   j                  d   j                  d       | j                  |j                  d   j                  d   j
                  d       | j                  |j                  d   j                  d   j                  d   j                  d       | j                  |j                  d   j                  d   j                  d   j
                  d       | j                  |j                  d   j                  d   j                  d       | j                  |j                  d   j                  d   j
                  d       | j                  |j                  d   j                  d       | j                  |j                  d   j
                  d	       y )
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   rv   r8   r9  r:  r#  r     )r   ro   r,   r{   r'   r&   r  s     r   :test_multi_line_docstring_col_offset_and_lineno_issue16806zJASTHelpers_Test.test_multi_line_docstring_col_offset_and_lineno_issue16806  s   yy+
 	100!41,,a01**1-88!<1**1-44a81**1-2215@@!D1**1-2215<<a@1**1-88!<1**1-44b9100!41,,b1r   c                     t        j                  d      }|j                  d   j                  d   }| j	                  |j
                  d       | j	                  |j                  d       y )Nz if a:
    pass
elif b:
    pass
r   r   r   ro   r{   orelser,   r&   r'   r   r   	elif_stmts      r   test_elif_stmt_start_positionz-ASTHelpers_Test.test_elif_stmt_start_position  sU    yy?@IIaL''*	))1---q1r   c                     t        j                  d      }|j                  d   j                  d   }| j	                  |j
                  d       | j	                  |j                  d       y )Nz/if a:
    pass
elif b:
    pass
else:
    pass
r   r   r;  r=  s      r   'test_elif_stmt_start_position_with_elsez7ASTHelpers_Test.test_elif_stmt_start_position_with_else  sU    yyPQIIaL''*	))1---q1r   c                     t        j                  d      }|j                  d   j                  j                  d   }| j                  |j                  d       | j                  |j                  d       y )Nz
f(*[0, 1])r   rv   r#  )r   ro   r{   r1   r   r,   r|   r~   )r   r   starred_exprs      r   *test_starred_expr_end_position_within_callz:ASTHelpers_Test.test_starred_expr_end_position_within_call  sZ    yy&yy|))..q100!444a8r   c                    | j                  t        j                  d      g d       | j                  t        j                  d      ddi       | j                  t        j                  d      d       | j                  t        j                  d      h d	       | j                  t        j                  d
      d       | j                  t        j                  d      t                      | j	                  t
        t        j                  d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        t        j                  d            d       | j	                  t
        t        j                  d       | j	                  t
        t        j                  d       | j	                  t
        t        j                  d       y )Nz	[1, 2, 3]rv   r8   r   z{"foo": 42}r   r6   z(True, False, None)r  z	{1, 2, 3}>   rv   r8   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   s    r   test_literal_evalz!ASTHelpers_Test.test_literal_eval  s   ))+6	B))-85"+F))*?@BUV))+6	B))'2E:))'2CE:*c&6&6@))#.2))$/3))$/4))&148))'2D9))'2E:c..v67@*c&6&6>*c&6&6@*c&6&6>r   c                    t        j                  d      5  t        j                  d       | j	                  t
              5 }t        j                  d       d d d        | j                  dt        j                               | j                  dt        |j                               d d d        y # 1 sw Y   \xY w# 1 sw Y   y xY w)Ni    3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333  33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333zExceeds the limit z Consider hexadecimal )	r   adjust_int_max_str_digitsr   r  r:   r  rS  r   rT  )r   err_ctxs     r   test_literal_eval_str_int_limitz/ASTHelpers_Test.test_literal_eval_str_int_limit  s    ..t4Z("";/7  , 0MM.G4E4E0FGMM2C8I8I4JK 54// 54s$   +B>B2AB>2B;	7B>>Cc                 8   | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d	      d
       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d
       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       y )N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   s    r   test_literal_eval_complexz)ASTHelpers_Test.test_literal_eval_complex  s   ))$/4))%0#6))'2E:))(3V<))&16:))'2G<))&16:))'2G<)),7F))-8-H)),7F))-8-H))(3V<*c&6&6@*c&6&6A*c&6&6@*c&6&6
C*c&6&6	Br   c                    t        j                  t        j                  d      t        j                  d      gt        j                  d      g      }| j                  t        t         j
                  |       t        j                  t        j                  d      gt        j                  d      t        j                  d      g      }| j                  t        t         j
                  |       y )Nrv   r8   r   )keysvalues)r   Dictr   r:   r}   r  )r   	malformeds     r   &test_literal_eval_malformed_dict_nodesz6ASTHelpers_Test.test_literal_eval_malformed_dict_nodes/  s    HH,,q/3<<?3S\\!_<M
	 	*c&6&6	BHH,,q/"CLLOS\\!_+M
	 	*c&6&6	Br   c                 ,   | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        t        j                  d       y )Nz    -1z		-1z 	 -1z
 -1)r,   r   r  r:   IndentationErrorr   s    r   test_literal_eval_trailing_wsz-ASTHelpers_Test.test_literal_eval_trailing_ws9  sl    ))(3R8))(3R8))(3R8*C,<,<gFr   c           	         d}| j                  t        |      5  t        j                  d       d d d        t        j                  t        j
                         t        j                  t        j
                         t        j                  d                  }| j                  t        |dd              d}| j                  t        |      5  t        j                  |       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nz#malformed node or string on line 3:z{'a': 1,
'b':2,
'c':++3,
'd':4}rH  r&   zmalformed node or string:)	rI   r}   r   r  UnaryOpUAddr   rX   r)   )r   rJ   r   s      r   "test_literal_eval_malformed_linenoz2ASTHelpers_Test.test_literal_eval_malformed_lineno?  s    4##J4AB 5 {{388:s{{388:s||A'OP'$$78*##J4T" 54 54 54s   C+C7+C47D c                     | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   y xY w)Nzunexpected indentz4
                \
                (\
            \ )rI   r  r   r  r   s    r   test_literal_eval_syntax_errorsz/ASTHelpers_Test.test_literal_eval_syntax_errorsJ  s3    ##K1DE   FEEs   6?c                 H   t        j                  dt        j                  d      gd d d       g}t        j                  |g       }| j	                  t
              5 }t        |dd       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Ntimesleepr   r   r   levelr&   r'   r  r[   zinvalid integer value: None)
r   r   r   r   r:   r}   rf   rS  r   rT  )r   r{   r   rW  s       r   test_bad_integerz ASTHelpers_Test.test_bad_integerQ  s     NNyyg./
 jjr"z*bC( +3S5FG +*s   BB!c                     t        j                  dt        j                  ddd      gd dd      g}t        j                  |g       }t	        |dd      }i }t        ||       | j                  d|       y )Nrf  rg  r   r   ri  r  r[   )r   r   r   r   rf   r[   rS  )r   r{   r   r  nss        r   test_level_as_nonez"ASTHelpers_Test.test_level_as_nonea  sp    NNyygaAFG
 jjr"sFF+T2gr"r   c                 L   t        j                  t        j                         dd      }||_        | j	                  t
              5  t        j                         5  t        t        j                  |      dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wNr   )r7  r&   r'   r   r]   
r   r`  Notoperandr:   r  r   r  rf   ra  r  s     r   test_recursion_directz%ASTHelpers_Test.test_recursion_directq  sm    KK3779Q1=	~.++-q)8V< . /.-- /.s$   B!B=BB	BB#c                    t        j                  t        j                         dd      }t        j                  t        j                         dd      }||_        ||_        | j	                  t
              5  t        j                         5  t        t        j                  |      dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wrp  rq  )r   r  fs      r   test_recursion_indirectz'ASTHelpers_Test.test_recursion_indirectx  s    KK3779Q1=KK3779Q1=		~.++-q)8V< . /.-- /.s$   8C!B?.C?C	CC) rP   r   rQ   r  r  r  r   r  r  r  r  r   r%  r+  r0  r4  r6  r9  r?  rA  rD  rK  rQ  rT  rZ  r^  rb  rd  rk  rn  rt  rw  r5   r   r   r  r    s    G3
:
0D
L
2,"
,@4::

F&;62&229?&LC*CG	#H # ==r   r  c                   
   e Zd ZdGeddZdHeddZdHdZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2 e3jh                  d2      d3        Z5 e6jn                  d4      Z8 e6jr                  e8      Z: e6jn                  d5      Z; e6jr                  e;      Z< e6jn                  d6      Z= e6j|                  d6      Z? e6j                  d7 e6j                               ZB e6jr                   e6j                   e6j                   e6j                  d5 e6j                               d8 e6j                               d9 e6j                                      e6jr                   e6j                   e6j                   e6j                  d5 e6j                               d8 e6j                               d9 e6j                                      e6jr                   e6jn                  d:             e6jr                   e6jn                  d6             e6jr                   e6jn                  d;             e6j|                  d<       e6j                   e6j|                  d<      g       e6j                   e6j                   e6j|                  d<      g      g       e6j                  e8e=ge<g       e6j                  e=e8ge<e:gd=>       e6j                  e= e6j                   e6j                  d? e6j                                e6j                               ge<e:gd@>       e6j                   e6j                   e6j                  e;d8 e6j                               d9 e6j                               g g g A       e6j                  eBg d=ge:gA       e6j                  eBg g e:gA       e6j                  eB e6j|                  d<      gg g A       e6j                  eB e6j                         gg g A       e6j                  eBg g  e6j                         gA       e6j                  e=g d=ge:gA       e6j                   e6j                  d=      g       e6j                  dBC       e6j                  g        e6j                  e:g       e6j                  e:e< e6j|                  dD      g       e6j                  dEC       e6j                  d5C       e6j                   e6j                  dE      g       e6j                  g g dE>      gZLdF ZMy)IASTValidatorTestsNr	  c                   dx|_         |_        t        j                  |       |t	        |d|       y | j                  |      5 }t	        |d|       d d d        | j                  |t        j                               y # 1 sw Y   /xY w)Nr   r   )	r&   r'   r   r[  rf   r:   rS  r   rT  )r   r   rJ   r  r	  rW  s         r   r   zASTValidatorTests.mod  sp    &''
S^!!#&;C4(""3'2Xt, (MM#s2<<01 ('s   BB
c                    t        j                  t        j                  |      gg       }| j                  |||       y )Nrz  )r   r   rR  r   )r   r   rJ   r	  r   s        r   r#   zASTValidatorTests.expr  s/    jj#((4.)2.cs#r   c                 V    t        j                  |gg       }| j                  ||       y rC   )r   r   r   )r   r$   rJ   r   s       r   r$   zASTValidatorTests.stmt  s"    jj$$cr   c           	      d   t        j                  t        j                  t        j                  dt        j                                     g      }| j                  |dd       t        j                  t        j                  dt        j                                     }| j                  |dd       y )Nr?   must have Load contextr\   r]   )r   InteractiverR  r   Storer   ra  )r   rV  s     r   r4  zASTValidatorTests.test_module  sn    OOSXXchhsCIIK&@ABC,h7NN388C56,f5r   c                    	 	 	 	 	 	 	 dfd	}t        j                  dt        j                  dt        j                                     g} | ||      d        | ||      d        | ||      d        | |t        j                  d      g      d	        | |t        j                  d
      g      d       t        j                  dt        j                  dt        j
                                     g} | ||t        j                  dt        j                               g      d       t        j                  dt        j                  dt        j
                                     t        j                  dt        j                  dt        j
                                     g} | ||d t        j                  dt        j                               g      d       y )Nc           	      r    | g } |g }|g }|g }|g }t        j                  | ||||||      }  |       S rC   )r   r   )r   r   r<   r   r   r   r   facs          r   r   z5ASTValidatorTests._check_arguments.<locals>.arguments  sd     |" !
" ==k6:{E8D t9r   r?   ri  r  )r   )r   r   )r   z"more positional defaults than argsr:  )r   z3length of kwonlyargs is not the same as kw_defaults)r   r   rT   r  r   )r   r   )NNNNNNN)r   r  r   r  r   rZ  )r   r  checkr   r   s    `   r   _check_argumentsz"ASTValidatorTests._check_arguments  st   	0 SXXc399;789iT"$<=iD)+CDi4(*BCQ013W	
 	3<<?"34A	
 SXXc388:6784388C+E*FG$	

 GGC#sxxz23GGC#sxxz23
 	D#((3		:T3UV$	
r   c                    t        j                  g g d g g d g       }t        j                  d|g g d d g       }| j                  |d       t        j                  d|t        j                         gt        j
                  dt        j                               gd d g       }| j                  |d       t        j                  d|t        j                         gg t        j
                  dt        j                               d g       }| j                  |d       t        j                  dt        j                         t        j                         g      }| j                  |       d }| j                  || j                         y )Nr?   zempty body on FunctionDefr  c           	      ^    t        j                  d| t        j                         gg d d g       S Nr?   )r   FunctionDefPassri  s    r   r  z+ASTValidatorTests.test_funcdef.<locals>.fac  s%    ??3sxxzlBdBOOr   )r   r   r  r$   r  r   r  r  )r   rT   rv  r  s       r   test_funcdefzASTValidatorTests.test_funcdef  s   MM"b$Bb9OOCBD$;		!01OOSXXZL388C#=">dB
 			!-.OOSXXZL"chhsCIIK&@$
 			!-.OOC388:,?		!	P 	c499-r   c                     d }d}t        j                  t        j                  |            }|j                  d   }| j                  |t         j                         | j                   ||             y )Nc                    | t         j                  dx\  dk(  rt         j                  d x\    r dk(  r\  t         j                  dx\  dk(  r  r dk(  r~\  t         j                  d xi\     rf dk(  ra\  t         j
                  dxL\  dk(  rFt         j                  d x3\   t         j
                  dx\  dk(  rt         j                  d x\   y    	 y	)
Nr5   r   ri  rv   r   capybarapacaranaTF)r   r  r   r  r  r   rZ  )r   s    r   matcherz@ASTValidatorTests.test_funcdef_pattern_matching.<locals>.matcher  sx    __ MM8'7'7 LSXXZ66SXX5j#((*HH4Z  r   zZ
            @capybara
            def foo(bar) -> pacarana:
                pass
        r   )r   ro   textwrapr   r{   r   r  r   )r   r  r  r  funcdefs        r   test_funcdef_pattern_matchingz/ASTValidatorTests.test_funcdef_pattern_matching  sY    	!
 8??401++a.gs7()r   c                    	 d
d}| j                   |t        j                  dt        j                               g      d       | j                   |t        j                  dt        j                  dt        j                                     g      d       | j                   |g       d       | j                   |d g      d       | j                   |t        j                  dt        j                               g	      d       y )Nc                     | g } |g }|t        j                         g}|g }|g }t        j                  d| ||||      S )Nmyclass)r   r  ClassDef)basesr  r{   r!   type_paramss        r   clsz,ASTValidatorTests.test_classdef.<locals>.cls  s_     }|
|%!#" <<5(D.+ r   r?   )r  r  )r  r^  zempty body on ClassDefNone disallowed)r!   )NNNNN)r$   r   r   r  r  )r   r  s     r   test_classdefzASTValidatorTests.test_classdef  s    SW	" 			#SXXc399;789;ST		#++c388C+EFGH$	
 			#2, 89		#D6"$56		ciik :;<>V	
r   c           	      2   | j                  t        j                  g       d       | j                  t        j                  d g      d       | j                  t        j                  t        j                  dt        j                               g      d       y )Nzempty targets on Deleter  r?   zmust have Del context)r$   r   Deleter   rZ  r   s    r   test_deletezASTValidatorTests.test_delete  s_    		#**R.";<		#**dV$&78		#**chhsCHHJ789;RSr   c           
         | j                  t        j                  g t        j                  d            d       | j                  t        j                  d gt        j                  d            d       | j                  t        j                  t        j                  dt        j
                               gt        j                  d            d       | j                  t        j                  t        j                  dt        j                               gt        j                  dt        j                                     d       y )Nr   zempty targets on Assignr  r?   must have Store contextr   r  )r$   r   Assignr   r   rZ  r  r   s    r   test_assignzASTValidatorTests.test_assign  s    		#**Ra13LM		#**dVS\\!_57HI		JJchhj12CLLOD%	
 			JJciik23SXXc399;5OP$	
r   c           	          t        j                  t        j                  dt        j                               t        j                         t        j                  dt        j                                     }| j                  |d       t        j                  t        j                  dt        j                               t        j                         t        j                  dt        j                                     }| j                  |d       y )Nr?   r   r  r  )r   	AugAssignr   rZ  r=  r$   r  )r   augs     r   test_augassignz ASTValidatorTests.test_augassign(  s    mmHHS#((*%swwy#((3
2K
 			#01mmHHS#))+&	388C3M
 			#/0r   c           
      t   t        j                  dt        j                               }t        j                  dt        j                               }t        j                         }| j                  t        j                  ||g g       d       | j                  t        j                  t        j                  dt        j                               ||gg       d       | j                  t        j                  |t        j                  dt        j                               |gg       d       t        j                  t        j                  dt        j                                     }| j                  t        j                  |||gg       d       | j                  t        j                  |||g|g      d       y )Nr?   r   zempty body on Forr  r  )r   r   r  rZ  r  r$   r   rR  )r   r?   r   pr  s        r   test_forzASTValidatorTests.test_for2  s$   HHS#))+&HHS#((*%HHJ		#''!QB')<=		GGCHHS#((*-q1#r:<U	
 			GGAsxxSYY[1A3;=U	
 HHSXXc399;/0		#''!QR(*BC		#''!QaS)+CDr   c                 F   | j                  t        j                  t        j                  d      g g       d       | j                  t        j                  t        j                  dt        j
                               t        j                         gg       d       | j                  t        j                  t        j                  d      t        j                         gt        j                  t        j                  dt        j
                                     g      d       y )Nr   zempty body on Whiler?   r  )r$   r   Whiler   r   r  r  rR  r   s    r   
test_whilezASTValidatorTests.test_whileA  s    		#))CLLOR46KL		IIchhsCIIK0388:,C$	
 			IIQ#((*#syy{9S0T/U %		
r   c                 :   | j                  t        j                  t        j                  d      g g       d       t        j                  t        j                  dt        j
                               t        j                         gg       }| j                  |d       t        j                  t        j                  d      t        j                  t        j                  dt        j
                                     gg       }| j                  |d       t        j                  t        j                  d      t        j                         gt        j                  t        j                  dt        j
                                     g      }| j                  |d       y )Nr   zempty body on Ifr?   r  )r$   r   Ifr   r   r  r  rR  )r   ri   s     r   test_ifzASTValidatorTests.test_ifN  s    		#&&a"b13EFFF388C-
|R@		!-.FF3<<?SXXchhsCIIK.H%I$JBO		!-.FFLLOchhj\CHHSXXc399;5O,P+Q
 			!-.r   c                    t        j                         }| j                  t        j                  g |g      d       t        j                  t        j
                  d      d       }| j                  t        j                  |gg       d       t        j                  t        j                  dt        j                               d       }| j                  t        j                  |g|g      d       t        j                  t        j
                  d      t        j                  dt        j                                     }| j                  t        j                  |g|g      d       y )Nzempty items on Withr   zempty body on Withr?   r  r  )	r   r  r$   Withrz  r   r   r  rZ  )r   r  ri   s      r   	test_withzASTValidatorTests.test_withY  s    HHJ		#((2s#%:;LLa$/		#((A3#%9:LL#syy{3T:		#((A3$&>?LLa#((3
*CD		#((A3$&?@r   c                    t        j                  d t        j                  d            }| j                  |d       t        j                  t        j                  dt        j
                               d       }| j                  |d       t        j                  t        j                  d      t        j                  dt        j
                                     }| j                  |d       y )Nr   z!Raise with cause but no exceptionr?   r  r:  )r   r  r   r$   r   r  )r   rs     r   
test_raisezASTValidatorTests.test_raisec  s    IIdCLLO,		!89IIchhsCIIK0$7		!-.IIcll1osxxSYY['AB		!-.r   c                    t        j                         }t        j                  g g g |g      }| j                  |d       t        j                  t        j                  t        j
                  dt        j                                     gg g |g      }| j                  |d       t        j                  |gg g g       }| j                  |d       t        j                  |gg |g|g      }| j                  |d       t        j                  |gt        j                  d dg       gg g       }| j                  |d       t        j                  t        j
                  dt        j                               d|g      g}| j                  t        j                  |g|g g       d       t        j                  d d|g      g}t        j                  |g|t        j                  t        j
                  dt        j                                     g|g      }| j                  |d       t        j                  |g||gt        j                  t        j
                  dt        j                                     g      }| j                  |d       y )Nzempty body on Tryr?   r  z-Try has neither except handlers nor finalbodyz%Try has orelse but no except handlersempty body on ExceptHandlerr   )r   r  Tryr$   rR  r   r  ExceptHandlerr   r  tr  s       r   test_tryzASTValidatorTests.test_tryk  s   HHJGGBB$		!()GGSXXchhsCIIK89:BQCH		!-.GGQCR$		!DEGGQCaS1#&		!<=GGQC#++D#r:;RD		!23sxxSYY[93DE		#''1#q"b)+CDtS1#./GGQCSXXchhsCIIK&@ABQCH		!-.GGQCQC#((388C+E"F!GH		!-.r   c                    t        j                         }t        j                  g g g |g      }| j                  |d       t        j                  t        j                  t        j
                  dt        j                                     gg g |g      }| j                  |d       t        j                  |gg g g       }| j                  |d       t        j                  |gg |g|g      }| j                  |d       t        j                  |gt        j                  d dg       gg g       }| j                  |d       t        j                  t        j
                  dt        j                               d|g      g}| j                  t        j                  |g|g g       d       t        j                  d d|g      g}t        j                  |g|t        j                  t        j
                  dt        j                                     g|g      }| j                  |d       t        j                  |g||gt        j                  t        j
                  dt        j                                     g      }| j                  |d       y )Nzempty body on TryStarr?   r  z1TryStar has neither except handlers nor finalbodyz)TryStar has orelse but no except handlersr  r   )r   r  TryStarr$   rR  r   r  r  r  s       r   test_try_starzASTValidatorTests.test_try_star  s   HHJKKBQC(		!,-KK#((3		"<=>BL		!-.KKRR(		!HIKKR!qc*		!@AKKc//c2>?RH		!23sxxSYY[93DE		#++qc1b"-/GHtS1#./KKQ#((3		*D!E FL		!-.KKQchhsxxSYY[/I&J%KL		!-.r   c           	         | j                  t        j                  t        j                  dt        j                               d       d       t        j                  t        j                  dt        j
                               t        j                  dt        j                                     }| j                  |d       y )Nr?   r  r   )r$   r   Assertr   r  rZ  )r   assrts     r   test_assertzASTValidatorTests.test_assert  ss    		JJsxxSYY[148:R	
 

388C4chhsCIIK6PQ		%12r   c                 N    | j                  t        j                  g       d       y )Nzempty names on Import)r$   r   r   r   s    r   test_importzASTValidatorTests.test_import      		#**R."9:r   c                     t        j                  d t        j                  dd       gd      }| j                  |d       | j                  t        j                  d g d      d       y )Nr?   izNegative ImportFrom levelr   zempty names on ImportFrom)r   r   r   r$   )r   imps     r   test_importfromz!ASTValidatorTests.test_importfrom  sM    nnTCIIc4$8#93?		#23		#..r1-/JKr   c                 N    | j                  t        j                  g       d       y )Nzempty names on Global)r$   r   Globalr   s    r   test_globalzASTValidatorTests.test_global  r  r   c                 N    | j                  t        j                  g       d       y )Nzempty names on Nonlocal)r$   r   Nonlocalr   s    r   test_nonlocalzASTValidatorTests.test_nonlocal  s    		#,,r"$=>r   c                     t        j                  t        j                  dt        j                                     }| j	                  |d       y Nr?   r  )r   rR  r   r  r$   r  s     r   	test_exprzASTValidatorTests.test_expr  s0    HHSXXc399;/0		!-.r   c           	         t        j                  t        j                         g       }| j                  |d       t        j                  t        j                         t        j                  d      g      }| j                  |d       t        j                  t        j                         t        j                  d      d g      }| j                  |d       t        j                  t        j                         t        j                  d      t        j
                  dt        j                               g      }| j                  |d       y )Nzless than 2 valuesr   r:  r  r?   r  )r   BoolOpAndr#   r   r   r  )r   r  s     r   test_boolopzASTValidatorTests.test_boolop  s    JJswwy"%		!)*JJswwy3<<?"34		!)*JJswwy3<<?D"9:		!&'JJswwy3<<?CHHS#))+4N"OP		!-.r   c                     t        j                  t        j                         t        j                  dt        j                                     }| j                  |d       y r  )r   r`  rr  r   r  r#   )r   us     r   test_unaryopzASTValidatorTests.test_unaryop  s8    KK	388C#=>		!-.r   c           
         t        j                  g g d g g d g       }| j                  t        j                  |t        j                  dt        j
                                     d       d }| j                  || j                         y )Nr?   r  c                 z    t        j                  | t        j                  dt        j                                     S r  )r   Lambdar   rZ  ri  s    r   r  z*ASTValidatorTests.test_lambda.<locals>.fac  s$    ::dCHHS#((*$=>>r   )r   r   r#   r  r   r  r  )r   rT   r  s      r   test_lambdazASTValidatorTests.test_lambda  sb    MM"b$Bb9		#**Qciik :;=UV	? 	c499-r   c                    t        j                  dt        j                               }t        j                  dt        j                               }|||f|||f|||ffD ]$  }| j	                  t        j
                  | d       & y Nr?   r   r  )r   r   rZ  r  r#   IfExp)r   lr   r   s       r   
test_ifexpzASTValidatorTests.test_ifexp  si    HHS#((*%HHS#))+&1I1ay1a)3DIIcii&(@A 4r   c                 B   t        j                  g t        j                  dt        j                               g      }| j	                  |d       t        j                  t        j                  dt        j                               gd g      }| j	                  |d       y )Nr?   zsame number of keys as valuesr  )r   rX  r   rZ  r#   )r   r*  s     r   	test_dictzASTValidatorTests.test_dict  sj    HHR#((3
345		!45HHchhsCHHJ/04&9		!&'r   c                     | j                  t        j                  d g      d       t        j                  t        j                  dt        j                               g      }| j                  |d       y Nr  r?   r  )r#   r   Setr   r  r   r   s     r   test_setzASTValidatorTests.test_set  sL    		#''4&/#45GGSXXc399;/01		!-.r   c           	         | j                   |g       d       t        j                  t        j                  dt        j                               t        j                  dt        j                               g d      }| j                   ||g      d       t        j                  t        j                  dt        j
                               t        j                  dt        j
                               g d      }| j                   ||g      d       t        j                  dt        j
                               }t        j                  dt        j                               }t        j                  ||d gd      }| j                   ||g      d       t        j                  ||t        j                  dt        j
                               gd      }| j                   ||g      d       y )Nz comprehension with no generatorsr?   r   r  r  r   r  )r#   r   r   r   rZ  r  )r   r  gr?   r   s        r   _check_comprehensionz&ASTValidatorTests._check_comprehension  sQ   		#b'=>HHS#((*%sxxSXXZ'@"a
 			#qc(56HHS#))+&ciik(BB
 			#qc(45HHS#))+&HHS#((*%aTFA.		#qc(-.aSXXc399;%?$@!D		#qc(45r   c           	      z   t        j                  t        j                  dt        j                               t        j                  dt        j                               g d      }| j                   t        j                  dt        j                               |g      d       fd}| j                  |       y )Nr?   r   r  c                 b     t        j                  dt        j                               |       S r  )r   r   r  )gensr  s    r   wrapz,ASTValidatorTests._simple_comp.<locals>.wrap  s!    sxxSYY[1488r   )r   r   r   r  rZ  r#   r  )r   r  r  r  s    `  r   _simple_compzASTValidatorTests._simple_comp  s~    HHS#))+&chhj(A2q
 			#chhsCIIK01#68PQ	9 	!!$'r   c                 B    | j                  t        j                         y rC   )r  r   ListCompr   s    r   test_listcompzASTValidatorTests.test_listcomp  s    #,,'r   c                 B    | j                  t        j                         y rC   )r  r   SetCompr   s    r   test_setcompzASTValidatorTests.test_setcomp  s    #++&r   c                 B    | j                  t        j                         y rC   )r  r   GeneratorExpr   s    r   test_generatorexpz#ASTValidatorTests.test_generatorexp  s    #**+r   c                    t        j                  t        j                  dt        j                               t        j                  dt        j                               g d      }t        j
                  t        j                  dt        j                               t        j                  dt        j                               |g      }| j                  |d       t        j
                  t        j                  dt        j                               t        j                  dt        j                               |g      }| j                  |d       d }| j                  |       y )Nr   r  r   r?   r  c                     t        j                  dt        j                               }t        j                  dt        j                               }t        j                  |||       S )Nr?   r   )r   r   rZ  DictComp)compskvs      r   factoryz0ASTValidatorTests.test_dictcomp.<locals>.factory  sA    chhj)Achhj)A<<1e,,r   )r   r   r   r  rZ  r  r#   r  )r   r  cr  s       r   test_dictcompzASTValidatorTests.test_dictcomp  s    HHS#))+&chhj(A2q
 LL#syy{3SXXc388:5NQRPST		!-.LL#sxxz2CHHS#))+4NQRPST		!-.	-
 	!!'*r   c           	      0   | j                  t        j                  t        j                  dt        j                                     d       | j                  t        j
                  t        j                  dt        j                                     d       y )Nr?   zmust have Load)r#   r   Yieldr   r  	YieldFromr   s    r   
test_yieldzASTValidatorTests.test_yield	  sT    		#))CHHS#))+679IJ		#--ciik :;=MNr   c                    t        j                  dt        j                               }t        j                  |t        j                         gg       }| j                  |d       t        j                  |t        j                         gt        j                  d      t        j                  d      g      }| j                  |d       t        j                  t        j                  d      t        j                         g|g      }| j                  |       t        j                  |t        j                         gt        j                  d      g      }| j                  |       y )Nr?   zno comparatorsr:  r9  z,different number of comparators and operandsblah)r   r   rZ  CompareInr#   r   )r   r6  comps      r   test_comparezASTValidatorTests.test_compare  s    xxSXXZ({{4#&&(R0		$(){{4#&&(cll1os||A-OP		$FG{{3<</#&&(dVD		${{4#&&(cll6.B-CD		$r   c                    t        j                  dt        j                               }t        j                  dt        j                               g}t        j                  dt        j                  dt        j                                     g}t        j                  t        j                  dt        j
                               ||      }| j                  |d       t        j                  |d g|      }| j                  |d       t        j                  dt        j                  dt        j
                                     g}t        j                  |||      }| j                  |d       y )Nr?   r   r   r   r  r  )r   r   rZ  r  r  r  r#   )r   r  r   r  callbad_keywordss         r   	test_callzASTValidatorTests.test_call  s    xxSXXZ(chhj)*KKSXXc388:%>?@xxciik2D(C		$01xxtfh/		$)*C#syy{)CDExxdL1		$01r   c                    t        j                  d      5 }t        j                  ddt               ddlm} d d d        t        j                  d      5 }t        j                  ddt                G d d	t              } G d
 dt              } G d dt              }dD ]&  }| j                  t	        j
                  |             (  |        |        |       fD ]-  }| j                  t	        j
                  |      dt               / 	 d d d        | j                  D cg c]  }t        |j                         c}g d       y # 1 sw Y   xY w# 1 sw Y   LxY wc c}w )NTr   r   r   r   r  r   c                       e Zd Zy)*ASTValidatorTests.test_num.<locals>.subintNrO   r5   r   r   subintr  ,  r)  r   r  c                       e Zd Zy),ASTValidatorTests.test_num.<locals>.subfloatNrO   r5   r   r   subfloatr  /  r)  r   r  c                       e Zd Zy).ASTValidatorTests.test_num.<locals>.subcomplexNrO   r5   r   r   
subcomplexr  2  r)  r   r  )0hellozinvalid typerz  )r   r   r   r   r   )r   r   r   r   r   r   r_  floatcomplexr#   r=   r,   r   r   )r   r   r   r  r  r  objr   s           r   test_numzASTValidatorTests.test_num$  s   $$D1T##Hb2DE 2 $$D1T##Hb2DE 5 W  $		#''#,' $xZ\9		#''#,I	F : 2" 	%)*TS^T*		
+ 21 21$ +s   "EB8E'E'EE$c                     t        j                  t        j                  dt        j                               dt        j                               }| j                  |d       y r  )r   	Attributer   r  rZ  r#   )r   r  s     r   test_attributez ASTValidatorTests.test_attributeE  s:    }}SXXc399;7chhjI		$01r   c           	         t        j                  t        j                  dt        j                               t        j                  d      t        j
                               }| j                  |d       t        j                  dt        j
                               }t        j                  |t        j                  dt        j                               t        j
                               }| j                  |d       t        j                  dt        j                               }|d d fd |d fd d |ffD ]M  }t        j                  | }| j                  t        j                  ||t        j
                               d       O t        j                  g t        j
                               }| j                  t        j                  ||t        j
                                      t        j                  |gt        j
                               }| j                  t        j                  ||t        j
                               d       y )Nr?   r   r  r   )	r   	Subscriptr   r  r   rZ  r#   SliceTuple)r   subr?   r   r   sls         r   test_subscriptz ASTValidatorTests.test_subscriptI  sk   mmCHHS#))+6QT		#/0HHS#((*%mmAsxxSYY[9388:F		#/0HHS#))+&dOdAt_tT1oEDD!BIIcmmAr388:68PQ F YYr388:&		#--2sxxz23YYsCHHJ'		#--2sxxz24LMr   c           	      f   t        j                  t        j                  t        j                  dt        j                               t        j
                               gt        j
                               }t        j                  |gt        j                  d            }| j                  |d       y )Nr?   r:  r  )	r   ListStarredr   rZ  r  r  r   r$   )r   r6  assigns      r   test_starredzASTValidatorTests.test_starredX  sk    xx[[#sxxz2CIIK@A399;
 TFCLLO4		&34r   c           	          | j                   |d gt        j                               d       | j                   |t        j                  dt        j                               gt        j                               d       y r  )r#   r   rZ  r   r  )r   r  s     r   	_sequencezASTValidatorTests._sequence_  sS    		#tfchhj)+<=		#syy{+,chhj9;S	
r   c                 B    | j                  t        j                         y rC   )r4  r   r/  r   s    r   	test_listzASTValidatorTests.test_liste  s    sxx r   c                 B    | j                  t        j                         y rC   )r4  r   r*  r   s    r   
test_tuplezASTValidatorTests.test_tupleh  s    syy!r   c                    t        j                  d      5 }t        j                  ddt               ddlm} d d d        t        j                  d      5 }t        j                  ddt               | j                  t	        j
                  d             d d d        | j                  D cg c]  }t        |j                         c}d	g       y # 1 sw Y   xY w# 1 sw Y   JxY wc c}w )
NTr   r   r   r   )r   r   r:  r   )
r   r   r   r   r   r   r#   r,   r   r   )r   r   r   r   s       r   test_nameconstantz#ASTValidatorTests.test_nameconstantk  s    $$D1T##Hb2DE( 2 $$D1T##Hb2DEIIc&&q)* 2 	%)*TS^T*m	
 21 21
 +s   "CA C .C,C C)cpuc                 <   t         j                  j                  t        j                        }t        j
                  |      D cg c]  }|j                  d      s| }}|j                  ddg       |D ]  }| j                  |      5  t         j                  j                  ||      }t        |dd      5 }|j                         }d d d        t        j                  |      }t        ||d       d d d         y c c}w # 1 sw Y   <xY w# 1 sw Y   xY w)Nz.pyztest/test_grammar.pyztest/test_unpack_ex.pyr  utf-8encodingr[   )ospathdirnamer   __file__listdirendswithextendre   joinopenreadro   rf   )r   stdlibfnr  r   fpr  r   s           r   test_stdlib_validatesz'ASTValidatorTests.test_stdlib_validates{  s    . jj0G0BKK4F0G,.FGHFf%WW\\&&1"cG4WWYF 5ii+R( &%  H
 54 &%s0   DD/D:D+DDDD	rv   r?   Tcarterr   r   .rF  stringr  )restlollegit)patterns	kwd_attrskwd_patternsr  rh  xxx_c           
      2   t        j                  dt        j                               }| j                  D ]  }| j	                  t        j
                  |d            5  t        j                  |t        j                  |t        j                         g      g      }t        j                  |      }t        j                  |gg       }| j                  t              5  t        |dd       d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Nr?   r:  r  )r  r{   )subjectcasesr   r[   )r   r   rZ  _MATCH_PATTERNSre   r  Matchr  r  r[  r   r:   r}   rf   )r   name_xr  r   r   s        r   test_match_validation_patternz/ASTValidatorTests.test_match_validation_pattern  s    #sxxz*++Gchhwq9:yy">>'MN 006TFB/&&z2FHf5 3 ;: , 32 ;:s%   BD D.DD
DD	)Nr[   rC   )NrP   r   rQ   r}   r   r#   r$   r4  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-  r2  r4  r6  r8  r:  r   requires_resourcerM  r   r   
constant_1
MatchValue	pattern_1
constant_x	pattern_xconstant_trueMatchSingletonpattern_truer   rZ  name_carterr%  r  MatchSequenceMatchMappingr0  
MatchClass	MatchStarMatchAsMatchOrr[  r^  r5   r   r   ry  ry    ss   2Z 2$* $60
d.(*2
:T


1E
	/A//(/(3;L
;?///.B(/
6"	((',+ O	
2
B2N5
!"
  Wu%
) &
) aJz*Ic"Jz*I CLL&M%3%%d+L#((8XSXXZ0K 	CMMhchhsICIIK8#xsxxzJ
	
 	CMMhchhsHCHHJ7iciikJ
	
 	|s||C()|s||D)*|s||I./8$-3--h789,3,,.@c.@.@.J-KLMN*m4ykBJ')Y)?f	
 	KCKK
(CXSXXZPQ	"	

 	CMM-#--
CDc8388:V		
 	"	{	
 	")	
 	(c((23		
 	=3==?"3rPR	
 	"-#--/AR	
 	h#		
 	=3==012!BYK Y	+=3+=+=e+DEF3=3==-./Rc*IEON6r   ry  c                   j    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
ej                  d	        Zd
 Zd Zy)ConstantTestsz$Tests on the ast.Constant node type.c                    t        j                  d      }|j                  d   j                  }t        j                  |      }t        j
                  ||       ||j                  d   _        t        |dd      }i }t        ||       |d   S )Nzx = 123r   r  rn   r[   r?   )r   ro   r{   r1   r   r  rf   r[   )r   r1   rr   r   new_noder  rm  s          r   compile_constantzConstantTests.compile_constant  sv    yy#yy|!!<<e,(D)%		!tZ0T2#wr   c                     | j                  t              5 }| j                  g d       d d d        | j                  t	        j
                        d       y # 1 sw Y   /xY w)NrF  z%got an invalid type in Constant: list)r:   r=   rs  r,   r   rT  )r   rW  s     r   test_validationzConstantTests.test_validation  sH    y)R!!), *R\\*,ST *)s   AA!c                     d ddt         dt               fD ]@  }| j                  |      5  | j                  |      }| j	                  ||       d d d        B y # 1 sw Y   MxY w)NFTr   )const)r   r`  re   rs  r   )r   rw  r1   s      r   test_singletonszConstantTests.test_singletons  sW    E43	DEE*--e4eU+ +* E**s   $AA"	c           	      >   d}t        dh      }t        d      D ]  }|df}t        |dh      } ddddd	t        d
      t        d      ||f	}|D ]@  }| j                  |      5  | j	                  |      }| j                  ||       d d d        B y # 1 sw Y   MxY w)N)rv   rv   r   r8   rF   g     ^@y             ^@unicode   bytesr   r`  r  )r`  r   r   re   rs  r,   )r   nested_tuplenested_frozensetrj  rW  r1   results          r   test_valueszConstantTests.test_values  s    $aS>1XE(!,L(*:A)>?  'Nk"

 EE*..u5  / +* **s   $$BB	c                    t        j                  d      }|j                  d   j                  d   }t        j                  d      }t        j
                  ||       ||j                  d   j                  d<   | j                  t              5 }t        |dd       d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nx = 1r   rv   r  rO  r[   z6expression which can't be assigned to in Store context)r   ro   r{   targetsr   r  r:   r}   rf   r,   r   rT  )r   rr   r  
new_targetrW  s        r   test_assign_to_constantz%ConstantTests.test_assign_to_constant  s    yy!1%%a(\\*
*f-",		!Qz*bD(F+ +G	
 +*s   CCc                 x    t        j                  d      }| j                  t        j                  |      d       y )Nz'docstring'
x = 1	docstring)r   ro   r,   r3  r   s     r   r4  z ConstantTests.test_get_docstring)  s,    yy-.**40+>r   c                     t        |dd      }g }t        j                  |      D ]<  }|j                  dk(  s|j                  dk(  s"|j	                  |j
                         > |S )Nrn   r[   
LOAD_CONSTRETURN_CONST)rf   disget_instructionsopnamer  argval)r   rr   coconstsinstrs        r   get_load_constzConstantTests.get_load_const-  sZ     T:v.))"-E|||+u||~/Mell+ . r   c                    g d}dj                  |D cg c]  }dj                  |       c}      }|dz  }|j                  t        d f       t	        j
                  |      }| j                  | j                  |      |       t        |j                  |      D ]B  \  }}t	        j                  |      }t	        j                  ||j                         ||_        D | j                  | j                  |      |       y c c}w )N)	NTF|   g       @y              @rz  r{  rF  ry  zx={!r}z
x = ...r  )rG  r   rF  r   r   ro   r,   r  rd   r{   r   r  r1   )r   r  rw  r  rr   r1  rr  s          r   test_load_constzConstantTests.test_load_const7  s    RyyfEfU(//%0fEFx&'yy,,T2F; !F3MFE||%0Hh5#FL	 4 	,,T2F; Fs   Dc                    t        j                  d      }|j                  d   j                  }t        j                  d      }t        j
                  ||j                         ||_        t        j                  d      }t        j
                  ||j                         ||_        | j                  t        j                  |      d       y )Nz1 + 2r   ru   r  y              4@y      $@      4@)
r   ro   r{   r1   r   r  r6  r8  r,   r  )r   rr   binopnew_left	new_rights        r   rK  zConstantTests.test_literal_evalK  s    yy!		!""<<b)(EJJ/
LLs+	)U[[1))%0(;r   c                    t        j                  dd      j                  }| j                  |j                  d       | j                  |j
                  d        t        j                  dd      j                  }| j                  |j                  d       | j                  |j
                  d       t        j                  dd      j                  }| j                  |j                  d       | j                  |j
                  d        t        j                  dd      j                  }| j                  |j                  d	       | j                  |j
                  d        y )
Nz"x"r]   r  r?   zu"x"r  zr"x"zb"x"   x)r   ro   r{   r,   r1   rc   )r   r  s     r   test_string_kindzConstantTests.test_string_kindY  s    IIe&)..#&&IIf6*//#&%IIf6*//#&&IIf6*//$'&r   N)rP   r   rQ   r{  rs  ru  rx  r  r  r4  r  r   r  r  rK  r  r5   r   r   rp  rp    sM    .U
,0,
? < <&<'r   rp  c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"y!)"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                 t    | j                  |j                  |       | j                  |j                  |       y rC   )r,   r|   r~   )r   r.   r|   r~   s       r   _check_end_poszEndPositionTests._check_end_posr  s.    ,,j900.Ar   c                 P    | j                  t        j                  ||      |       y rC   )r,   r   get_source_segment)r   r  r.   contents       r   _check_contentzEndPositionTests._check_contentv  s    //A7Kr   c                 Z    t        j                  |      j                  d   j                  S )Nr   )r   ro   r{   r1   r  s     r   _parse_valuezEndPositionTests._parse_valuey  s#     yy|  #)))r   c                    d}| j                  |      }| j                  ||j                  d       | j                  ||j                  j                  d   d       | j                  ||j                  j                  d       y )Nzlambda x, *y: Noner  r   r?   r   )r  r  r{   r   r<   )r   r   lams      r   r  zEndPositionTests.test_lambda~  sf     "Asxx0Asxx}}Q/5Asxx4r   c                 L   t        d      j                         }t        j                  |      j                  d   }| j                  |dd       | j                  ||j                  d   d       | j                  ||j                  j                  d   d       | j                  ||j                  j                  d   j                  d       | j                  ||j                  j                  d       | j                  ||j                  j                  j                  d	       y )
Nz
            def func(x: int,
                     *args: str,
                     z: float = 0,
                     **kwargs: Any) -> bool:
                return True
            r   r9     zreturn Truezx: intr_  zkwargs: AnyAny)
r   r   r   ro   r{   r  r  r   
annotationr   r   r   fdefs      r   test_func_defzEndPositionTests.test_func_def  s        	
 yy|  #D!R(Atyy|];Atyy~~a0(;Atyy~~a0;;UCAtyy>Atyy995Ar   c                    d}| j                  |      }| j                  ||j                  d       | j                  ||j                  d   j                  d       | j                  ||j                  d   j                  d       y )Nzfunc(x, y=2, **kw)r  r   2rv   kw)r  r  r  r  r1   r   r   r  s      r   r  zEndPositionTests.test_call  so       #Atyy&1At}}Q/55s;At}}Q/55t<r   c                     d}| j                  |      }| j                  ||j                  d       | j                  |dd       y )Nzx[0]()zx[0]rv   rH  )r  r  r  r  r  s      r   test_call_noargsz!EndPositionTests.test_call_noargs  s?      #Atyy&1D!Q'r   c                     t        d      j                         }t        j                  |      j                  d   }| j                  |dd       | j                  ||j                  d   d       | j                  ||j                  d   d       y )Nz?
            class C(A, B):
                x: int = 0
        r   r8      rv   Bz
x: int = 0)r   r   r   ro   r{   r  r  r  r   r   cdefs      r   test_class_defzEndPositionTests.test_class_def  s}       UW 	
 yy|  #D!R(Atzz!}c2Atyy|\:r   c                     d}t        j                  |      j                  d   }| j                  ||j                  d   j
                  d       y )Nz$class S(metaclass=abc.ABCMeta): passr   zabc.ABCMeta)r   ro   r{   r  r  r1   r  s      r   test_class_kwzEndPositionTests.test_class_kw  s@    2yy|  #At}}Q/55}Er   c                     t        d      j                         }t        j                  |      j                  d   }| j                  |dd       | j                  |j                  dd       y )Nzh
            x = """Some multi-line text.

            It goes on starting from same indent."""
        r   r   (   r   r   r   ro   r{   r  r1   r   r   r1  s      r   test_multi_line_strz$EndPositionTests.test_multi_line_str  s_       UW	 	

 1""1%FAr*FLL!R0r   c                     t        d      j                         }t        j                  |      j                  d   }| j                  |dd       | j                  |j                  dd       y )NzB
            x = "first part" \
            "second part"
        r   r8   r8  r  r  s      r   test_continued_strz#EndPositionTests.test_continued_str  s_       UW 	
 1""1%FAr*FLL!R0r   c                 P   t        d      j                         }t        j                  |      }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }| j                  |dd       | j                  |dd	       | j                  |d	d
       | j                  |dd       | j                  |dd       | j                  ||j                  d       | j                  ||j                  d   d       | j                  ||j                  d   j                  d       | j                  ||j                  d       | j                  ||j                  d   d       | j                  ||j                  d   j                  d       y )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   rv   r8   r   r:  r   r#     r  r      r  zx = Nonezother()x, yzraise RuntimeErrorr=   )r   r   r   ro   r{   r  r  r  r<  r  handlersr   )r   r   r   
while_loopif_stmtfor_looptry_stmt	pass_stmts           r   test_suiteszEndPositionTests.test_suites  so      ( UW) 	
* iilXXa[
((1+88A;88A;HHQK	J1-GQ+Hb"-Hb!,Ir1-Az7Aw||A
;Aw~~a055yAAx7Ax}}Q/1EFAx00388+Fr   c                     d}| j                  |      }|j                  d   j                  }| j                  ||d       y )Nzx = f"abc {x + y} abc"rv   zx + y)r  rW  r1   r  r   r   fstrr  s       r   test_fstringzEndPositionTests.test_fstring  s<    $  #A$$Aug.r   c                 $   t        d      j                         }| j                  |      }|j                  d   j                  }| j                  |dd       | j                  ||j                  d       | j                  ||j                  d       y )Nz
            f"""Some multi-line text.
            {
            arg_one
            +
            arg_two
            }
            It goes on..."""
        rv   r9  r   arg_onearg_two)	r   r   r  rW  r1   r  r  r6  r8  r  s       r   test_fstring_multi_linez(EndPositionTests.test_fstring_multi_line  s       UW 	
   #A$$E1a(Auzz95Au{{I6r   c                     t        d      j                         }t        j                  |      j                  d   }| j                  |dd       | j                  |j                  d   dd       y )NzT
            from x.y.z import (
                a, b, c as c
            )
        r   r   rv   r8   r   )r   r   r   ro   r{   r  r   )r   r   r  s      r   test_import_from_multi_linez,EndPositionTests.test_import_from_multi_line	  sc       UW	 	

 iil"CA&CIIaL!R0r   c                    d}d}t        d      j                         }t        | j                  |||f      \  }}}| j	                  ||j
                  d       | j	                  ||j
                  j                  d       | j	                  ||j                  j                  d       | j	                  ||j                  j                  d       | j	                  ||j                  j                  d   j                  d	       | j	                  ||j                  j                  d
   j                  d       | j                  |dd       y )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, 2za.bzc.dr   f ()rv   g ()r   )r   r   mapr  r  r1   r   r   r   eltsr  )r   s1s2smi1i2r   s          r   test_sliceszEndPositionTests.test_slices	  s      UW	 	
 **RRL9
BB+6B7B6B6Ba 0 6 6?Ba 0 6 6?B1%r   c                 @   t        d      j                         }| j                  |      }| j                  |dd       | j	                  ||j
                  d       | j	                  ||j                  d       | j	                  ||j                  j
                  d       y )NzF
            (1 * 2 + (3 ) +
                 4
            )
        r8   rH  4z1 * 2 + (3 )3)r   r   r  r  r  r8  r6  )r   r   r  s      r   
test_binopzEndPositionTests.test_binop!	  s       UW	 	

 !!!$E1a(Au{{C0Auzz>:Auzz//5r   c                     t        d      j                         }t        j                  |      j                  d   j
                  }| j                  |dd       | j                  ||j                  d   d       y )Nz{
            if (one_condition and
                    (other_condition or yet_another_one)):
                pass
        r   r8   ,   rv   z"other_condition or yet_another_one)	r   r   r   ro   r{   r  r  r  rW  )r   r   bops      r   r  zEndPositionTests.test_boolop-	  sj       UW	 	

 iil"''CB'Aszz!}.RSr   c                    d}d}d}t        d      j                         }t        | j                  ||||f      \  }}}}| j	                  ||d       | j	                  ||d       | j	                  ||d       | j                  |dd	       y )
Nzx = () ;z	x = 1 , ;zx = (1 , 2 ) ;z?
            x = (
                a, b,
            )
        r  z1 ,z(1 , 2 )r   rv   )r   r   r  r  r  r  )	r   r  r  s3r  t1t2t3tms	            r   test_tupleszEndPositionTests.test_tuples7	  s       UW	 	
 T..RR0@ABBBD)BE*BJ/B1%r   c                     d}| j                  |      }| j                  |||       | j                  ||j                  d   d       y )Nzfunc(x. y .z)r   zx. y .z)r  r  r   r  s      r   test_attribute_spacesz&EndPositionTests.test_attribute_spacesF	  sC      #AtQ'Atyy|Y7r   c                    d}t        j                  |      j                  d   j                  }| j	                  t        |      j                  d       | j                  ||d       d|z   }t        j                  |      j                  d   j                  j                  }| j	                  t        |      j                  d       | j                  ||d       y )Nz( ( ( a + b ) ) )r   r<  za + bawait )r   ro   r{   r1   r,   r   rP   r  )r   r   r  r  s       r   test_redundant_parenthesisz+EndPositionTests.test_redundant_parenthesisL	  s    IIaLa &&a))73Aq'*\IIbMq!''--a))73B7+r   c                    d}|D ]  \  }}| j                  |      5  t        j                  |      j                  d   j                  }| j                  t        |      j                  |       | j                  |||       d|z   }t        j                  |      j                  d   j                  j                  }| j                  t        |      j                  |       | j                  |||       d d d         y # 1 sw Y   xY w)N))z( ( ( a ) ) ) ( )r  )z( ( ( a ) ) ) ( b )r  )z( ( ( a ) ) ) [ b ]r(  )z( ( ( a ) ) ) . br%  r   r  )	re   r   ro   r{   r1   r,   r   rP   r  )r   r  r   r  r  r  s         r   (test_trailers_with_redundant_parenthesisz9EndPositionTests.test_trailers_with_redundant_parenthesisV	  s    
 DAqaIIaL%%a(..  a!1!115##Aq!,\IIbM&&q)//55  a!1!115##B1- !  s   CC??D		c                    d}d}| j                  |      }| j                  |      }| j                  ||j                  d   d       | j                  ||j                  d   d       | j                  ||j                  d   d       | j                  ||j                  d   d	       | j                  ||j                  d   d
       y )Nz[{}, {1, }, {1, 2,} ]z{a: b, f (): g () ,}r   z{}rv   z{1, }r8   z{1, 2,}r  r  )r  r  r  rV  rW  )r   r  r  c1c2s        r   test_displayszEndPositionTests.test_displaysg	  s    $#r"r"B
D1B
G4B
I6B
F3B		!f5r   c                    t        d      j                         }| j                  |      }| j                  |dd       | j	                  ||j
                  d   j                  d       | j	                  ||j                  j
                  d   j                  d       | j	                  ||j                  j
                  d   j                  d   d       | j	                  ||j                  j
                  d   j                  d       y )	Nza
            x = [{x for x, y in stuff
                  if cond.x} for stuff in things]
        r8   %   r   thingsstuffzcond.xr  )
r   r   r  r  r  
generatorsr  eltifsr  )r   r   cmps      r   test_comprehensionsz$EndPositionTests.test_comprehensionsr	  s       UW 	
 "CB'As~~a055x@Asww11!4997CAsww11!488;XFAsww11!4;;VDr   c                 "   t        d      j                         }t        j                  |      j                  d   }| j                  ||j                  d   j                  d       | j                  ||j                  d   j                  d       y )NzT
            async def f():
                yield x
                await y
        r   zyield xrv   zawait y)r   r   r   ro   r{   r  r1   r  s      r   test_yield_awaitz!EndPositionTests.test_yield_await~	  sw       UW	 	

 yy|  #Atyy|119=Atyy|119=r   c                     t        d      j                         }t        d      j                         }| j                  |      }| j                  t	        j
                  ||j                        |       y )NzD
            x = (
                a, b,
            ) + ()
        z;
            (
                a, b,
            )
        )r   r   r  r,   r   r  r6  )r   s_origs_tupler  s       r   test_source_segment_multiz*EndPositionTests.test_source_segment_multi	  sm       UW	 	
    UW	 	
 !!&)//

CWMr   c                     t        d      j                         }d}t        j                  |      j                  d   }| j                  t        j                  ||j                  d   d      |       y )Nuf   
            class C:
                def fun(self) -> None:
                    "ЖЖЖЖЖ"
        u/       def fun(self) -> None:
        "ЖЖЖЖЖ"r   Tpaddedr   r   r   ro   r{   r,   r  )r   r	  s_methodr  s       r   test_source_segment_paddedz+EndPositionTests.test_source_segment_padded	  sh       UW	 	
 Iyy %%a(""6499Q<Ex	
r   c                    d}t        j                  |      j                  \  }}}}}| j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       y )Nz!v = 1
w = 1
x = 1
y = 1z = 1
zv = 1zw = 1r  zy = 1zz = 1)r   ro   r{   r  )r   r   r  r   r?   r   r   s          r   test_source_segment_endingsz,EndPositionTests.test_source_segment_endings	  s~    7		!))1aAAq'*Aq'*Aq'*Aq'*Aq'*r   c                     t        d      j                         }d}t        j                  |      j                  d   }| j                  t        j                  ||j                  d   d      |       y )Nzb
            class C:
              	  def fun(self) -> None:
              	      pass
        z+  	  def fun(self) -> None:
  	      passr   Tr  r  )r   r   r  r  s       r   test_source_segment_tabsz)EndPositionTests.test_source_segment_tabs	  sd       UW	 	

 Iyy|  #//499Q<MxXr   c                 J   d}t        j                  |      j                  \  }}}| j                  ||d       | j                  ||d       | j                  ||d       d}t        j                  |      j                  d   }| j                  |||j	                                y )Nz3def f():
  pass
def g():  pass
def h():
  pass
zdef f():
  passzdef g():  passzdef h():
  passz"def f():
  a = 1  b = 2
  c = 3
r   )r   ro   r{   r  rstrip)r   r   rv  r  hs        r   test_source_segment_newlinesz-EndPositionTests.test_source_segment_newlines	  s    J))A,##1aAq"45Aq"45Aq"675IIaLa Aq!((*-r   c                    d}t        j                  |      j                  \  }}}}|`|`|`|`| j                  t        j                  ||             | j                  t        j                  ||             | j                  t        j                  ||             | j                  t        j                  ||             y )Nzv = 1
w = 1
x = 1
y = 1
)	r   ro   r{   r&   r|   r'   r~   rX   r  )r   r   r  r   r?   r   s         r    test_source_segment_missing_infoz1EndPositionTests.test_source_segment_missing_info	  s    0YYq\&&
1aHLL#00A67#00A67#00A67#00A67r   N)#rP   r   rQ   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  r5   r   r   r  r  k  s    BL*
5B =(;F
11*GX/7 1&"
6T&8,."	6
E>N

+	Y	.
8r   r  c                       e Zd Zd Zy)BaseNodeVisitorCasesc                     G fdd| j                         }t        j                  t        d            } |       }g t	        j
                  d      5 }t	        j                  ddt               |j                  |       d d d        | j                  g d       | j                  D cg c]  }t        |j                         c}g d	       y # 1 sw Y   SxY wc c}w )
Nc                   @    e Zd Z fdZ fdZ fdZ fdZ fdZy)=BaseNodeVisitorCases.test_old_constant_nodes.<locals>.Visitorc                 V    j                  |j                  d|j                  f       y )Nr   )r  r&   r   r   r   logs     r   	visit_NumzGBaseNodeVisitorCases.test_old_constant_nodes.<locals>.Visitor.visit_Num	      

DKK78r   c                 V    j                  |j                  d|j                  f       y )Nr   r  r&   r   r"  s     r   	visit_StrzGBaseNodeVisitorCases.test_old_constant_nodes.<locals>.Visitor.visit_Str	  r%  r   c                 V    j                  |j                  d|j                  f       y )Nr   r'  r"  s     r   visit_ByteszIBaseNodeVisitorCases.test_old_constant_nodes.<locals>.Visitor.visit_Bytes	  s    

DKK$&&9:r   c                 V    j                  |j                  d|j                  f       y )Nr   )r  r&   r1   r"  s     r   visit_NameConstantzPBaseNodeVisitorCases.test_old_constant_nodes.<locals>.Visitor.visit_NameConstant	  s    

DKKDEr   c                 B    j                  |j                  ddf       y )Nr   .)r  r&   r"  s     r   visit_EllipsiszLBaseNodeVisitorCases.test_old_constant_nodes.<locals>.Visitor.visit_Ellipsis	  s    

DKKS9:r   N)rP   r   rQ   r$  r(  r*  r,  r.  )r#  s   r   Visitorr   	  s    99;F;r   r/  z            i = 42
            f = 4.25
            c = 4.25j
            s = 'string'
            b = b'bytes'
            t = True
            n = None
            e = ...
            Tr   r   r   ))rv   r   r6   )r8   r   r   )r   r   r   )r:  r   rO  )r9  r   r{  )rH  r   T)r   r   N)r   r   .)+visit_Num is deprecated; add visit_Constantr   r0  r   r0  r   z+visit_Str is deprecated; add visit_Constantr   z-visit_Bytes is deprecated; add visit_Constantr   4visit_NameConstant is deprecated; add visit_Constantr1  z0visit_Ellipsis is deprecated; add visit_Constant)visitor_classr   ro   r   r   r   r   r   visitr,   r   r   )r   r/  r   visitorr   r   r#  s         @r   test_old_constant_nodesz,BaseNodeVisitorCases.test_old_constant_nodes	  s    	;d(( 	;  ii 	 	
 )$$D1T##Hb2DEMM# 2 			
 	%)*TS^T*	
! 21" +s   -C.C!CN)rP   r   rQ   r5  r5   r   r   r  r  	  s    @
r   r  c                   $    e Zd Zej                  Zy)NodeVisitorTestsN)rP   r   rQ   r   NodeVisitorr2  r5   r   r   r7  r7  
  s    OOMr   r7  c                   H    e Zd Zej                  Zd Zd Zd Zd Z	d Z
d Zy)NodeTransformerTestsc                     t        j                  t        |            }t        j                  t        |            } |       }t        j                  |j	                  |            }| j                  ||       y rC   )r   ro   r   r[  r3  assertASTEqual)r   tranformer_classinitial_codeexpected_codeinitial_astexpected_ast
tranformer
result_asts           r   assertASTTransformationz,NodeTransformerTests.assertASTTransformation
  s[    ii| 45yy!67%'
..z/?/?/LM
J5r   c                 d    d}d} G d dt         j                        }| j                  |||       y )Nzdef func(arg) -> SomeType: ...zdef func(arg): ...c                   ,    e Zd Zdej                  fdZy)ENodeTransformerTests.test_node_remove_single.<locals>.SomeTypeRemoverr   c                 H    | j                  |       |j                  dk(  ry |S )NSomeType)generic_visitr  r  s     r   
visit_NamezPNodeTransformerTests.test_node_remove_single.<locals>.SomeTypeRemover.visit_Name*
  s$    ""4(77j(r   N)rP   r   rQ   r   r   rK  r5   r   r   SomeTypeRemoverrG  )
      sxx r   rL  r   NodeTransformerrD  )r   r  expectedrL  s       r   test_node_remove_singlez,NodeTransformerTests.test_node_remove_single#
  s2    /'	c11 	 	$$_dHEr   c                 d    d}d} G d dt         j                        }| j                  |||       y )NzM
        def func(arg):
            print(arg)
            yield arg
        7
        def func(arg):
            print(arg)
        c                   ,    e Zd Zdej                  fdZy)ENodeTransformerTests.test_node_remove_from_list.<locals>.YieldRemoverr   c                 r    | j                  |       t        |j                  t        j                        ry |S rC   )rJ  r   r1   r   r  r  s     r   
visit_ExprzPNodeTransformerTests.test_node_remove_from_list.<locals>.YieldRemover.visit_Expr@
  s*    ""4(djj#))4r   N)rP   r   rQ   r   rR  rW  r5   r   r   YieldRemoverrU  ?
  rM  r   rX  rN  )r   r  rP  rX  s       r   test_node_remove_from_listz/NodeTransformerTests.test_node_remove_from_list2
  s6    
	3.. 	 	$$\4Br   c                 d    d}d} G d dt         j                        }| j                  |||       y )Nz0
        class DSL(Base, kw1=True): ...
        zE
        class DSL(Base, kw1=True, kw2=True, kw3=False): ...
        c                   ,    e Zd Zdej                  fdZy)BNodeTransformerTests.test_node_return_list.<locals>.ExtendKeywordsr   c                     | j                  |       |j                  dk(  rS|t        j                  dt        j                  d            t        j                  dt        j                  d            gS |S )Nkw1kw2Tkw3F)rJ  r  r   r  r   r  s     r   visit_keywordzPNodeTransformerTests.test_node_return_list.<locals>.ExtendKeywords.visit_keywordQ
  s^    ""4(88u$E3<<+=>E3<<+>? 
 r   N)rP   r   rQ   r   r  ra  r5   r   r   ExtendKeywordsr\  P
  s    #++ r   rb  rN  )r   r  rP  rb  s       r   test_node_return_listz*NodeTransformerTests.test_node_return_listH
  s6    		S00 		 	$$^T8Dr   c                 d    d}d} G d dt         j                        }| j                  |||       y )NrS  z5
        def func(arg):
            log(arg)
        c                   ,    e Zd Zdej                  fdZy)9NodeTransformerTests.test_node_mutate.<locals>.PrintToLogr   c                     | j                  |       t        |j                  t        j                        r*|j                  j
                  dk(  rd|j                  _        |S )Nprintr#  )rJ  r   r  r   r   r  r  s     r   
visit_CallzDNodeTransformerTests.test_node_mutate.<locals>.PrintToLog.visit_Callh
  sA    ""4(dii2tyy||w7N#(DIILr   NrP   r   rQ   r   r  ri  r5   r   r   
PrintToLogrf  g
  rM  r   rk  rN  r   r  rP  rk  s       r   test_node_mutatez%NodeTransformerTests.test_node_mutate]
  s6    
	,, 	 	$$Zx@r   c                 d    d}d} G d dt         j                        }| j                  |||       y )NrS  zH
        def func(arg):
            logger.log(arg, debug=True)
        c                   ,    e Zd Zdej                  fdZy):NodeTransformerTests.test_node_replace.<locals>.PrintToLogr   c           
         | j                  |       t        |j                  t        j                        r|j                  j
                  dk(  rt        j                  t        j                  t        j                  dt        j                               dt        j                               |j                  t        j                  dt        j                  d            g      S |S )	Nrh  logger)r  r#  )r  r  debugT)r  r   r  )rJ  r   r  r   r   r  r  r%  rZ  r   r  r   r  s     r   ri  zENodeTransformerTests.test_node_replace.<locals>.PrintToLog.visit_Call{
  s    ""4(dii2tyy||w7N88 ]]HHX388:>!& #

 "YY"%++gs||D7I"J!K  r   Nrj  r5   r   r   rk  rp  z
  s    sxx r   rk  rN  rl  s       r   test_node_replacez&NodeTransformerTests.test_node_replacep
  s6    
	,, 	 	$$Zx@r   N)rP   r   rQ   r   rO  r2  rD  rQ  rY  rc  rm  rt  r5   r   r   r:  r:  
  s0    ''M6FC,E*A&Ar   r:  c                   $    e Zd Zd Zd Zd Zd Zy)ModuleStateTestsc                     d}d}d}t        |||t        j                        }t        |||      }| j                  |t        j
                         y )Nzx + 1rn   r]   )flags)rf   r   rg   r   typesCodeType)r   r  filenamer  rk   s        r   check_ast_modulez!ModuleStateTests.check_ast_module
  sM     44s7H7HI x40dENN3r   c                 8   t        j                  t        j                  dd       5  t        j                  d= dd l}t        j                  d= dd l}| j                          d d d        ~~t        j                          | j                          y # 1 sw Y   0xY w)N_astr   )r   	swap_itemsysmodulesr~  r|  rW   )r   ast1rN  s      r   test_reload_modulez#ModuleStateTests.test_reload_module
  sp    s{{FD9F#F#!!# :  :9s   ;BBc                    t               fd}t        j                  t        j                  dd       5  t        j                  d= t        j
                  t        d|      5  | j                          | j                  dt        j                         dd l	}| j                  |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                 .    t         j                  | <   S rC   )r  r  )r   r   r  lazy_mods      r   	my_importz4ModuleStateTests.test_sys_modules.<locals>.my_import
  s     (CKKOr   r~  
__import__r   )objectr   r  r  r  rm  r   r|  assertNotInr~  r   )r   r  r~  r  s      @r   test_sys_modulesz!ModuleStateTests.test_sys_modules
  s     8	 s{{FD9F#""8\9E%%'  5 dH- F :9 FE :9s$   -C#AB;*C;C	 CCc                 h    t        d      }t        j                  |      }| j                  |d       y )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   run_in_subinterpr,   )r   r  ress      r   test_subinterpreterz$ModuleStateTests.test_subinterpreter
  s5       & &&t,a r   N)rP   r   rQ   r|  r  r  r  r5   r   r   rv  rv  
  s    4 $.,!r   rv  c                       e Zd Zd Zy)ASTMainTestsc                    d}t        j                  t        j                  |      d      }t        j                         5 }t
        j                  j                  |d      }t        |dd      5 }|j                  |       d d d        t        j                  dd	|      \  }}d d d        | j                  j                  d
       | j                  |j                         |j                  j!                  d      j                                | j                  |j"                  d       y # 1 sw Y   xY w# 1 sw Y   xY w)Nzprint(1, 2, 3)r   r  ztest_module.pyr   r=  r>  z-mr   r   utf8r   )r   r  ro   r   temp_dirr@  rA  rG  rH  writer   run_python_until_endr,   err
splitlinesoutdecoderc)r   r  rP  tmp_dirr{  rv  r  rW  s           r   test_cli_file_inputz ASTMainTests.test_cli_file_input
  s    88CIIdOA6!Www||G-=>Hhg6! 7"77eXNFC	 " 	#&,,.v0F0Q0Q0ST# 76 "!s$   /D80D,"D8,D5	1D88EN)rP   r   rQ   r  r5   r   r   r  r  
  s    $r   r  )-r   r   r  r  r@  r  r  r  ry  r  r   rU   	functoolsr   r   r  r   test.support.import_helperr   test.supportr   r   test.support.ast_helperr	   test.test_ast.utilsr
   test.test_ast.snippetsr   r   r   r   r   r   TestCaser   r  ry  rp  r  r  r7  r:  r  rv  r  r5   r   r   <module>r     s,   
  
  	 	 
         : 1 0 ( 
f7!! f7R|=h'' |=~c	6)) c	6L@'H%% @'F`8x(( `8FB
 B
J$+X->-> $rA<)=x?P?P rAj 	O!x(( O! O!d$8$$ $r   