a
    3j+                     @   s   d dl Z dd ZG dd deZG dd deZddd	Zd
d Zdd ZG dd de j	Z
G dd de j	Zedkr~e   dS )    Nc                     s    fdd}|S )Nc                    s   | j   | S N)__dict__updatefunckwds P/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_decorators.pydecorate   s    zfuncattrs.<locals>.decorater	   )r   r   r	   r   r
   	funcattrs   s    r   c                   @   s   e Zd Zedd ZdS )MiscDecoratorsc                    s    fdd}|S )Nc                    s    | j d< | S )Nauthor)r   r   namer	   r
   r      s    
z'MiscDecorators.author.<locals>.decorater	   )r   r   r	   r   r
   r   
   s    zMiscDecorators.authorN)__name__
__module____qualname__staticmethodr   r	   r	   r	   r
   r   	   s   r   c                   @   s   e Zd Zdd ZdS )DbcheckErrorc                 C   s   t | d||||f  d S )Nz+dbcheck %r failed (func=%s args=%s kwds=%s))	Exception__init__)selfexprstrr   argsr   r	   r	   r
   r      s    
zDbcheckError.__init__N)r   r   r   r   r	   r	   r	   r
   r      s   r   c                    s    fdd}|S )z+Decorator to implement debugging assertionsc                    s*   t dj d  fdd}|S )Nz
dbcheck-%sevalc                     s(   t  st| || i |S r   )r   r   r   r   )exprr   r   globalslocalsr	   r
   check   s    z(dbcheck.<locals>.decorate.<locals>.check)compiler   )r   r    r   r   r   )r   r   r
   r      s    zdbcheck.<locals>.decorater	   )r   r   r   r   r	   r"   r
   dbcheck   s    r#   c                    s    fdd}|S )z&Decorator to count calls to a functionc                    s(    j d<  fdd}|_ |S )Nr   c                     s      d7  < | i |S )N   r	   r   )countsr   	func_namer	   r
   call,   s    z*countcalls.<locals>.decorate.<locals>.callr   r   r'   r%   )r   r&   r
   r   )   s
    zcountcalls.<locals>.decorater	   )r%   r   r	   r*   r
   
countcalls'   s    r+   c                    s   i  fdd} j |_ |S )Nc                     sN   z
|  W S  t y0    |  }|| < | Y S  tyH    |   Y S 0 d S r   )KeyError	TypeError)r   resr   Zsavedr	   r
   r'   7   s    
zmemoize.<locals>.callr(   r)   r	   r/   r
   memoize5   s    
r0   c                   @   sl   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )TestDecoratorsc                 C   s6   G dd dt }| | d | |  d d S )Nc                   @   s   e Zd Zedd ZdS )z%TestDecorators.test_single.<locals>.Cc                   S   s   dS N*   r	   r	   r	   r	   r
   fooJ   s    z)TestDecorators.test_single.<locals>.C.fooN)r   r   r   r   r4   r	   r	   r	   r
   CI   s   r5   r3   )objectassertEqualr4   r   r5   r	   r	   r
   test_singleH   s    zTestDecorators.test_singlec                 C   s   t dd }| t|d d S )Nc                 S   s   | S r   r	   xr	   r	   r
   
notamethodP   s    z=TestDecorators.test_staticmethod_function.<locals>.notamethodr$   )r   assertRaisesr-   )r   r<   r	   r	   r
   test_staticmethod_functionO   s    
z)TestDecorators.test_staticmethod_functionc                 C   s8   t  }|ddd }| | d | |jd d S )NZCleesec                   S   s   dS r2   r	   r	   r	   r	   r
   r4   W   s    z'TestDecorators.test_dotted.<locals>.foor3   )r   r   r7   )r   Z
decoratorsr4   r	   r	   r
   test_dottedU   s
    
zTestDecorators.test_dottedc                 C   s   dd }d}t ddd}||i |dd }| | d	 | |j||f |d
dddddd }| | d | |jdt dddf |dddd }| |jdi f d S )Nc                     s    fdd}|S )Nc                    s   t | d f | S )Ndbval)setattrr   r   r	   r
   r   a   s    z@TestDecorators.test_argforms.<locals>.noteargs.<locals>.decorater	   )r   r   r   r	   r   r
   noteargs`   s    z.TestDecorators.test_argforms.<locals>.noteargs)ZNowisZthetimer$      )ZoneZtwoc                   S   s   dS r2   r	   r	   r	   r	   r
   f1h   s    z(TestDecorators.test_argforms.<locals>.f1r3   terrygilliamZidleZcleese)ZericZjohnc                   S   s   dS )NT   r	   r	   r	   r	   r
   f2m   s    z(TestDecorators.test_argforms.<locals>.f2rI   )rG   rH   c                   S   s   d S r   r	   r	   r	   r	   r
   f3s   s    z(TestDecorators.test_argforms.<locals>.f3)r$   rE   )dictr7   r@   )r   rB   r   r   rF   rJ   rK   r	   r	   r
   test_argforms\   s     




zTestDecorators.test_argformsc                 C   s6   t ddd }| |ddd | t|dd  d S )Nzargs[1] is not Nonec                 S   s   | | S r   r	   )abr	   r	   r
   fx   s    z&TestDecorators.test_dbcheck.<locals>.fr$   rE      )r#   r7   r=   r   )r   rP   r	   r	   r
   test_dbcheckw   s    
zTestDecorators.test_dbcheckc                 C   s   i }t t|dd }| |jd | |tdd | |dd | |d d | |dd | |d d | |d	d
 | |d d | |dgddg | |d d	 | |dgddg | |d d d S )Nc                 S   s   | d S )NrE   r	   r:   r	   r	   r
   double   s    z+TestDecorators.test_memoize.<locals>.doublerS   r   )rS   rE      r$   rQ      
   )r0   r+   r7   r   rL   )r   r%   rS   r	   r	   r
   test_memoize~   s     zTestDecorators.test_memoizec              	   C   s  dD ]N}t |dd | t$ t d| ddd W d    q1 sH0    Y  qdD ]J}t |dd | t  td| d W d    qX1 s0    Y  qXdd	 }td |d
}dtfdtfdtfdtffD ],\}}d| }t |dd}| |t	|| qd S )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                 S   s   t d S r   )NotImplementedErrorr   r	   r	   r
   unimp   s    z)TestDecorators.test_errors.<locals>.unimp)nullvalr`   Zundefra   znullval.attrr`   z$@%s
def f(): pass
assert f() is None)
r!   r=   SyntaxErrorr-   rZ   rL   	NameErrorAttributeErrorr_   r   )r   Zstmtr   r`   contextexcZcodestrcoder	   r	   r
   test_errors   s$    40zTestDecorators.test_errorsc                 C   s"   dD ]}t d| ddd qd S )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\   rY   rZ   )r!   )r   r   r	   r	   r
   test_expressions   s    zTestDecorators.test_expressionsc                 C   sV   G dd dt }| |  d | |jjd | |jjd | |jjd d S )Nc                   @   s*   e Zd Zedddedddd ZdS )	z%TestDecorators.test_double.<locals>.Cr$   haha)abcxyzr3   )boohc                 S   s   dS r2   r	   )r   r	   r	   r
   r4      s    z)TestDecorators.test_double.<locals>.C.fooN)r   r   r   r   r4   r	   r	   r	   r
   r5      s   
r5   r3   r$   rj   )r6   r7   r4   rk   rl   rm   r8   r	   r	   r
   test_double   s
    zTestDecorators.test_doublec                 C   s4   dd }|d|ddd }|  | dd d S )Nc                    s    fdd}|S )zDecorator factory that returns a decorator that replaces the
            passed-in function with one that returns the value of 'num'c                    s    fddS )Nc                      s    S r   r	   r	   numr	   r
   <lambda>       zJTestDecorators.test_order.<locals>.callnum.<locals>.deco.<locals>.<lambda>r	   r   ro   r	   r
   deco   s    z8TestDecorators.test_order.<locals>.callnum.<locals>.decor	   )rp   rs   r	   ro   r
   callnum   s    z*TestDecorators.test_order.<locals>.callnumrE   r$   c                   S   s   dS r2   r	   r	   r	   r	   r
   r4      s    z&TestDecorators.test_order.<locals>.fooz,Application order of decorators is incorrect)r7   )r   rt   r4   r	   r	   r
   
test_order   s    
zTestDecorators.test_orderc                    s   g   fddG  fdddt }t|g d\}}}g d}g  ||j||j||jdd }| | d	 |  | g  d
d }||j||j||j|}| | d	 |  | d S )Nc                    s     d    fdd}|S )NZmakedecc                    s     d  | S )NZcalldecappendr   )actionstagr	   r
   r      s    zHTestDecorators.test_eval_order.<locals>.make_decorator.<locals>.decoraterv   )ry   r   )rx   )ry   r
   make_decorator   s    z6TestDecorators.test_eval_order.<locals>.make_decoratorc                       s"   e Zd Zdd Z fddZdS )z8TestDecorators.test_eval_order.<locals>.NameLookupTracerc                 S   s
   || _ d S r   )index)r   r{   r	   r	   r
   r      s    zATestDecorators.test_eval_order.<locals>.NameLookupTracer.__init__c                    sV   |dkrd }}n*|dkr.dt | j }}nds>J d|  d|| jf  |S )Nrz   ZevalnameargZevalargsFzUnknown attrname %sz%s%d)strr{   rw   )r   Zfnameopnamer.   rx   rz   r	   r
   __getattr__   s    zDTestDecorators.test_eval_order.<locals>.NameLookupTracer.__getattr__N)r   r   r   r   r   r	   r   r	   r
   NameLookupTracer   s   r   )r$   rE   rQ   )Z	evalname1Z	evalargs1Zmakedec1Z	evalname2Z	evalargs2Zmakedec2Z	evalname3Z	evalargs3Zmakedec3Zcalldec3Zcalldec2Zcalldec1c                   S   s   dS r2   r	   r	   r	   r	   r
   r4      s    z+TestDecorators.test_eval_order.<locals>.foor3   c                   S   s   dS r2   r	   r	   r	   r	   r
   bar  rr   z+TestDecorators.test_eval_order.<locals>.bar)r6   maprz   r|   r7   )r   r   c1c2Zc3Zexpected_actionsr4   r   r	   r   r
   test_eval_order   s"    


(zTestDecorators.test_eval_orderc                    s   G dd d G  fdddfddG fddd}|  | d	 |  | d
 |  |  d	 |  |  d
 d S )Nc                   @   s   e Zd Zdd Zdd ZdS )zOTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.BoundWrapperc                 S   s
   || _ d S r   __wrapped__r   wrappedr	   r	   r
   r     s    zXTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.BoundWrapper.__init__c                 _   s   | j |i |S r   r   )r   r   kwargsr	   r	   r
   __call__  s    zXTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.BoundWrapper.__call__N)r   r   r   r   r   r	   r	   r	   r
   BoundWrapper  s   r   c                       s    e Zd Zdd Z fddZdS )zJTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Wrapperc                 S   s
   || _ d S r   r   r   r	   r	   r
   r     s    zSTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Wrapper.__init__c                    s   | j ||} |S r   )r   __get__)r   instanceownerZbound_functionr   r	   r
   r     s    zRTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Wrapper.__get__N)r   r   r   r   r   r	   r   r	   r
   Wrapper  s   r   c                    s    | S r   r	   )r   )r   r	   r
   	decorator   s    zLTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.decoratorc                       s,   e Zd Z edd Ze dd ZdS )zHTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Classc                 S   s   dS )Nspamr	   clsr	   r	   r
   inner$  s    zNTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Class.innerc                 S   s   dS )Neggsr	   r   r	   r	   r
   outer*  s    zNTestDecorators.test_wrapped_descriptor_inside_classmethod.<locals>.Class.outerN)r   r   r   classmethodr   r   r	   )r   r	   r
   Class#  s   r   r   r   )r7   r   r   )r   r   r	   )r   r   r   r
   *test_wrapped_descriptor_inside_classmethod  s    z9TestDecorators.test_wrapped_descriptor_inside_classmethodN)r   r   r   r9   r>   r?   rM   rR   rW   rh   ri   rn   ru   r   r   r	   r	   r	   r
   r1   F   s   
=r1   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestClassDecoratorsc                 C   s.   dd }|G dd dt }| |jd d S )Nc                 S   s
   d| _ | S )NHelloextrar:   r	   r	   r
   plain:  s    z.TestClassDecorators.test_simple.<locals>.plainc                   @   s   e Zd ZdS )z*TestClassDecorators.test_simple.<locals>.CNr   r   r   r	   r	   r	   r
   r5   =  s   r5   r   r6   r7   r   )r   r   r5   r	   r	   r
   test_simple9  s    zTestClassDecorators.test_simplec                 C   s:   dd }dd }||G dd dt }| |jd d S )Nc                 S   s
   d| _ | S )NrV   r   r:   r	   r	   r
   tenB  s    z,TestClassDecorators.test_double.<locals>.tenc                 S   s   |  j d7  _ | S )N   r   r:   r	   r	   r
   add_fiveE  s    z1TestClassDecorators.test_double.<locals>.add_fivec                   @   s   e Zd ZdS )z*TestClassDecorators.test_double.<locals>.CNr   r	   r	   r	   r
   r5   I  s   r5      r   )r   r   r   r5   r	   r	   r
   rn   A  s    zTestClassDecorators.test_doublec                 C   s:   dd }dd }||G dd dt }| |jd d S )Nc                 S   s
   d| _ | S )Nfirstr   r:   r	   r	   r
   applied_firstO  s    z5TestClassDecorators.test_order.<locals>.applied_firstc                 S   s
   d| _ | S )Nsecondr   r:   r	   r	   r
   applied_secondR  s    z6TestClassDecorators.test_order.<locals>.applied_secondc                   @   s   e Zd ZdS )z)TestClassDecorators.test_order.<locals>.CNr   r	   r	   r	   r
   r5   U  s   r5   r   r   )r   r   r   r5   r	   r	   r
   ru   N  s    zTestClassDecorators.test_orderN)r   r   r   r   rn   ru   r	   r	   r	   r
   r   7  s   r   __main__)NN)Zunittestr   r6   r   r   r   r#   r+   r0   ZTestCaser1   r   r   mainr	   r	   r	   r
   <module>   s   

 r#