
    <e&                     x    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                     dS dS )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
c                 l    |                                  D ]}|                                |k    r|c S d S N)get_childrenget_name)blocknamechs      )/usr/lib/python3.11/test/test_symtable.py
find_blockr   .   sH      ""  ;;==D  III !     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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#S )$SymtableTest?execMinea_methodspaminternalother_internalfooc                    |                      | j                                        d           |                      | j                                        d           |                      | j                                        d           |                      | j                                        d           |                      | j                                        d           d S )Nmoduleclassfunction)assertEqualtopget_typer   r   r   r   selfs    r
   	test_typezSymtableTest.test_type?   s    **,,h777++--w777//11:>>>++--z::://11:>>>>>r   c                    |                      | j                                        d           |                      | j                                        d           |                      | j                                        d           |                      | j                                        d           |                      | j                                        d           d S )Nr   )assertGreaterr   get_idr   r   r   r   r   s    r
   test_idzSymtableTest.test_idF   s    48??,,a00049++--q1114=//11155549++--q1114=//11155555r   c                     |                      | j                                                   |                     | j                                                   d S r   )assertFalser   is_optimized
assertTruer   r   s    r
   test_optimizedzSymtableTest.test_optimizedM   sJ    ..00111	..0011111r   c                 f   |                      | j                                                   |                      | j                                                   |                      | j                                                   |                     | j                                                   d S r   )r&   r   	is_nestedr   r   r(   r   r   s    r
   test_nestedzSymtableTest.test_nestedR   s    ++--...,,..///,,../////1122222r   c                    |                      | j                                                   |                      | j                                                   |                     | j                                                   d S r   )r(   r   has_childrenr   r&   r   r   s    r
   test_childrenzSymtableTest.test_childrenX   sj    --//000	..00111..0011111r   c                     |                      | j                                        d           |                      | j                                        d           d S )Nr      )r   r   
get_linenor   r   s    r
   test_linenozSymtableTest.test_lineno]   sP    ,,..222--//44444r   c                    | j         }|                     t          |                                          g d           g d}|                     t          |                                          |           |                     t          |                                          g d           |                     | j                                        d           d S )N)abkwvar)r5   r6   r   r7   r   some_varr8   x)barglobsome_assigned_global_var)r:   )r   r   sortedget_parameters
get_localsget_globalsr   	get_frees)r   funcexpecteds      r
   test_function_infozSymtableTest.test_function_infoa   s    y 3 3 5 5668O8O8OPPPYYY 1 122H=== 0 0 2 2335`5`5`aaa0022F;;;;;r   c                 t   |                      | j                            d                                                     |                     | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                     | j                            d                                                     |                     | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     d S )Nr<   r;   r:   instance_varsome_non_assigned_global_varr=   )	r(   r   lookup	is_globalr&   is_declared_globalr   r   r   r   s    r
   test_globalszSymtableTest.test_globalsi   s   	((00::<<===))&11DDFFGGG	((//99;;<<<	((//BBDDEEE--c22<<>>???)).99CCEEFFF	((//99;;<<<(FGGQQSSTTT(BCCMMOOPPPPPr   c                 `   |                      | j                            d                                                     |                     | j                            d                                                     d}|                     | j                                        |           d S )Nr9   )r9   )r&   r   rI   is_nonlocalr(   r   r   get_nonlocals)r   rD   s     r
   test_nonlocalzSymtableTest.test_nonlocalu   s    ))*55AACCDDD+22:>>JJLLMMM ,::<<hGGGGGr   c                    |                      | j                            d                                                     |                     | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     d S )Nr:   r;   rH   r=   )r(   r   rI   is_localr&   r   r   s    r
   
test_localzSymtableTest.test_local{   s    	((--6688999))%0099;;<<<(FGGPPRRSSS(BCCLLNNOOOOOr   c                     |                      | j                            d                                                     d S )Nr:   )r(   r   rI   is_freer   s    r
   	test_freezSymtableTest.test_free   s6    ,,S1199;;<<<<<r   c                    |                      | j                            d                                                     |                      | j                            d                                                     |                     | j                            d                                                     d S )Nr:   r   )r(   r   rI   is_referencedr   r&   r   s    r
   test_referencedzSymtableTest.test_referenced   s    ,,S11??AABBB	((44BBDDEEE))#..<<>>?????r   c                    dD ]A}|                      | j                            |                                                     B|                     | j                            d                                                     d S )N)r5   r8   r7   r:   )r(   r   rI   is_parameterr&   )r   syms     r
   test_parameterszSymtableTest.test_parameters   sz    % 	B 	BCOODI,,S11>>@@AAAA))#..;;==>>>>>r   c                    |                      t          | j                                                  t          | j                                                             |                     t          | j        j        d           d S )Nnot_here)r   lenr   get_identifiersget_symbolsassertRaisesKeyErrorrI   r   s    r
   test_symbol_lookupzSymtableTest.test_symbol_lookup   so    TX557788TX113344	6 	6 	6 	(DHOZ@@@@@r   c                 B   |                      | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                     | j                            d                                                     |                      | j                            d                                          | j        u            | j                            d          }|                     t          |
                                          d           |                     t          |j                   | j                            d          }|                     t          |
                                          d	           |                     t          |j                   d S )
Nr   r   r   r   namespace_testr:      r<   r   )r(   r   rI   is_namespacer   r   r&   get_namespacer   r`   get_namespacesrc   
ValueError)r   ns_test	ns_test_2s      r
   test_namespaceszSymtableTest.test_namespaces   s   //<<>>???	((44AACCDDD//<<>>???	((44AACCDDD(899FFHHIII))#..;;==>>>//==??49LMMM(//"233W335566:::*g&;<<<HOOF++	Y557788!<<<*i&=>>>>>r   c                 |   |                      | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                      | j                            d                                                     |                     | j                            d                                                     d S )Nr:   r;   r   r   )r(   r   rI   is_assignedr   r   r&   r   r   s    r
   test_assignedzSymtableTest.test_assigned   s    	((--99;;<<<	((//;;==>>>//;;==>>>	((44@@BBCCC--c22>>@@AAAAAr   c                    t          j         ddd          }|                                d         }|                     |                    d                                                     |                     |                    d                                                     |                     |                    d                                                     t          j         ddd          }|                                d         }|                     |                    d                                                     |                     |                    d                                                     t          j         ddd          }|                     |                    d                                                     t          j         ddd          }d S )	Nzdef f():
    x: int
testr   r   r:   zdef f():
    x = 1
zglobal x
x: intz=def g():
    x = 2
    def f():
        nonlocal x
    x: int)symtabler   r(   rI   rR   is_annotatedr&   rJ   )r   st1st2st3st4st5st6s          r
   test_annotatedzSymtableTest.test_annotated   s    8&&II  #

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

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

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

31133444  !-
 !'0 0r   c                     |                      | j                            d                                                     d S )Nsys)r(   r   rI   is_importedr   s    r
   test_importedzSymtableTest.test_imported   s4    ..::<<=====r   c                    |                      | j                                        d           |                      | j                                        d           |                      | j                            d                                          d           |                      | j                                        d           d S )Nr   r   r:   r   )r   r   r   r   rI   r   r   s    r
   	test_namezSymtableTest.test_name   s    **,,e444++--v666))#..77993???++--v66666r   c                 `    |                      | j                                        d           d S )N)r   )r   r   get_methodsr   s    r
   test_class_infozSymtableTest.test_class_info   s,    ..00-@@@@@r   c                      fd} |dd            |dd           t          j         ddd                                t                    5                       t                    5  t          j         dt          d          d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y                        t                    5  t          j         dt          d          d           d d d            n# 1 swxY w Y                        t                    5  t          j         dt          d          d           d d d            d S # 1 swxY w Y   d S )	Nc                 8   	 t          j         | dd                               d|            d S # t          $ r\}                    |j        d                               |j        d                               |j        |           Y d }~d S d }~ww xY w)Nr   r   zno SyntaxError for    )ru   failSyntaxErrorr   filenamelinenooffset)
brokencoder   er   s      r
   checkfilenamez9SymtableTest.test_filename_correct.<locals>.checkfilename   s    C!*ff=== 			ZZABBBBB  3 3 3  V444  1---  62222222223s   3 
BABBzdef f(x): foo)(r1   zdef f(x): global x   passs   spamr   )ru   assertWarnsDeprecationWarningrc   	TypeError	bytearray
memoryviewlist)r   r   s   ` r
   test_filename_correctz"SymtableTest.test_filename_correct   s   	C 	C 	C 	C 	C 	',,,*B///&'6222011 	B 	By))	B 	Bfi&8&8&AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 011 	C 	Cfj&9&96BBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cy)) 	= 	=fd7mmV<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=sZ   B1*$BB1B	B1!B	"B11B58B5$DD
D
+$EE #E c                 2    t          j         ddd          }d S )N42r   evalru   r   symbolss     r
   	test_evalzSymtableTest.test_eval   s    #D#v66r   c                 2    t          j         ddd          }d S )Nr   r   singler   r   s     r
   test_singlezSymtableTest.test_single   s    #D#x88r   c                 2    t          j         ddd          }d S )Nzdef f(x): return xr   r   r   r   s     r
   	test_execzSymtableTest.test_exec   s    #$8#vFFr   c                    t          j         t                              d          dd          }|                     t	          |d                     d}t          j         |dd          }|                     t	          |d                     d S )Nutf8r   r   r   s+   # -*- coding: iso8859-15 -*-
class : pass
u   Ž)ru   	TEST_CODEencodeassertIsNotNoner   )r   r   codes      r
   
test_byteszSymtableTest.test_bytes   s    	 0 0 8 8#vFFZV44555Bc622ZX6677777r   c                     |                      t          | j                  d           |                      t          | j                  d           d S )Nz<SymbolTable for module ?>z$<Function SymbolTable for spam in ?>)r   strr   r   r   s    r
   test_symtable_reprzSymtableTest.test_symtable_repr   sF    TX(DEEETY)OPPPPPr   N)'__name__
__module____qualname__ru   r   r   r   r   r   r   r   r   r   r    r$   r)   r,   r/   r3   rE   rL   rP   rS   rV   rY   r]   re   ro   rr   r}   r   r   r   r   r   r   r   r   r    r   r
   r   r   4   s4       
(
IsF
3
3C:c6""Dz$
++H:c6""Dz$
++HZ&677N
*S%
 
 C? ? ?6 6 62 2 2
3 3 32 2 2
5 5 5< < <
Q 
Q 
QH H HP P P= = =@ @ @
? ? ?
A A A? ? ?"B B B0 0 02> > >7 7 7A A A= = =.7 7 79 9 9G G G8 8 8Q Q Q Q Qr   r   __main__)	__doc__ru   unittestr   r   TestCaser   r   mainr   r   r
   <module>r      s      "	J  IQ IQ IQ IQ IQ8$ IQ IQ IQX zHMOOOOO r   