
    daf5,                     z    d Z ddlZddlZdZd Z G d dej
                        Zedk(  r ej                          yy)z&
Test the API of the symtable module.
    Na  
import sys

glob = 42
some_var = 12
some_non_assigned_global_var = 11
some_assigned_global_var = 11

class Mine:
    instance_var = 24
    def a_method(p1, p2):
        pass

def spam(a, b, *var, **kw):
    global bar
    global some_assigned_global_var
    some_assigned_global_var = 12
    bar = 47
    some_var = 10
    x = 23
    glob
    def internal():
        return x
    def other_internal():
        nonlocal some_var
        some_var = 3
        return some_var
    return internal

def foo():
    pass

def namespace_test(): pass
def namespace_test(): pass

type Alias = int
type GenericAlias[T] = list[T]

def generic_spam[T](a):
    pass

class GenericMine[T: int]:
    pass
c                 \    | j                         D ]  }|j                         |k(  s|c S  y N)get_childrenget_name)blocknamechs      -/root/Python-3.12.4/Lib/test/test_symtable.py
find_blockr   7   s-      " ;;=D I    c                      e Zd Z ej                  edd      Z eed      Z eed      Z eed      Z	 ee	d      Z
 ee	d      Z eed      Z eed	      Z eed
      Z eed
      Z eed      Z eed      Z eed      Z eed      Z ee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))*SymtableTest?execMinea_methodspaminternalother_internalfooAliasGenericAliasgeneric_spamGenericMineTc                    | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j
                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       y )Nmoduleclassfunctionz
type aliasztype parameterzTypeVar bound)assertEqualtopget_typer   r   r   r   r   r   r   GenericAlias_innerr   generic_spam_innerr   GenericMine_innerr   selfs    r
   	test_typezSymtableTest.test_typeP   s   **,h7++-w7//1:>++-z://1:>**,j9,,.=**3357GH0099;\J**3357GH0099;ZH))2246FG//88:GD*O<r   c                 L   | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j
                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       y )Nr   )assertGreaterr!   get_idr   r   r   r   r   r   r   r   r   r&   s    r
   test_idzSymtableTest.test_id`   s&   488??,a0499++-q14==//115499++-q14==//115488??,a04::,,.24,,335q94,,335q94++224a8r   c                     | j                  | j                  j                                | j                  | j                  j                                y r   )assertFalser!   is_optimized
assertTruer   r&   s    r
   test_optimizedzSymtableTest.test_optimizedl   s6    ..01		..01r   c                 L   | j                  | j                  j                                | j                  | j                  j                                | j                  | j                  j                                | j                  | j                  j                                y r   )r.   r!   	is_nestedr   r   r0   r   r&   s    r
   test_nestedzSymtableTest.test_nestedq   sl    ++-.,,./,,.///12r   c                     | j                  | j                  j                                | j                  | j                  j                                | j	                  | j
                  j                                y r   )r0   r!   has_childrenr   r.   r   r&   s    r
   test_childrenzSymtableTest.test_childrenw   sO    --/0		..01..01r   c                     | j                  | j                  j                         d       | j                  | j                  j                         d       y )Nr      )r    r!   
get_linenor   r&   s    r
   test_linenozSymtableTest.test_lineno|   s<    ,,.2--/4r   c                 v   | j                   }| j                  t        |j                               g d       g d}| j                  t        |j	                               |       | j                  t        |j                               g d       | j                  | j                  j                         d       y )N)abkwvar)r=   r>   r   r?   r   some_varr@   x)barglobsome_assigned_global_var)rB   )r   r    sortedget_parameters
get_localsget_globalsr   	get_frees)r'   funcexpecteds      r
   test_function_infozSymtableTest.test_function_info   s    yy 3 3 568OPY 12H= 0 0 235`a002F;r   c                    | j                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                y )NrD   rC   rB   instance_varsome_non_assigned_global_varrE   )	r0   r   lookup	is_globalr.   is_declared_globalr   r   r!   r&   s    r
   test_globalszSymtableTest.test_globals   sJ   		((0::<=))&1DDFG		((/99;<		((/BBDE--c2<<>?)).9CCEF		((/99;<(FGQQST(BCMMOPr   c                 <   | j                  | j                  j                  d      j                                | j	                  | j
                  j                  d      j                                d}| j                  | j
                  j                         |       y )NrA   )rA   )r.   r   rQ   is_nonlocalr0   r   r    get_nonlocalsr'   rL   s     r
   test_nonlocalzSymtableTest.test_nonlocal   sr    ))*5AACD++22:>JJLM ,,::<hGr   c                    | j                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j
                  j                  d      j                                y )NrB   rC   rP   rE   )r0   r   rQ   is_localr.   r!   r&   s    r
   
test_localzSymtableTest.test_local   s    		((-6689))%099;<(FGPPRS(BCLLNOr   c                 t    | j                  | j                  j                  d      j                                y )NrB   )r0   r   rQ   is_freer&   s    r
   	test_freezSymtableTest.test_free   s&    ,,S199;<r   c                 T   | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                y )NrB   r   )r0   r   rQ   is_referencedr   r.   r&   s    r
   test_referencedzSymtableTest.test_referenced   sp    ,,S1??AB		((4BBDE))#.<<>?r   c                     dD ]:  }| j                  | j                  j                  |      j                                < | j	                  | j                  j                  d      j                                y )N)r=   r@   r?   rB   )r0   r   rQ   is_parameterr.   )r'   syms     r
   test_parameterszSymtableTest.test_parameters   s]    % 	BCOODII,,S1>>@A	B))#.;;=>r   c                    | j                  t        | j                  j                               t        | j                  j	                                      | j                  t        | j                  j                  d       y )Nnot_here)r    lenr!   get_identifiersget_symbolsassertRaisesKeyErrorrQ   r&   s    r
   test_symbol_lookupzSymtableTest.test_symbol_lookup   sU    TXX5578TXX1134	6 	(DHHOOZ@r   c                    | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j                  j                  d      j                         | j
                  u        | j                  j                  d      }| j                  t        |j                               d       | j                  t        |j                         | j                  j                  d      }| j                  t        |j                               d	       | j                  t        |j                         y )
Nr   r   r   r   namespace_testrB      rD   r   )r0   r!   rQ   is_namespacer   r   r.   get_namespacer    ri   get_namespacesrl   
ValueError)r'   ns_test	ns_test_2s      r
   test_namespaceszSymtableTest.test_namespaces   s   /<<>?		((4AACD/<<>?		((4AACD(89FFHI))#.;;=>/==?499LM((//"23W3356:*g&;&;<HHOOF+	Y5578!<*i&=&=>r   c                 4   | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j                  j                  d      j                                y )NrB   rC   r   r   )r0   r   rQ   is_assignedr!   r   r.   r   r&   s    r
   test_assignedzSymtableTest.test_assigned   s    		((-99;<		((/;;=>/;;=>		((4@@BC--c2>>@Ar   c                 0   t        j                   ddd      }|j                         d   }| j                  |j                  d      j	                                | j                  |j                  d      j                                | j                  |j                  d      j                                t        j                   ddd      }|j                         d   }| j                  |j                  d      j	                                | j                  |j                  d      j                                t        j                   ddd      }| j                  |j                  d      j                                t        j                   ddd      }y )	Nzdef f():
    x: int
testr   r   rB   zdef f():
    x = 1
zglobal x
x: intz=def g():
    x = 2
    def f():
        nonlocal x
    x: int)symtabler   r0   rQ   r[   is_annotatedr.   rR   )r'   st1st2st3st4st5st6s          r
   test_annotatedzSymtableTest.test_annotated   s9    8&&I #

30023

34467C2245 7H #

30023C5578  2FFC

31134  !-
 !'0r   c                 t    | j                  | j                  j                  d      j                                y )Nsys)r0   r!   rQ   is_importedr&   s    r
   test_importedzSymtableTest.test_imported   s$    .::<=r   c                 r   | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j	                  d      j                         d       | j                  | j
                  j                         d       y )Nr!   r   rB   r   )r    r!   r   r   rQ   r   r&   s    r
   	test_namezSymtableTest.test_name   s    **,e4++-v6))#.7793?++-v6r   c                 X    | j                  | j                  j                         d       y )N)r   )r    r   get_methodsr&   s    r
   test_class_infozSymtableTest.test_class_info   s    ..0-@r   c                      fd} |dd        |dd       t        j                   ddd        j                  t              5  t        j                   dt        d      d       d d d         j                  t              5  t        j                   dt	        d      d       d d d         j                  t              5  t        j                   dt        d      d       d d d        y # 1 sw Y   xY w# 1 sw Y   TxY w# 1 sw Y   y xY w)	Nc                 2   	 t        j                   | dd       j                  d|        y # t        $ r^}j                  |j                  d       j                  |j
                  d       j                  |j                  |       Y d }~y d }~ww xY w)Nr   r   zno SyntaxError for    )r~   failSyntaxErrorr    filenamelinenooffset)
brokencoder   er'   s      r
   checkfilenamez9SymtableTest.test_filename_correct.<locals>.checkfilename   s}    C!!*ff= 		ZAB  3  V4  1-  6223s   / 	BABBzdef f(x): foo)(r9   zdef f(x): global x   passs   spamr   )r~   rl   	TypeError	bytearray
memoryviewlist)r'   r   s   ` r
   test_filename_correctz"SymtableTest.test_filename_correct   s    	C 	',*B/&'62y) 	Bfi&8&A	By) 	Cfj&96B	Cy) 	=fd7mV<	= 	=		B 	B	C 	C	= 	=s$   !C+!C7!D+C47D Dc                 2    t        j                   ddd      }y )N42r   evalr~   r'   symbolss     r
   	test_evalzSymtableTest.test_eval  s    ##D#v6r   c                 2    t        j                   ddd      }y )Nr   r   singler   r   s     r
   test_singlezSymtableTest.test_single
  s    ##D#x8r   c                 2    t        j                   ddd      }y )Nzdef f(x): return xr   r   r   r   s     r
   	test_execzSymtableTest.test_exec  s    ##$8#vFr   c                     t        j                   t        j                  d      dd      }| j                  t	        |d             d}t        j                   |dd      }| j                  t	        |d             y )Nutf8r   r   r   s+   # -*- coding: iso8859-15 -*-
class : pass
u   Ž)r~   	TEST_CODEencodeassertIsNotNoner   )r'   r!   codes      r
   
test_byteszSymtableTest.test_bytes  sd    	 0 0 8#vFZV45Bc62ZX67r   c                     | j                  t        | j                        d       | j                  t        | j                        d       y )Nz<SymbolTable for module ?>z$<Function SymbolTable for spam in ?>)r    strr!   r   r&   s    r
   test_symtable_reprzSymtableTest.test_symtable_repr  s4    TXX(DETYY)OPr   c                     d| j                   j                          d| j                   j                          d}| j                  t	        | j                   j
                        |       y )Nz<symtable entry top(z), line >)r!   r+   r:   r    repr_tablerX   s     r
   test_symtable_entry_reprz%SymtableTest.test_symtable_entry_repr  sN    )$((//*;)<HTXXEXEXEZD[[\]dhhoo.9r   N)0__name__
__module____qualname__r~   r   r!   r   r   r   r   r   r   r   r   r   r#   r   r$   r   r%   r   r(   r,   r1   r4   r7   r;   rM   rT   rY   r\   r_   rb   rf   rn   rx   r{   r   r   r   r   r   r   r   r   r   r   r    r   r
   r   r   =   sT   
(

IsF
3Cc6"D$
+Hc6"D$
+H&67N
S%
 CsG$Ec>2L#L.Ac>2L#L.AS-0K";>;$A= 
92
32
5<
QHP=@
?
A?"B02>7A=,79G8Q:r   r   __main__)	__doc__r~   unittestr   r   TestCaser   r   mainr   r   r
   <module>r      sN     +	\b:8$$ b:J zHMMO r   