Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_decorators.cpython-34.pyc

�
f fd&�@s�ddlZddlmZdd�ZGdd�de�ZGdd�de�Zddd	d
�Zdd�Z	d
d�Z
Gdd�dej�ZGdd�dej�Z
dd�Zedkr�e�ndS)�N)�supportcs�fdd�}|S)Ncs|jj��|S)N)�__dict__�update)�func)�kwds��9/opt/alt/python34/lib64/python3.4/test/test_decorators.py�decorateszfuncattrs.<locals>.decorater)rr	r)rr�	funcattrssr
c@s"eZdZedd��ZdS)�MiscDecoratorscs�fdd�}|S)Ncs�|jd<|S)N�author)r)r)�namerrr	
s
z'MiscDecorators.author.<locals>.decorater)r
r	r)r
rrszMiscDecorators.authorN)�__name__�
__module__�__qualname__�staticmethodrrrrrr
src@seZdZdd�ZdS)�DbcheckErrorcCs$tj|d||||f�dS)Nz+dbcheck %r failed (func=%s args=%s kwds=%s))�	Exception�__init__)�self�exprstrr�argsrrrrrszDbcheckError.__init__N)rrrrrrrrrsrcs���fdd�}|S)z+Decorator to implement debugging assertionscs;t�d�jd�������fdd�}|S)Nz
dbcheck-%s�evalcs7t����s*t��||��n�||�S)N)rr)rr)�exprrr�globals�localsrr�checksz(dbcheck.<locals>.decorate.<locals>.check)�compiler)rr)rrr)rrrr	szdbcheck.<locals>.decorater)rrrr	r)rrrr�dbchecksrcs�fdd�}|S)z&Decorator to count calls to a functioncs8�j�d��<���fdd�}�|_|S)Nrcs��d7<�||�S)N�r)rr)�countsr�	func_namerr�call-sz*countcalls.<locals>.decorate.<locals>.call)r)rr")r )rr!rr	*s
	
	zcountcalls.<locals>.decorater)r r	r)r r�
countcalls(sr#cs+i���fdd�}�j|_|S)NcsZy�|SWnGtk
r:�|�}|�|<|SYntk
rU�|�SYnXdS)N)�KeyError�	TypeError)r�res)r�savedrrr"8s


zmemoize.<locals>.call)r)rr"r)rr'r�memoize6s
r(c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestDecoratorscCsIGdd�dt�}|j|j�d�|j|�j�d�dS)Nc@s"eZdZedd��ZdS)z%TestDecorators.test_single.<locals>.CcSsdS)N�*rrrrr�fooKsz)TestDecorators.test_single.<locals>.C.fooN)rrrrr+rrrr�CJsr,r*)�object�assertEqualr+)rr,rrr�test_singleIszTestDecorators.test_singlecCs)tdd��}|jt|d�dS)NcSs|S)Nr)�xrrr�
notamethodQsz=TestDecorators.test_staticmethod_function.<locals>.notamethodr)r�assertRaisesr%)rr1rrr�test_staticmethod_functionPsz)TestDecorators.test_staticmethod_functioncCsNt�}|jd�dd��}|j|�d�|j|jd�dS)NZCleesecSsdS)Nr*rrrrrr+Xsz'TestDecorators.test_dotted.<locals>.foor*)rrr.)rZ
decoratorsr+rrr�test_dottedVs	zTestDecorators.test_dottedcCsdd�}d}tddd	d
�}|||�dd��}|j|�d
�|j|j||f�|dddddd�dd��}|j|�d�|j|jdtdddd�f�|dd
�dd��}|j|jdif�dS)Ncs��fdd�}|S)Ncst|d��f�|S)N�dbval)�setattr)r)rrrrr	bsz@TestDecorators.test_argforms.<locals>.noteargs.<locals>.decorater)rrr	r)rrr�noteargsasz.TestDecorators.test_argforms.<locals>.noteargs�Now�is�the�timeZonerZtwo�cSsdS)Nr*rrrrr�f1isz(TestDecorators.test_argforms.<locals>.f1r*�terry�gilliamZericZidleZjohnZcleesecSsdS)N�Trrrrr�f2nsz(TestDecorators.test_argforms.<locals>.f2r@cSsdS)Nrrrrr�f3tsz(TestDecorators.test_argforms.<locals>.f3)r8zisr:r;)r>r?)rr<)�dictr.r5)rr7rrr=rArBrrr�
test_argforms]s'zTestDecorators.test_argformscCsKtd�dd��}|j|dd�d�|jt|dd�dS)Nzargs[1] is not NonecSs||S)Nr)�a�brrr�fysz&TestDecorators.test_dbcheck.<locals>.frr<�)rr.r2r)rrGrrr�test_dbcheckxszTestDecorators.test_dbcheckcCs8i}tt|�dd���}|j|jd�|j|tdd��|j|d�d�|j|dd�|j|d�d�|j|dd�|j|d�d	�|j|dd�|j|d
g�d
d
g�|j|dd�|j|d
g�d
d
g�|j|dd�dS)NcSs|dS)Nr<r)r0rrr�double�sz+TestDecorators.test_memoize.<locals>.doublerJrr<�rrH��
)r(r#r.rrC)rr rJrrr�test_memoizeszTestDecorators.test_memoizecCs�xJdddgD]9}t|dd�d|}|jtt|dd�qW|jttddd�d	d
�}tddd|�}xjd
tfdtfdtfdtfgD]>\}}d|}t|dd�}|j|t||�q�WdS)Nz1+2zx[3]z(1, 2)Ztestexpr�execz@%s
def f(): pass�testz@f1 @f2
def f(): passcSs
t�dS)N)�NotImplementedError)rrrr�unimp�sz)TestDecorators.test_errors.<locals>.unimpZnullvalrRZundefznullval.attrz$@%s
def f(): pass
assert f() is None)	rr2�SyntaxErrorrC�	NameErrorr%�AttributeErrorrQr)rrZcodestrrR�context�exc�coderrr�test_errors�s

		
zTestDecorators.test_errorscCsuGdd�dt�}|j|�j�d�|j|jjd�|j|jjd�|j|jjd�dS)Nc@s@eZdZedddd�edd�dd���Zd	S)
z%TestDecorators.test_double.<locals>.C�abcr�xyz�haha�boohr*cSsdS)Nr*r)rrrrr+�sz)TestDecorators.test_double.<locals>.C.fooN)rrrr
r+rrrrr,�sr,r*rr\)r-r.r+rZr[r])rr,rrr�test_double�s
zTestDecorators.test_doublecCsJdd�}|d�|d�dd���}|j|�dd�dS)Ncs�fdd�}|S)z�Decorator factory that returns a decorator that replaces the
            passed-in function with one that returns the value of 'num'cs�fdd�S)Ncs�S)Nrr)�numrr�<lambda>�szJTestDecorators.test_order.<locals>.callnum.<locals>.deco.<locals>.<lambda>r)r)r_rr�deco�sz8TestDecorators.test_order.<locals>.callnum.<locals>.decor)r_rar)r_r�callnum�sz*TestDecorators.test_order.<locals>.callnumr<rcSsdS)Nr*rrrrrr+�sz&TestDecorators.test_order.<locals>.fooz,Application order of decorators is incorrect)r.)rrbr+rrr�
test_order�s
	zTestDecorators.test_ordercsbg��fdd��G��fdd�dt�}t|dddg�\}}}dd	d
ddd
ddddddg}g�|j|j�|j|j�|j|j�dd����}|j|�d�|j�|�g�dd�}|j|j�|j|j�|j|j�|���}|j|�d�|j�|�dS)Ncs*�jd����fdd�}|S)NZmakedeccs�jd��|S)NZcalldec)�append)r)�actions�tagrrr	�szHTestDecorators.test_eval_order.<locals>.make_decorator.<locals>.decorate)rd)rfr	)re)rfr�make_decorator�sz6TestDecorators.test_eval_order.<locals>.make_decoratorcs1eZdZdd�Z��fdd�ZdS)z8TestDecorators.test_eval_order.<locals>.NameLookupTracercSs
||_dS)N)�index)rrhrrrr�szATestDecorators.test_eval_order.<locals>.NameLookupTracer.__init__csu|dkrd�}}n;|dkrAdt|j�}}ndsWtd|���jd||jf�|S)NrgZevalname�argZevalargsFzUnknown attrname %sz%s%d)�strrh�AssertionErrorrd)rZfname�opnamer&)rergrr�__getattr__�szDTestDecorators.test_eval_order.<locals>.NameLookupTracer.__getattr__N)rrrrrmr)rergrr�NameLookupTracer�srnrr<rHZ	evalname1Z	evalargs1Zmakedec1Z	evalname2Z	evalargs2Zmakedec2Z	evalname3Z	evalargs3Zmakedec3Zcalldec3Zcalldec2Zcalldec1cSsdS)Nr*rrrrrr+�sz+TestDecorators.test_eval_order.<locals>.foor*cSsdS)Nr*rrrrr�barsz+TestDecorators.test_eval_order.<locals>.bar)r-�maprgrir.)rrnZc1Zc2Zc3Zexpected_actionsr+ror)rergr�test_eval_order�s&!			$<zTestDecorators.test_eval_orderN)
rrrr/r3r4rDrIrNrYr^rcrqrrrrr)Gs
r)c@s4eZdZdd�Zdd�Zdd�ZdS)�TestClassDecoratorscCs?dd�}|Gdd�dt��}|j|jd�dS)NcSs
d|_|S)N�Hello)�extra)r0rrr�plains	z.TestClassDecorators.test_simple.<locals>.plainc@seZdZdS)z*TestClassDecorators.test_simple.<locals>.CN)rrrrrrrr,sr,rs)r-r.rt)rrur,rrr�test_simpleszTestClassDecorators.test_simplecCsQdd�}dd�}||Gdd�dt���}|j|jd�dS)NcSs
d|_|S)NrM)rt)r0rrr�tens	z,TestClassDecorators.test_double.<locals>.tencSs|jd7_|S)N�)rt)r0rrr�add_fivesz1TestClassDecorators.test_double.<locals>.add_fivec@seZdZdS)z*TestClassDecorators.test_double.<locals>.CN)rrrrrrrr,sr,�)r-r.rt)rrwryr,rrrr^szTestClassDecorators.test_doublecCsQdd�}dd�}||Gdd�dt���}|j|jd�dS)NcSs
d|_|S)N�first)rt)r0rrr�
applied_first%s	z5TestClassDecorators.test_order.<locals>.applied_firstcSs
d|_|S)N�second)rt)r0rrr�applied_second(s	z6TestClassDecorators.test_order.<locals>.applied_secondc@seZdZdS)z)TestClassDecorators.test_order.<locals>.CN)rrrrrrrr,+sr,r})r-r.rt)rr|r~r,rrrrc$szTestClassDecorators.test_orderN)rrrrvr^rcrrrrrr
s
rrcCstjt�tjt�dS)N)rZrun_unittestr)rrrrrr�	test_main0s
r�__main__)ZunittestrPrr
r-rrrrr#r(ZTestCaser)rrrrrrrr�<module>s

�#