
    dafI>                     |   d dl Z 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$                          yy)    Nc                       d   fdS )Nc                        G d d      } d a | S )Nc                       e Zd Zy);global_function.<locals>.inner_function.<locals>.LocalClassN)__name__
__module____qualname__     ./root/Python-3.12.4/Lib/test/test_funcattrs.py
LocalClassr   	   s    r   r   c                      d } | S )Nc                       y 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   s    	 		# 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y)FuncAttrsTestc                 R     G d d      }d } |       | _         || _        || _        y )Nc                       e Zd Zd Zy)FuncAttrsTest.setUp.<locals>.Fc                      y 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                       y)N   r
   r
   r   r   bzFuncAttrsTest.setUp.<locals>.b   s    r   )fir"   r%   )r    r"   r%   s      r   setUpzFuncAttrsTest.setUp   s(    	 		#r   c                     	 t        |||       | j                  d|d|       	 t        ||       | j                  d|z         y # |$ r Y )w xY w# |$ r Y y 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   sq    	KCu% IIT5IJ	<C II3d:;  		  		s"   A A AAAAN)r   r   r	   r'   r0   r
   r   r   r   r      s    <r   r   c                   l    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y)FunctionPropertiesTestc                 X    | j                  | j                  j                  t               y r   )assertEqualr%   r   r   r   s    r   test_modulez"FunctionPropertiesTest.test_module0   s    **H5r   c                    d| j                   _        | j                  dt        | j                         d       d| j                  j
                  _        | j                  dt        | j                  j
                        d       y )N   
known_attrz+set attributes not in dir listing of methodzEset attribute on function implementations, should show up in next dir)r%   r8   assertIndirr"   r!   r&   r   s    r   test_dir_includes_correct_attrsz6FunctionPropertiesTest.test_dir_includes_correct_attrs3   s^    lCK9	;  lC		N 5C 	Dr   c                 B    d }| j                  | j                  |       y )Nc                       y)zmy docstringr$   r
   r
   r   r   	duplicatezJFunctionPropertiesTest.test_duplicate_function_equality.<locals>.duplicate>   s    r   )assertNotEqualr%   )r    r>   s     r    test_duplicate_function_equalityz7FunctionPropertiesTest.test_duplicate_function_equality<   s    	 	DFFI.r   c                     d }| j                   |       d        | j                  j                  |_        | j                   |       d       y )Nc                       y r   r
   r
   r   r   testz:FunctionPropertiesTest.test_copying___code__.<locals>.testD   s    Dr   r$   )r4   r%   __code__)r    rC   s     r   test_copying___code__z,FunctionPropertiesTest.test_copying___code__C   s8    &#r   c                     | j                  | j                  j                  t                      | j	                  | j                  ddt
        t        f       y )N__globals__   )assertIsr%   rG   globalsr0   AttributeError	TypeErrorr   s    r   test___globals__z'FunctionPropertiesTest.test___globals__I   s<    dff((')4TVV]A,i8	:r   c                    | j                  | j                  j                  t               | j                  | j                  ddt        t
        f       d }i } t        |      |j                  |      }| j                  |j                  |       | j                  |j                  t               | j                   |d      d       | j                  |i        t        j                  d      }dd i}t        |d}t        ||       | j                  |d	   j                  |       | j                  |d
   j                  |       | j                  |d	   j                  d   |       | j                  d|d
   j                         y )N__builtins__rH   c                     t        |       S r   )len)ss    r   funcz6FunctionPropertiesTest.test___builtins__.<locals>.funcU   s
    CF]r   abcr$   z\
            def func3(s): pass
            func4 = type(func3)(func3.__code__, {})
        None)typerO   func3func4)rI   r%   rO   r0   rK   rL   rV   rD   rG   r4   textwrapdedentexecassertNotIn)r    rS   nsfunc2codesafe_builtinss         r   test___builtins__z(FunctionPropertiesTest.test___builtins__N   sB   dff))<8TVV^Q,i8	:
 	#T
4=="-e'',e((,7 	uq)R       M:T2bk..>bk..>bk--n=}MG)@)@Ar   c                    dfd}|j                   }| j                  |t               | j                  t	        |      d       | j                  |d   j
                  j                  d       | j                  |d|t               y )N   c                      t                y r   printr!   s   r   fz2FunctionPropertiesTest.test___closure__.<locals>.fo   	    qr      r   cell__closure__)	rl   assertIsInstancetupler4   rQ   	__class__r   r0   rK   r    rh   cr!   s      @r   test___closure__z'FunctionPropertiesTest.test___closure__m   sj    MMa'Q#100&9Qq.Ar   c                    t        j                  d      }| j                  |j                  d       t        j                         }d}| j	                  t
        |      5  |j                   d d d        y # 1 sw Y   y xY w)Nrj   'shouldn't be able to read an empty cell)msg)typesCellTyper4   cell_contentsassertRaises
ValueError)r    cell_objru   s      r   test_cell_newz$FunctionPropertiesTest.test_cell_neww   sh    >>!$//3>>#7zs3 	#""	# 	# 	#s   A55A>c                     fd}	 |j                   d   j                   | j                  d       dy # t        $ r Y dy w xY w)Nc                      t                y r   re   rg   s   r   rh   z1FunctionPropertiesTest.test_empty_cell.<locals>.f   ri   r   r   rt   rc   )rl   rx   r*   rz   )r    rh   r!   s     @r   test_empty_cellz&FunctionPropertiesTest.test_empty_cell   sM    	AMM!** II?@	  	 		s   5 	AAc                    dfd}|j                   }d|d   _        | j                  |d   j                  d       | j                   |       d       | j                  d       |d   `	 |d   j                   | j                  d       | j                  t              5   |        d d d        | j                  t              5  t               d d d        y # t        $ r Y Zw xY w# 1 sw Y   BxY w# 1 sw Y   y xY w)Nrc   c                       S r   r
   rg   s   r   rh   z/FunctionPropertiesTest.test_set_cell.<locals>.f   s    r   	   r   rt   )	rl   rx   r4   r*   rz   ry   	NameErrorUnboundLocalErrorrf   rp   s      @r   test_set_cellz$FunctionPropertiesTest.test_set_cell   s    MM!1++Q/a AaD	AaD II?@y) 	C	01 	!H	 	  			 		 	s*   -C "C+C7	C('C(+C47D c                 H   | j                  | j                  j                  d       d| j                  _        | j                  | j                  j                  d       d| j                  _        | j                  | j                  j                  d       | j                  | j                  ddt               d}t        |di i       | j                  | j                  j                  j                  d       | j                  | j                  j                  ddt               y )	Nr%   rq   dr   r7   zdef f(): pass
f.__name__rO   r!   )	r4   r%   r   r0   rL   r[   r&   r!   rK   )r    rR   s     r   test___name__z$FunctionPropertiesTest.test___name__   s    #.#.#.TVVZI> ,Q$%++S1TWWYY
CHr   c                    | j                  | j                  j                  d       | j                  t        j                  j                  d       | j                  t
        j                  d       | j                  t               j                  d       | j                   t                      j                  d       | j                    t                             j                  d       | j                  t        j                  d       | j                  t               j                  d       d	| j                  _        | j                  | j                  j                  d	       d
| j                  _        | j                  | j                  j                  d
       | j                  | j                  ddt               y )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_function2rq   r   r	   r7   )	r4   r%   r	   r   r'   r   r   r0   rL   r   s    r   test___qualname__z(FunctionPropertiesTest.test___qualname__   sP   ,,.NO,,99;PQ557HI*77<	>**,99B	D,**,.;;V	X.;;=TU.0==?op!,,c2!,,c2TVV^Q	Br   c                 R    d        }d }d }|j                   \  }| j                  |t        j                         | j	                  |j                   |f       ||fD ]  }| j                  |      5  | j	                  |j                   d       | j                  t              5  |` d d d        | j                  t              5  d|_         d d d        |f|_         | j	                  |j                   |f       d d d         y # 1 sw Y   ^xY w# 1 sw Y   ExY w# 1 sw Y   xY w)Nc                      d x}fd cS )Tc                       y r   r
   r
   r   r   genericz<FunctionPropertiesTest.test___type_params__.<locals>.generic   s    $r   r
   )	.defaultsr   s     r   z<generic parameters of generic>zTFunctionPropertiesTest.test___type_params__.<locals>.<generic parameters of generic>   s    Ar   c                       y r   r
   r
   r   r   not_genericz@FunctionPropertiesTest.test___type_params__.<locals>.not_generic   s    4r   c                       y)N.r
   r
   r   r   r   z=FunctionPropertiesTest.test___type_params__.<locals>.<lambda>   s    r   )rS   r
   *   )__type_params__rm   typingTypeVarr4   subTestry   rL   )r    r   r   lambda_r   rS   s         r   test___type_params__z+FunctionPropertiesTest.test___type_params__   s   $$a0001$7 '* 	=D4( =  !5!5r:&&y1 -,-&&y1 .+-D(.()t$  !5!5t<= =	=- -. .	= =s<   32D%D(DD-DD
DDDD&	c                 |   d\  d }d }fd}fd}fd}|||||fD ]5  }| j                  t        |j                        t        j                         7 | j                   |       d       | j                   |       d       |j                  |_        | j                  |j                  |j                         | j                   |       d       	 |j                  |_        | j                  d	       	 |j                  |_        | j                  d	       y # t        $ r Y /w xY w# t        $ r Y y w xY w)
N)r7      c                       y r   r
   r
   r   r   r!   z/FunctionPropertiesTest.test___code__.<locals>.a   s    r   c                       y)Nrc   r
   r
   r   r   r%   z/FunctionPropertiesTest.test___code__.<locals>.b   s    r   c                       S r   r
   )num_ones   r   rq   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   r7   r   zC__code__ with different numbers of free vars should not be possible)r4   rV   rD   rv   CodeTyper*   rz   )	r    r!   r%   rq   r   r   rS   r   r   s	          @@r   test___code__z$FunctionPropertiesTest.test___code__   s   (1aO 	BDT$--0%..A	Ba a ZZ
QZZ0a 	)AJ II ( )	)AJ II ( )  		  		s$   D  =D/  	D,+D,/	D;:D;c                     | j                  | j                  j                  d        | j                  `| j                  | j                  j                  d        y r   )r4   r%   __defaults__r   s    r   test_blank_func_defaultsz/FunctionPropertiesTest.test_blank_func_defaults   s@    ,,d3FF,,d3r   c                    d }dd}| j                  |j                  d        | j                  |j                  d       d|_        | j                  |j                  d       | j                   |       d       | j                   |d      d       | j                   |dd      d       |`| j                  |j                  d        	  |        | j                  d       y # t        $ r Y y w xY w)Nc                     | |z   S r   r
   r!   r%   s     r   
first_funczAFunctionPropertiesTest.test_func_default_args.<locals>.first_func       Q3Jr   c                     | |z   S r   r
   r   s     r   second_funczBFunctionPropertiesTest.test_func_default_args.<locals>.second_func   r   r   )rj   rH   r$      r   zE__defaults__ does not update; deleting it does not remove requirement)r4   r   r*   rL   )r    r   r   s      r   test_func_default_argsz-FunctionPropertiesTest.test_func_default_args   s    		00$7116:"(
00&9q)A*Aq)1-$1148	,M II + ,  		s   
C# #	C/.C/N)r   r   r	   r5   r;   r@   rE   rM   ra   rr   r|   r   r   r   r   r   r   r   r   r
   r   r   r2   r2   .   sW    6D/$:
B>B#(I C(=")<4
,r   r2   c                   $    e Zd Zd Zd Zd Zd Zy)InstancemethodAttrTestc                     | j                  | j                  j                  j                  j                  | j
                         | j                  | j                  j                  d| j
                  t               y )Nro   )r4   r&   r!   __self__ro   r"   r0   rL   r   s    r   test___class__z%InstancemethodAttrTest.test___class__  sJ    ++55tvv>TWWYYTVVYGr   c                    | j                  | j                  j                  j                  | j                  j                         | j                  | j                  j                  d| j                  j                  t               y )N__func__)r4   r&   r!   r   r"   r0   rK   r   s    r   test___func__z$InstancemethodAttrTest.test___func__  sL    ++TVVXX6TWWYY
DFFHHnMr   c                     | j                  | j                  j                  j                  | j                         | j	                  | j                  j                  d| j                  t
               y )Nr   )r4   r&   r!   r   r0   rK   r   s    r   test___self__z$InstancemethodAttrTest.test___self__  sD    ++TWW5TWWYY
DGG^Lr   c                    t        j                  t        | j                        | j                  _        | j	                  | j                  j                         t        | j                               	 | j                  j                  j
                   | j                  d       | j                  | j                  j                  ddt               y # t        $ r Y 8w xY w)N4using unknown attributes should raise AttributeErrorunknown_attrrH   )	rv   
MethodTypeidr&   r4   r   r*   rK   r0   r   s    r   test___func___non_methodz/InstancemethodAttrTest.test___func___non_method  s     %%b$''2
r$''{3	NGGJJ## IILMTWWZZNK  		s   2 C 	CCN)r   r   r	   r   r   r   r   r
   r   r   r   r     s    HNMLr   r   c                       e Zd Zd Zd Zd Zy)ArbitraryFunctionAttrTestc                     d| j                   _        | j                  | j                   j                  d       	 d| j                  j                  _        | j                  d       y # t        $ r Y y w xY w)Nr7   z0setting attributes on methods should raise error)r%   r8   r4   r&   r!   r*   rK   r   s    r   test_set_attrz'ArbitraryFunctionAttrTest.test_set_attr,  sa    **A.	J#$DGGII  IIHI  		s   A& &	A21A2c                 ^    	 | j                   `| j                  d       y # t        $ r Y y w xY w)Nz1deleting unknown attribute should raise TypeError)r%   r   r*   rK   r   s    r   test_delete_unknown_attrz2ArbitraryFunctionAttrTest.test_delete_unknown_attr6  s5    	K# IIIJ  		     	,,c                     | j                   | j                  j                  fD ]   }	 |j                   | j	                  d       " y # t
        $ r Y /w xY w)Nr   )r%   r&   r!   non_existent_attrr*   rK   )r    rS   s     r   test_unset_attrz)ArbitraryFunctionAttrTest.test_unset_attr>  sW    VVTWWYY' 	,D,&& 		 + ,	, " s   A	AAN)r   r   r	   r   r   r   r
   r   r   r   r   +  s    JK,r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)FunctionDictsTestc                     | j                  | j                  dd t               ddlm}  |ddi      }| j                  | j
                  j                  j                  d|t               y )N__dict__r   )UserDictr8   r7   )r0   r%   rL   collectionsr   r&   r!   r   )r    r   r   s      r   test_setting_dict_to_invalidz.FunctionDictsTest.test_setting_dict_to_invalidJ  sN    TVVZyA(lA&'TWWYY//Q	Jr   c                    ddi}|| j                   _        | j                  || j                   j                         || j                  j                  _        | j                  || j
                  j                  j                  j                         | j                  || j
                  j                  j                         | j                  | j                   j                  d       | j                  | j                   j                  d   d       | j                  | j
                  j                  j                  j                  d       | j                  | j
                  j                  j                  d       y )Nr8   r7   )	r%   r   rI   r"   r!   r&   r   r4   r8   )r    r   s     r   test_setting_dict_to_validz,FunctionDictsTest.test_setting_dict_to_validP  s    1a)a++445a++,**A.6:++66:--q1r   c                 ^    	 | j                   `| j                  d       y # t        $ r Y y w xY w)Nz3deleting function dictionary should raise TypeError)r%   r   r*   rL   r   s    r   test_delete___dict__z&FunctionDictsTest.test_delete___dict__`  s4    	M IIKL  		r   c                 P    | j                  | j                  j                  i        y r   )r4   r%   r   r   s    r   test_unassigned_dictz&FunctionDictsTest.test_unassigned_dicth  s    "-r   c                 h    d}i }||| j                   <   | j                  || j                      |       y )NzSome string)r%   r4   )r    r.   r   s      r   test_func_as_dict_keyz'FunctionDictsTest.test_func_as_dict_keyk  s1    $&&	466E*r   N)r   r   r	   r   r   r   r   r   r
   r   r   r   r   I  s    K2 M.+r   r   c                       e Zd Zd Zd Zy)FunctionDocstringTestc                    | j                  | j                  j                  d        d}|| j                  _        || j                  j                  _        | j                  | j                  j                  |       | j                  | j
                  j                  j                  |       | j                  | j
                  j                  d|t               y )NzA test method that does nothing__doc__)r4   r%   r   r"   r!   r&   r0   rK   )r    docstrs     r   test_set_docstring_attrz-FunctionDocstringTest.test_set_docstring_attrs  s    .2!0**F3TWWYY	6>Jr   c                     d| j                   _        | j                   `| j                  | j                   j                  d        y )NzThe docstring)r%   r   r4   r   s    r   test_delete_docstringz+FunctionDocstringTest.test_delete_docstring|  s.    (FFN.r   N)r   r   r	   r   r   r
   r   r   r   r   r  s    K/r   r   c                 0    fd}| |j                   d   S )z)Create a cell containing the given value.c                      t                y r   re   rg   s   r   rh   zcell.<locals>.f  
    ar   r   rl   )r.   rh   r!   s     @r   rk   rk     s    A==r   c                 4    fd}| sd|j                   d   S )zCreate an empty cell.c                      t                y r   re   rg   s   r   rh   zempty_cell.<locals>.f  r   r   i  r   r   )emptyrh   r!   s     @r   
empty_cellr     s!    
 ==r   c                       e Zd Zd Zy)CellTestc                 x   | j                  t        d      t        d      k         | j                  t               t        d      k         | j                  t               t               k(         | j                  t        d      t        d      k(         | j                  t        d      t               kD         y )NrH   r$   saturdayig      BT)
assertTruerk   r   r   s    r   test_comparisonzCellTest.test_comparison  sz    
 	Q$q')*
tJ'778

45S	T%[01T
Z\12r   N)r   r   r	   r   r
   r   r   r   r     s    	3r   r   c                       e Zd Zd Zy)StaticMethodAttrsTestc                     d }t        |      }| j                  |j                  |u        t        |      }| j                  |j                  |u        y )Nc                       y r   r
   r
   r   r   rh   z4StaticMethodAttrsTest.test_func_attribute.<locals>.f  s    r   )classmethodr   r   staticmethod)r    rh   rq   rR   s       r   test_func_attributez)StaticMethodAttrsTest.test_func_attribute  sC    	 N

a(O

a(r   N)r   r   r	   r   r
   r   r   r   r     s    )r   r   c                       e Zd Zd Zy)BuiltinFunctionPropertiesTestc                    dd l }| j                  t        j                  d       | j                  |j                   j                  d       | j                  t        j
                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  g dj                  j                  d	       | j                  d
dij                  j                  d       y )Nr   rQ   timezdict.fromkeyszfloat.__getformat__zstr.maketranszbytes.maketrans)rj   rH   r$   zlist.appendfoobarzdict.pop)r   r4   rQ   r	   dictfromkeysfloat__getformat__str	maketransbytesappendpop)r    r   s     r   test_builtin__qualname__z6BuiltinFunctionPropertiesTest.test_builtin__qualname__  s     	))51//8 	33_E,,99.	0 	33_E557HI 	))66F%++88*Er   N)r   r   r	   r	  r
   r   r   r   r     s    Fr   r   __main__)T)rY   rv   r   unittestr   TestCaser   r2   r   r   r   r   rk   r   r   r   r   r   mainr
   r   r   <module>r     s       
"<H%% <4\,] \,~L] L<, ,<&+ &+R/M / 	
3x   
3	)H-- 	)FH$5$5 F2 zHMMO r   