
    daf:                         d dl Z d dlmZ d Z G d de      Z G d de      ZddZd	 Z	d
 Z
 G d de j                        Z G d de j                        Zedk(  r e j                          yy)    N)
MethodTypec                        fd}|S )Nc                 >    | j                   j                         | S N)__dict__update)funckwdss    //root/Python-3.12.4/Lib/test/test_decorators.pydecoratezfuncattrs.<locals>.decorate   s    T"     )r
   r   s   ` r   	funcattrsr      s     Or   c                       e Zd Zed        Zy)MiscDecoratorsc                       fd}|S )Nc                 &    | j                   d<   | S )Nauthor)r   )r	   names    r   r   z'MiscDecorators.author.<locals>.decorate   s    &*DMM(#Kr   r   )r   r   s   ` r   r   zMiscDecorators.author   s    	 r   N)__name__
__module____qualname__staticmethodr   r   r   r   r   r   
   s     r   r   c                       e Zd Zd Zy)DbcheckErrorc                 J    t         j                  | d|d|d|d|d	       y )Nzdbcheck z failed (func=z args=z kwds=))	Exception__init__)selfexprstrr	   argsr
   s        r   r   zDbcheckError.__init__   s     4#T4"7 	8r   N)r   r   r   r   r   r   r   r   r      s    8r   r   c                       fd}|S )z+Decorator to implement debugging assertionsc                 R     t        d j                  z  d       fd}|S )Nz
dbcheck-%sevalc                  J    t              st        | |       | i |S r   )r%   r   )r"   r
   exprr!   r	   globalslocalss     r   checkz(dbcheck.<locals>.decorate.<locals>.check   s0    gv."7D$==&&&r   )compiler   )r	   r*   r'   r!   r(   r)   s   ` @r   r   zdbcheck.<locals>.decorate   s+    wt}} <fE	' 	' r   r   )r!   r(   r)   r   s   ``` r   dbcheckr,      s     Or   c                       fd}|S )z&Decorator to count calls to a functionc                 J      j                   d<    fd}|_         |S )Nr   c                  .    xx   dz  cc<    | i |S )N   r   )r"   r
   countsr	   	func_names     r   callz*countcalls.<locals>.decorate.<locals>.call-   s#    9"&&&r   r   )r	   r3   r2   r1   s   ` @r   r   zcountcalls.<locals>.decorate*   s)    MM	y	' "r   r   )r1   r   s   ` r   
countcallsr5   (   s     Or   c                 <     i  fd} j                   |_         |S )Nc                  d    	 |    S # t         $ r  |  }|| <   |cY S t        $ r  |  cY S w xY wr   )KeyError	TypeError)r"   resr	   saveds     r   r3   zmemoize.<locals>.call8   sJ    	; 	+CE$KJ 	;	s    ///r4   )r	   r3   r;   s   ` @r   memoizer<   6   s    E	 MMDMKr   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)TestDecoratorsc                      G d dt               }| j                  |j                         d       | j                   |       j                         d       y )Nc                       e Zd Zed        Zy)%TestDecorators.test_single.<locals>.Cc                       yN*   r   r   r   r   fooz)TestDecorators.test_single.<locals>.C.fooK   s     r   N)r   r   r   r   rE   r   r   r   CrA   J   s       r   rF   rD   )objectassertEqualrE   r    rF   s     r   test_singlezTestDecorators.test_singleI   s>    	! 	! 	"%B'r   c                 :   d } ||      }| j                  |j                  |       | j                  |j                  |       dD ](  }| j                  t        ||      t        ||             * | j	                  t        |      |j                  |             |S )Nc                     | S r   r   xs    r   r	   z0TestDecorators.check_wrapper_attrs.<locals>.funcQ   s    Hr   )r   r   r   __doc____annotations__)assertIs__func____wrapped__getattrrH   reprformat)r    method_wrapper
format_strr	   wrapperattrs         r   check_wrapper_attrsz"TestDecorators.check_wrapper_attrsP   s    	 &g&&-g))403 	/DMM''40!$-/	/
 	g
(9(9$(?@r   c                 `    | j                  t        d      }| j                   |d      d       y )Nz<staticmethod({!r})>r0   )r[   r   rH   r    rY   s     r   test_staticmethodz TestDecorators.test_staticmethod`   s+    **<9OP 	Q'r   c                 ^    | j                  t        d      }| j                  t        |d       y )Nz<classmethod({!r})>r0   )r[   classmethodassertRaisesr9   r]   s     r   test_classmethodzTestDecorators.test_classmethodf   s'    **;8MN)Wa0r   c                     t               }|j                  d      d        }| j                   |       d       | j                  |j                  d       y )NCleesec                       yrC   r   r   r   r   rE   z'TestDecorators.test_dotted.<locals>.foom   s    r   rD   )r   r   rH   )r    
decoratorsrE   s      r   test_dottedzTestDecorators.test_dottedk   sI    #%
			8	$ 
%#X.r   c                    d }d}t        dd      } ||i |d        }| j                   |       d       | j                  |j                  ||f        |dd	d
d      d        }| j                   |       d       | j                  |j                  dt        d
d      f        |dd      d        }| j                  |j                  di f       y )Nc                        fd}|S )Nc                 &    t        | df       | S )Ndbval)setattr)r	   r"   r
   s    r   r   z@TestDecorators.test_argforms.<locals>.noteargs.<locals>.decoratew   s    gd|4r   r   )r"   r
   r   s   `` r   noteargsz.TestDecorators.test_argforms.<locals>.noteargsv   s     Or   )Nowisthetimer0      )onetwoc                       yrC   r   r   r   r   f1z(TestDecorators.test_argforms.<locals>.f1~       r   rD   terrygilliamidlecleese)ericjohnc                       y)NT   r   r   r   r   f2z(TestDecorators.test_argforms.<locals>.f2   rw   r   r   )rx   ry   c                       y r   r   r   r   r   f3z(TestDecorators.test_argforms.<locals>.f3   s    r   )r0   rr   )dictrH   rk   )r    rm   r"   r
   rv   r   r   s          r   test_argformszTestDecorators.test_argformsr   s    	 .q!	4	 4	  
!r"D$<0	'96	A 
Br"$8%)vH%E$G 	H 
!Q 
FB<0r   c                     t        d      d        }| j                   |dd      d       | j                  t        |dd        y )Nzargs[1] is not Nonec                     | |z   S r   r   )abs     r   fz&TestDecorators.test_dbcheck.<locals>.f   s    q5Lr   r0   rr      )r,   rH   ra   r   )r    r   s     r   test_dbcheckzTestDecorators.test_dbcheck   sD    	&	'	 
(	1a!$,1d3r   c                 z   i }t         t        |      d               }| j                  |j                  d       | j                  |t	        d             | j                   |d      d       | j                  |d   d       | j                   |d      d       | j                  |d   d       | j                   |d      d	       | j                  |d   d       | j                   |d
g      d
d
g       | j                  |d   d       | j                   |d
g      d
d
g       | j                  |d   d       y )Nc                     | dz  S )Nrr   r   rM   s    r   doublez+TestDecorators.test_memoize.<locals>.double   s     q5Lr   r   r   )r   rr      r0   r      
   )r<   r5   rH   r   r   )r    r1   r   s      r   test_memoizezTestDecorators.test_memoize   s+   		F		 
 
	(3Q0 	A&)1-A&)1-A&)1- 	Bx0)1-Bx0)1-r   c                    dD ]>  }t        |dd       | j                  t              5  t        d| ddd       d d d        @ dD ]<  }t        |dd       | j                  t              5  t	        d| d       d d d        > d }t        d |	      }d
t        fdt        fdt        fdt        ffD ]/  \  }}d|z  }t        |dd      }| j                  |t        ||       1 y # 1 sw Y   xY w# 1 sw Y   xY w)N)zx,zx, yzx = ypassz
import systestexec@
def f(): pass)z1.+2jz
[1, 2][-1]z(1, 2)Truez...Noner%   c                     t         r   )NotImplementedErrorr	   s    r   unimpz)TestDecorators.test_errors.<locals>.unimp   s    %%r   )nullvalr   undefr   znullval.attrr   z$@%s
def f(): pass
assert f() is None)
r+   ra   SyntaxErrorr9   r   r   	NameErrorAttributeErrorr   r%   )r    stmtr'   r   contextexccodestrcodes           r   test_errorszTestDecorators.test_errors   s0    B 	CDD&&)"";/ C!D6166BC C	C M 	0DD&&)""9- 0qo./0 0	0
	&t51#Y/%y1*N;#%89; 	8ID# ?EG7FF3Dc4w7	8C C0 0s   C&+C2&C/	2C;	c                 4    dD ]  }t        d| ddd        y )N)z(x,)z(x, y)zx := yz(x := y)zx @yz(x @ y)zx[0]zw[x].y.zzw + x - (y + z)z	x(y)()(z)z[w, x, y][z]zx.yr   r   r   r   )r+   )r    r'   s     r   test_expressionszTestDecorators.test_expressions   s*    
 	?D av_-vv>		?r   c                 P    G d dt               }| j                   |       j                         d       | j                  |j                  j                  d       | j                  |j                  j                  d       | j                  |j                  j
                  d       y )Nc                   D    e Zd Z edd       ed      d               Zy)%TestDecorators.test_double.<locals>.Cr0   haha)abcxyzrD   )boohc                      yrC   r   )r    s    r   rE   z)TestDecorators.test_double.<locals>.C.foo   s    "$r   N)r   r   r   r   rE   r   r   r   rF   r      s$    1&)B$   *$r   rF   rD   r0   r   )rG   rH   rE   r   r   r   rI   s     r   test_doublezTestDecorators.test_double   sp    	% 	% 	B'A&F+R(r   c                 l    d } |d       |d      d               }| j                   |       dd       y )Nc                       fd}|S )zDecorator factory that returns a decorator that replaces the
            passed-in function with one that returns the value of 'num'c                     fdS )Nc                       S r   r   )nums   r   <lambda>zJTestDecorators.test_order.<locals>.callnum.<locals>.deco.<locals>.<lambda>   s    s r   r   )r	   r   s    r   decoz8TestDecorators.test_order.<locals>.callnum.<locals>.deco   s	    ""r   r   )r   r   s   ` r   callnumz*TestDecorators.test_order.<locals>.callnum   s    #Kr   rr   r0   c                       yrC   r   r   r   r   rE   z&TestDecorators.test_order.<locals>.foo   s    r   z,Application order of decorators is incorrect)rH   )r    r   rE   s      r   
test_orderzTestDecorators.test_order   s?    	 
	 
 
J	Lr   c                   	 g fd	 G 	fddt               }t        |g d      \  }}}g d}g |j                  |j                        |j                  |j                        |j                  |j                        d                      }| j	                   |       d       | j	                  |       g d } |j                  |j                         |j                  |j                         |j                  |j                        |                  }| j	                   |       d       | j	                  |       y )	Nc                 >     j                  d z           fd}|S )Nmakedecc                 0    j                  dz          | S )Ncalldecappend)r	   actionstags    r   r   zHTestDecorators.test_eval_order.<locals>.make_decorator.<locals>.decorate   s    y3/r   r   )r   r   r   s   ` r   make_decoratorz6TestDecorators.test_eval_order.<locals>.make_decorator   s    NN9s?+ Or   c                        e Zd Zd Z fdZy)8TestDecorators.test_eval_order.<locals>.NameLookupTracerc                     || _         y r   )index)r    r   s     r   r   zATestDecorators.test_eval_order.<locals>.NameLookupTracer.__init__  s	    "
r   c                     |dk(  rd}}n'|dk(  rdt        | j                        }}n
J d|z         j                  d|| j                  fz         |S )Nr   evalnameargevalargszUnknown attrname %sz%s%d)strr   r   )r    fnameopnamer:   r   r   s       r   __getattr__zDTestDecorators.test_eval_order.<locals>.NameLookupTracer.__getattr__  s\    ,,#-~CFe^#-s4::CF?"7%"??5v(<<=
r   N)r   r   r   r   r   )r   r   s   r   NameLookupTracerr      s    #r   r   )r0   rr   r   )	evalname1	evalargs1makedec1	evalname2	evalargs2makedec2	evalname3	evalargs3makedec3calldec3calldec2calldec1c                       yrC   r   r   r   r   rE   z+TestDecorators.test_eval_order.<locals>.foo  s     r   rD   c                       yrC   r   r   r   r   barz+TestDecorators.test_eval_order.<locals>.bar!  s    "r   )rG   mapr   r   rH   )
r    r   c1c2c3expected_actionsrE   r   r   r   s
           @@r   test_eval_orderzTestDecorators.test_eval_order   s*    		 	 );7
BB
 			266	"			266	"			266	" 
# 
# 
# 	#"23 'b'(A(9(9"&&(AB["BSBSTVTZTZB[\_B`(ab#"23r   c                 l    G d d       G fdd      fd G fdd      }| j                  |j                         d       | j                  |j                         d	       | j                   |       j                         d       | j                   |       j                         d	       y )
Nc                       e Zd Zd Zd Zy)OTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.BoundWrapperc                     || _         y r   rS   r    wrappeds     r   r   zXTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.BoundWrapper.__init__(  
    #* r   c                 &     | j                   |i |S r   r   )r    r"   kwargss      r   __call__zXTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.BoundWrapper.__call__+  s    't''888r   N)r   r   r   r   r   r   r   r   BoundWrapperr   '  s    +9r   r   c                       e Zd Zd Z fdZy)JTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Wrapperc                     || _         y r   r   r   s     r   r   zSTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Wrapper.__init__/  r   r   c                 L    | j                   j                  ||      } |      S r   )rS   __get__)r    instanceownerbound_functionr   s       r   r   zRTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Wrapper.__get__2  s&    !%!1!1!9!9(E!J#N33r   N)r   r   r   r   r   )r   s   r   Wrapperr   .  s    +4r   r   c                      |       S r   r   )r   r   s    r   	decoratorzLTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.decorator6  s    7##r   c                   F    e Zd ZW  ed               ZeW  d               Zy)HTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Classc                      yNspamr   clss    r   innerzNTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Class.inner:  s     r   c                      y)Neggsr   r  s    r   outerzNTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Class.outer@  s    
 r   N)r   r   r   r`   r	  r  )r  s   r   Classr  9  s9         r   r  r  r  )rH   r	  r  )r    r  r   r   r  s     @@@r   *test_wrapped_descriptor_inside_classmethodz9TestDecorators.test_wrapped_descriptor_inside_classmethod&  s    	9 	9	4 	4	$	 	 	//&1&1r   c                 r     G d d       G fdd      }| j                  |j                         d       y )Nc                       e Zd Zd Zy)@TestDecorators.test_bound_function_inside_classmethod.<locals>.Ac                      yr  r   r    r  s     r   rE   zDTestDecorators.test_bound_function_inside_classmethod.<locals>.A.fooN  s    r   N)r   r   r   rE   r   r   r   Ar  M  s    r   r  c                   >    e Zd Z e W         j                        Zy)@TestDecorators.test_bound_function_inside_classmethod.<locals>.BN)r   r   r   r`   rE   r   )r  s   r   Br  Q  s    acgg&Cr   r  r  )rH   r   )r    r  r  s     @r   &test_bound_function_inside_classmethodz5TestDecorators.test_bound_function_inside_classmethodL  s/    	 		' 	' 	&)r   c                 |    G d d       G d d      fD ]   G fdd      }| j                  |j                         |       | j                  |j                         |       | j                  |j                         |       | j                  |j	                         |       | j                  |j                         |       | j                  |j                         |        |       }| j                  |j                         |       | j                  |j                         |       | j                  |j                         |       | j                  |j	                         |       | j                  |j                         |       | j                  |j                         |       d }| j                    |      j                  |             |       | j                    |      j                  ||             |       | j                    |      j                  ||             |       | j                    |      j                  |             t        |             | j                   t        |      j                  |             |       | j                   t        |      j                  ||             |       | j                   t        |      j                  ||             |       | j                   t        |      j                  |             t        |               y )Nc                        e Zd Zd Zd ZddZy)RTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod1c                     || _         y r   r   r    r	   s     r   r   z[TestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod1.__init__X  s	     	r   c                     t        | j                  d      r! | j                  j                  ||             S | j                  |      S )Nr   )hasattrr	   r   r  s     r   r   z[TestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod1.__call__[  s:    499i06499,,S#688yy~%r   Nc                 4    |t        |      }t        | |      S r   typer   r    r   r   s      r   r   zZTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod1.__get__`      = NE!$..r   r   r   r   r   r   r   r   r   r   r   MyClassMethod1r  W  s    !&
/r   r&  c                        e Zd Zd Zd ZddZy)RTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod2c                 J    t        |t              r|j                  }|| _        y r   )
isinstancer`   rR   r	   r  s     r   r   z[TestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod2.__init__f  s    dK0==D 	r   c                 $    | j                  |      S r   r   r  s     r   r   z[TestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod2.__call__k  s    yy~%r   Nc                 4    |t        |      }t        | |      S r   r!  r#  s      r   r   zZTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.MyClassMethod2.__get__n  r$  r   r   r%  r   r   r   MyClassMethod2r(  e  s    !
&/r   r-  c                       e Zd ZW d        ZeW d               ZW ed               Zeed               ZW W  d               ZW W d               Z	y)ETestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.Ac                     | S r   r   r  s    r   rv   zHTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.A.f1u  s    Jr   c                     | S r   r   r  s    r   r   zHTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.A.f2y  	     Jr   c                     | S r   r   r  s    r   r   zHTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.A.f3~  r2  r   c                     | S r   r   r  s    r   f4zHTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.A.f4  r2  r   c                     | S r   r   r  s    r   f5zHTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.A.f5  r2  r   c                     | S r   r   r  s    r   f6zHTestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.A.f6  r2  r   N)
r   r   r   rv   r`   r   r   r5  r7  r9  )r&  r-  myclassmethods   r   r  r/  t  s                      r   r  c                     | S r   r   r  s    r   r   zETestDecorators.test_wrapped_classmethod_inside_classmethod.<locals>.f  s    
r   )
rQ   rv   r   r   r5  r7  r9  r   r"  r`   )r    r  r   r   r&  r-  r:  s       @@@r   +test_wrapped_classmethod_inside_classmethodz:TestDecorators.test_wrapped_classmethod_inside_classmethodV  sf   	/ 	/	/ 	/ -n= 7	@M < MM!$$&!$MM!$$&!$MM!$$&!$MM!$$&!$MM!$$&!$MM!$$&!$AMM!$$&!$MM!$$&!$MM!$$&!$MM!$$&!$MM!$$&!$MM!$$&!$ MM5-*22157;MM8-*221a8:A>MM8-*221a8:A>MM5-*22157aAMM3+a.0035q9MM6+a.00A68!<MM6+a.00A68!<MM3+a.0035tAw?o7	@r   N)r   r   r   rJ   r[   r^   rb   rg   r   r   r   r   r   r   r   r   r  r  r<  r   r   r   r>   r>   G   sW    ( (1
/164.684?)L;4z$2L*T@r   r>   c                       e Zd Zd Zd Zd Zy)TestClassDecoratorsc                 j    d }| G d dt                      }| j                  |j                  d       y )Nc                     d| _         | S )NHelloextrarM   s    r   plainz.TestClassDecorators.test_simple.<locals>.plain      AGHr   c                       e Zd Zy)*TestClassDecorators.test_simple.<locals>.CNr   r   r   r   r   r   rF   rG    s    r   rF   rA  rG   rH   rC  )r    rD  rF   s      r   test_simplezTestClassDecorators.test_simple  s0    	 
 
'*r   c                 z    d }d }|| G d dt                             }| j                  |j                  d       y )Nc                     d| _         | S )Nr   rB  rM   s    r   tenz,TestClassDecorators.test_double.<locals>.ten  s    AGHr   c                 0    | xj                   dz  c_         | S )N   rB  rM   s    r   add_fivez1TestClassDecorators.test_double.<locals>.add_five  s    GGqLGHr   c                       e Zd Zy)*TestClassDecorators.test_double.<locals>.CNrH  r   r   r   rF   rR        r   rF      rI  )r    rM  rP  rF   s       r   r   zTestClassDecorators.test_double  s=    		 
	 
 
"%r   c                 z    d }d }|| G d dt                             }| j                  |j                  d       y )Nc                     d| _         | S )NfirstrB  rM   s    r   applied_firstz5TestClassDecorators.test_order.<locals>.applied_first  rE  r   c                     d| _         | S )NsecondrB  rM   s    r   applied_secondz6TestClassDecorators.test_order.<locals>.applied_second  s    AGHr   c                       e Zd Zy))TestClassDecorators.test_order.<locals>.CNrH  r   r   r   rF   r]    rS  r   rF   rZ  rI  )r    rX  r[  rF   s       r   r   zTestClassDecorators.test_order  s=    		 
	 
 
(+r   N)r   r   r   rJ  r   r   r   r   r   r>  r>    s    +&
,r   r>  __main__)NN)unittesttypesr   r   rG   r   r   r   r,   r5   r<   TestCaser>   r>  r   mainr   r   r   <module>rc     s{     f 8I 8	
"c@X&& c@J!,(++ !,F zHMMO r   