
    <ep;                        d dl Z d dlZd dlZd Z G d dej                  Z G d de          Z G d de          Z G d	 d
e          Z G d de          Z	 G d de          Z
d ZddZ G d dej                  Z G d dej                  Z G d dej                  Zedk    r ej                     dS dS )    Nc                       d   fdS )Nc                  &     G d d          } d a | S )Nc                       e Zd ZdS );global_function.<locals>.inner_function.<locals>.LocalClassN)__name__
__module____qualname__     */usr/lib/python3.11/test/test_funcattrs.py
LocalClassr      s        Dr   r   c                      d } | S )Nc                      d S Nr
   r
   r   r   inner_function2z.inner_global_function.<locals>.inner_function2       r   r
   )r   s    r   inner_global_functionr      s      ""r   )r   )r   s    r   inner_functionz'global_function.<locals>.inner_function   sA    	 	 	 	 	 	 	 		# 	# 	# r   c                       S r   r
   r   s   r   <lambda>z!global_function.<locals>.<lambda>   s    > r   r
   r   s   @r   global_functionr      s#       "!!!!r   c                       e Zd Zd Zd ZdS )FuncAttrsTestc                 `     G d d          }d } |            | _         || _        || _        d S )Nc                       e Zd Zd ZdS )FuncAttrsTest.setUp.<locals>.Fc                     d S r   r
   selfs    r   az FuncAttrsTest.setUp.<locals>.F.a   r   r   N)r   r   r	   r!   r
   r   r   Fr      s#            r   r"   c                      dS N   r
   r
   r   r   bzFuncAttrsTest.setUp.<locals>.b   s    1r   )fir"   r&   )r    r"   r&   s      r   setUpzFuncAttrsTest.setUp   sX    	 	 	 	 	 	 	 		 	 	!##r   c                     	 t          |||           |                     d|d|           n# |$ r Y nw xY w	 t          ||           |                     d|z             d S # |$ r Y d S w xY w)Nzshouldn't be able to set z to zshouldn't be able to del %s)setattrfaildelattr)r    objnamevalue
exceptionss        r   cannot_set_attrzFuncAttrsTest.cannot_set_attr   s    	KCu%%% IIITTT55IJJJJ  	 	 	D		<C II3d:;;;;;  	 	 	DD	s   / 77A% %A.-A.N)r   r   r	   r(   r1   r
   r   r   r   r      s2          < < < < <r   r   c                   h    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S )FunctionPropertiesTestc                 P    |                      | j        j        t                     d S r   )assertEqualr&   r   r   r   s    r   test_modulez"FunctionPropertiesTest.test_module/   s#    *H55555r   c                     d| j         _        |                     dt          | j                   d           d| j        j        _        |                     dt          | j        j                  d           d S )N   
known_attrz+set attributes not in dir listing of methodzEset attribute on function implementations, should show up in next dir)r&   r9   assertIndirr"   r!   r'   r   s    r   test_dir_includes_correct_attrsz6FunctionPropertiesTest.test_dir_includes_correct_attrs2   sx    lCKK9	; 	; 	;  lC	NN 5C 	D 	D 	D 	D 	Dr   c                 B    d }|                      | j        |           d S )Nc                      	 dS r$   r
   r
   r   r   	duplicatezJFunctionPropertiesTest.test_duplicate_function_equality.<locals>.duplicate=   s
    1r   )assertNotEqualr&   )r    r?   s     r    test_duplicate_function_equalityz7FunctionPropertiesTest.test_duplicate_function_equality;   s1    	 	 	 	DFI.....r   c                     d }|                       |            d            | j        j        |_        |                       |            d           d S )Nc                      d S r   r
   r
   r   r   testz:FunctionPropertiesTest.test_copying___code__.<locals>.testC         r   r%   )r5   r&   __code__)r    rD   s     r   test_copying___code__z,FunctionPropertiesTest.test_copying___code__B   sT    &&&#####r   c                     |                      | j        j        t                                 |                     | j        ddt
          t          f           d S )N__globals__   )assertIsr&   rI   globalsr1   AttributeError	TypeErrorr   s    r   test___globals__z'FunctionPropertiesTest.test___globals__H   sQ    df('))444TV]A,i8	: 	: 	: 	: 	:r   c                 @   |                      | j        j        t                     |                     | j        ddt          t
          f           d }i } t          |          |j        |          }|                      |j        |           |                      |j        t                     | 	                     |d          d           | 	                    |i            t          j        d          }dd i}t          |d}t          ||           |                      |d	         j        |           |                      |d
         j        |           |                      |d	         j        d         |           |                     d|d
         j                   d S )N__builtins__rJ   c                      t          |           S r   )len)ss    r   funcz6FunctionPropertiesTest.test___builtins__.<locals>.funcT   s    CFF]r   abcr%   z\
            def func3(s): pass
            func4 = type(func3)(func3.__code__, {})
        None)typerQ   func3func4)rK   r&   rQ   r1   rM   rN   rX   rF   rI   r5   textwrapdedentexecassertNotIn)r    rU   nsfunc2codesafe_builtinss         r   test___builtins__z(FunctionPropertiesTest.test___builtins__M   s   df)<888TV^Q,i8	: 	: 	:
 	#""T

4="--e',,,e(,777 	uq)))R          M::T2bk.>>>bk.>>>bk-n=}MMMG)@AAAAAr   c                 &   dfd}|j         }|                     |t                     |                     t	          |          d           |                     |d         j        j        d           |                     |d|t                     d S )N   c                  &    t                      d S r   printr!   s   r   fz2FunctionPropertiesTest.test___closure__.<locals>.fn       qr      r   cell__closure__)	rn   assertIsInstancetupler5   rS   	__class__r   r1   rM   r    rj   cr!   s      @r   test___closure__z'FunctionPropertiesTest.test___closure__l   s    Ma'''Q###10&999Qq.AAAAAr   c                    t          j        d          }|                     |j        d           t          j                    }d}|                     t
          |          5  |j         d d d            d S # 1 swxY w Y   d S )Nrl   'shouldn't be able to read an empty cell)msg)typesCellTyper5   cell_contentsassertRaises
ValueError)r    cell_objrw   s      r   test_cell_newz$FunctionPropertiesTest.test_cell_newv   s    >!$$/333>##7zs33 	# 	#""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   !A66A:=A:c                     fd}	 |j         d         j         |                     d           n# t          $ r Y nw xY wdd S )Nc                  &    t                      d S r   rg   ri   s   r   rj   z1FunctionPropertiesTest.test_empty_cell.<locals>.f   rk   r   r   rv   re   )rn   rz   r+   r|   )r    rj   r!   s     @r   test_empty_cellz&FunctionPropertiesTest.test_empty_cell   sm    	AM!** II?@@@@  	 	 	D	 s   0 
==c                 \   dfd}|j         }d|d         _        |                     |d         j        d           |                      |            d           |                     d           |d         `	 |d         j         |                     d           n# t          $ r Y nw xY w|                     t                    5   |             d d d            n# 1 swxY w Y   |                     t                    5  t                     d d d            d S # 1 swxY w Y   d S )Nre   c                       S r   r
   ri   s   r   rj   z/FunctionPropertiesTest.test_set_cell.<locals>.f   s    r   	   r   rv   )	rn   rz   r5   r+   r|   r{   	NameErrorUnboundLocalErrorrh   rr   s      @r   test_set_cellz$FunctionPropertiesTest.test_set_cell   s   M!1+Q///a   AaD	AaD II?@@@@  	 	 	D	 y)) 	 	ACCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	011 	 	!HHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   ;B 
B+*B+CC#&C#D!!D%(D%c                    |                      | j        j        d           d| j        _        |                      | j        j        d           d| j        _        |                      | j        j        d           |                     | j        ddt                     d}t          |di i           |                      | j        j        j        d           |                     | j        j        ddt                     d S )	Nr&   rs   dr   r8   zdef f(): pass
f.__name__rQ   r!   )	r5   r&   r   r1   rN   r]   r'   r!   rM   )r    rT   s     r   test___name__z$FunctionPropertiesTest.test___name__   s    #...#...#...TVZI>>> ,Q$%%%+S111TWY
CHHHHHr   c                 l   |                      | j        j        d           |                      t          j        j        d           |                      t
          j        d           |                      t                      j        d           |                       t                                  j        d           |                        t                                              j        d           |                      t          j        d           |                      t                      j        d           d	| j        _        |                      | j        j        d	           d
| j        _        |                      | j        j        d
           |                     | j        ddt                     d S )NzFuncAttrsTest.setUp.<locals>.bzFuncAttrsTest.setUpr   z!global_function.<locals>.<lambda>z'global_function.<locals>.inner_functionr   r   z.inner_global_function.<locals>.inner_function2rs   r   r	   r8   )	r5   r&   r	   r   r(   r   r   r1   rN   r   s    r   test___qualname__z(FunctionPropertiesTest.test___qualname__   s   ,.NOOO,9;PQQQ57HIII**7<	> 	> 	>***,,9B	D 	D 	D,***,,..;V	X 	X 	X.;=TUUU.00=?oppp!,c222!,c222TV^Q	BBBBBr   c                    d\  d }d }fd}fd}fd}|||||fD ]4}|                      t          |j                  t          j                   5|                       |            d           |                       |            d           |j        |_        |                      |j        |j                   |                       |            d           	 |j        |_        |                     d	           n# t          $ r Y nw xY w	 |j        |_        |                     d	           d S # t          $ r Y d S w xY w)
N)r8      c                      d S r   r
   r
   r   r   r!   z/FunctionPropertiesTest.test___code__.<locals>.a   rE   r   c                      dS )Nre   r
   r
   r   r   r&   z/FunctionPropertiesTest.test___code__.<locals>.b   s    r   c                       S r   r
   )num_ones   r   rs   z/FunctionPropertiesTest.test___code__.<locals>.c       r   c                       S r   r
   )num_twos   r   r   z/FunctionPropertiesTest.test___code__.<locals>.d   r   r   c                       fS r   r
   )r   r   s   r   ez/FunctionPropertiesTest.test___code__.<locals>.e   s    ((r   r8   r   zC__code__ with different numbers of free vars should not be possible)r5   rX   rF   rx   CodeTyper+   r|   )	r    r!   r&   rs   r   r   rU   r   r   s	          @@r   test___code__z$FunctionPropertiesTest.test___code__   s   ((((((1aO 	B 	BDT$-00%.AAAAa   a   Z
QZ000a   	)AJ II ( ) ) ) )  	 	 	D	
	)AJ II ( ) ) ) ) )  	 	 	DD	s$   !D 
DDD7 7
EEc                     |                      | j        j        d            | j        `|                      | j        j        d            d S r   )r5   r&   __defaults__r   s    r   test_blank_func_defaultsz/FunctionPropertiesTest.test_blank_func_defaults   sF    ,d333F,d33333r   c                    d }dd}|                      |j        d            |                      |j        d           d|_        |                      |j        d           |                       |            d           |                       |d          d           |                       |dd          d           |`|                      |j        d            	  |             |                     d	           d S # t          $ r Y d S w xY w)
Nc                     | |z   S r   r
   r!   r&   s     r   
first_funczAFunctionPropertiesTest.test_func_default_args.<locals>.first_func       Q3Jr   rl   rJ   c                     | |z   S r   r
   r   s     r   second_funczBFunctionPropertiesTest.test_func_default_args.<locals>.second_func   r   r   )rl   rJ   r%      r   zE__defaults__ does not update; deleting it does not remove requirement)r5   r   r+   rN   )r    r   r   s      r   test_func_default_argsz-FunctionPropertiesTest.test_func_default_args   sN   	 	 		 	 	 	0$77716:::"(
0&999q)))A***Aq))1---$14888	,KMMM II + , , , , ,  	 	 	DD	s   
C< <
D
	D
N)r   r   r	   r6   r<   rA   rG   rO   rc   rt   r~   r   r   r   r   r   r   r   r
   r   r   r3   r3   -   s       6 6 6D D D/ / /$ $ $: : :
B B B>B B B# # #    (I I I C C C() ) )<4 4 4
, , , , ,r   r3   c                   &    e Zd Zd Zd Zd Zd ZdS )InstancemethodAttrTestc                     |                      | j        j        j        j        | j                   |                     | j        j        d| j        t                     d S )Nrq   )r5   r'   r!   __self__rq   r"   r1   rN   r   s    r   test___class__z%InstancemethodAttrTest.test___class__   sJ    +5tv>>>TWYTVYGGGGGr   c                     |                      | j        j        j        | j        j                   |                     | j        j        d| j        j        t                     d S )N__func__)r5   r'   r!   r   r"   r1   rM   r   s    r   test___func__z$InstancemethodAttrTest.test___func__  sK    +TVX666TWY
DFHnMMMMMr   c                     |                      | j        j        j        | j                   |                     | j        j        d| j        t
                     d S )Nr   )r5   r'   r!   r   r1   rM   r   s    r   test___self__z$InstancemethodAttrTest.test___self__  sG    +TW555TWY
DG^LLLLLr   c                    t          j        t          | j                  | j        _        |                     | j                                        t          | j                             	 | j        j        j         |                     d           n# t          $ r Y nw xY w|                     | j        j        ddt                     d S )N4using unknown attributes should raise AttributeErrorunknown_attrrJ   )	rx   
MethodTypeidr'   r5   r   r+   rM   r1   r   s    r   test___func___non_methodz/InstancemethodAttrTest.test___func___non_method	  s     %b$'22
r$'{{333	NGJ## IILMMMM  	 	 	D	
 	TWZNKKKKKs   *B 
BBN)r   r   r	   r   r   r   r   r
   r   r   r   r      s^        H H HN N NM M ML L L L Lr   r   c                        e Zd Zd Zd Zd ZdS )ArbitraryFunctionAttrTestc                     d| j         _        |                     | j         j        d           	 d| j        j        _        |                     d           d S # t          $ r Y d S w xY w)Nr8   z0setting attributes on methods should raise error)r&   r9   r5   r'   r!   r+   rM   r   s    r   test_set_attrz'ArbitraryFunctionAttrTest.test_set_attr  sx    *A...	J#$DGI  IIHIIIII  	 	 	DD	s   A 
A$#A$c                 b    	 | j         `|                     d           d S # t          $ r Y d S w xY w)Nz1deleting unknown attribute should raise TypeError)r&   r   r+   rM   r   s    r   test_delete_unknown_attrz2ArbitraryFunctionAttrTest.test_delete_unknown_attr$  sO    	K# IIIJJJJJ  	 	 	DD	     
..c                     | j         | j        j        fD ]/}	 |j         |                     d            # t
          $ r Y ,w xY wd S )Nr   )r&   r'   r!   non_existent_attrr+   rM   )r    rU   s     r   test_unset_attrz)ArbitraryFunctionAttrTest.test_unset_attr,  sx    VTWY' 	, 	,D,&& 		 + , , , , "   	, 	,s   4
A AN)r   r   r	   r   r   r   r
   r   r   r   r     sG        J J JK K K, , , , ,r   r   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )FunctionDictsTestc                     |                      | j        dd t                     ddlm}  |ddi          }|                      | j        j        j        d|t                     d S )N__dict__r   )UserDictr9   r8   )r1   r&   rN   collectionsr   r'   r!   r   )r    r   r   s      r   test_setting_dict_to_invalidz.FunctionDictsTest.test_setting_dict_to_invalid8  sk    TVZyAAA((((((HlA&''TWY/Q	JJJJJr   c                 P   ddi}|| j         _        |                     || j         j                   || j        j        _        |                     || j        j        j        j                   |                     || j        j        j                   |                     | j         j        d           |                     | j         j        d         d           |                     | j        j        j        j        d           |                     | j        j        j        d           d S )Nr9   r8   )	r&   r   rK   r"   r!   r'   r   r5   r9   )r    r   s     r   test_setting_dict_to_validz,FunctionDictsTest.test_setting_dict_to_valid>  s    1a)))a+4555a+,,,*A...6:::+6:::-q11111r   c                 b    	 | j         `|                     d           d S # t          $ r Y d S w xY w)Nz3deleting function dictionary should raise TypeError)r&   r   r+   rN   r   s    r   test_delete___dict__z&FunctionDictsTest.test_delete___dict__N  sN    	M IIKLLLLL  	 	 	DD	r   c                 F    |                      | j        j        i            d S r   )r5   r&   r   r   s    r   test_unassigned_dictz&FunctionDictsTest.test_unassigned_dictV  s"    "-----r   c                 d    d}i }||| j         <   |                     || j                  |           d S )NzSome string)r&   r5   )r    r/   r   s      r   test_func_as_dict_keyz'FunctionDictsTest.test_func_as_dict_keyY  s9    $&	46E*****r   N)r   r   r	   r   r   r   r   r   r
   r   r   r   r   7  se        K K K2 2 2 M M M. . .+ + + + +r   r   c                       e Zd Zd Zd ZdS )FunctionDocstringTestc                 \   |                      | j        j        d            d}|| j        _        || j        j        _        |                      | j        j        |           |                      | j        j        j        |           |                     | j        j        d|t                     d S )NzA test method that does nothing__doc__)r5   r&   r   r"   r!   r'   r1   rM   )r    docstrs     r   test_set_docstring_attrz-FunctionDocstringTest.test_set_docstring_attra  s    ...2!000*F333TWY	6>JJJJJr   c                 l    d| j         _        | j         `|                     | j         j        d            d S )NzThe docstring)r&   r   r5   r   s    r   test_delete_docstringz+FunctionDocstringTest.test_delete_docstringj  s2    (FN.....r   N)r   r   r	   r   r   r
   r   r   r   r   `  s5        K K K/ / / / /r   r   c                 .    	 fd}| |j         d         S )Nc                  &    t                      d S r   rg   ri   s   r   rj   zcell.<locals>.fr      ar   r   rn   )r/   rj   r!   s     @r   rm   rm   p  s1    3    A=r   Tc                 2    	 fd}| sd|j         d         S )Nc                  &    t                      d S r   rg   ri   s   r   rj   zempty_cell.<locals>.fy  r   r   i  r   r   )emptyrj   r!   s     @r   
empty_cellr   w  s;        
  =r   c                       e Zd Zd ZdS )CellTestc                    |                      t          d          t          d          k                |                      t                      t          d          k                |                      t                      t                      k               |                      t          d          t          d          k               |                      t          d          t                      k               d S )NrJ   r%   saturdayig      BT)
assertTruerm   r   r   s    r   test_comparisonzCellTest.test_comparison  s    
 	Q$q'')***
tJ'7'77888

4555S		T%[[0111T

Z\\122222r   N)r   r   r	   r   r
   r   r   r   r     s#        	3 	3 	3 	3 	3r   r   c                       e Zd Zd ZdS )StaticMethodAttrsTestc                     d }t          |          }|                     |j        |u            t          |          }|                     |j        |u            d S )Nc                      d S r   r
   r
   r   r   rj   z4StaticMethodAttrsTest.test_func_attribute.<locals>.f  s    Dr   )classmethodr   r   staticmethod)r    rj   rs   rT   s       r   test_func_attributez)StaticMethodAttrsTest.test_func_attribute  s_    	 	 	 NN
a(((OO
a(((((r   N)r   r   r	   r   r
   r   r   r   r     s#        ) ) ) ) )r   r   c                       e Zd Zd ZdS )BuiltinFunctionPropertiesTestc                 >   dd l }|                     t          j        d           |                     |j         j        d           |                     t          j        j        d           |                     t          j        j        d           |                     t          j	        j        d           |                     t          j	        j        d           |                     g dj        j        d	           |                     d
dij        j        d           d S )Nr   rS   timezdict.fromkeyszfloat.__getformat__zstr.maketranszbytes.maketrans)rl   rJ   r%   zlist.appendfoobarzdict.pop)r   r5   rS   r	   dictfromkeysfloat__getformat__str	maketransbytesappendpop)r    r   s     r   test_builtin__qualname__z6BuiltinFunctionPropertiesTest.test_builtin__qualname__  s    	)5111/888 	3_EEE,9.	0 	0 	0 	3_EEE57HIII 	)6FFF%+8*EEEEEr   N)r   r   r	   r   r
   r   r   r   r     s(        F F F F Fr   r   __main__)T)r[   rx   unittestr   TestCaser   r3   r   r   r   r   rm   r   r   r   r   r   mainr
   r   r   <module>r      s     
" 
" 
"< < < < <H% < < <4K, K, K, K, K,] K, K, K,\L L L L L] L L L<, , , , , , , ,<&+ &+ &+ &+ &+ &+ &+ &+R/ / / / /M / / /   	 	 	 	
3 
3 
3 
3 
3x  
3 
3 
3	) 	) 	) 	) 	)H- 	) 	) 	)F F F F FH$5 F F F2 zHMOOOOO r   