Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_decorators.cpython-35.pyc



��Yf�%�@s�ddlZdd�ZGdd�de�ZGdd�de�Zdddd	�Zd
d�Zdd
�ZGdd�dej	�Z
Gdd�dej	�Zedkr�ej
�dS)�Ncs�fdd�}|S)Ncs|jj��|S)N)�__dict__�update)�func)�kwds��9/opt/alt/python35/lib64/python3.5/test/test_decorators.py�decorateszfuncattrs.<locals>.decorater)rrr)rr�	funcattrssr	c@s"eZdZedd��ZdS)�MiscDecoratorscs�fdd�}|S)Ncs�|jd<|S)N�author)r)r)�namerrrs
z'MiscDecorators.author.<locals>.decorater)rrr)rrr
szMiscDecorators.authorN)�__name__�
__module__�__qualname__�staticmethodrrrrrr
	sr
c@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)r
rrrrrrrrsrcs���fdd�}|S)z+Decorator to implement debugging assertionscs;t�d�jd�������fdd�}|S)Nz
dbcheck-%s�evalcs4t����s't��||���||�S)N)rr)rr)�exprrr�globals�localsrr�checksz(dbcheck.<locals>.decorate.<locals>.check)�compiler
)rr)rrr)rrrrszdbcheck.<locals>.decorater)rrrrr)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)rrr)rr�
countcalls'sr"cs+i���fdd�}�j|_|S)NcsZy�|SWnGtk
r:�|�}|�|<|SYntk
rU�|�SYnXdS)N)�KeyError�	TypeError)r�res)r�savedrrr!7s


zmemoize.<locals>.call)r
)rr!r)rr&r�memoize5s
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�fooJsz)TestDecorators.test_single.<locals>.C.fooN)r
rrrr*rrrr�CIsr+r))�object�assertEqualr*)rr+rrr�test_singleHszTestDecorators.test_singlecCs)tdd��}|jt|d�dS)NcSs|S)Nr)�xrrr�
notamethodPsz=TestDecorators.test_staticmethod_function.<locals>.notamethodr)r�assertRaisesr$)rr0rrr�test_staticmethod_functionOsz)TestDecorators.test_staticmethod_functioncCsNt�}|jd�dd��}|j|�d�|j|jd�dS)NZCleesecSsdS)Nr)rrrrrr*Wsz'TestDecorators.test_dotted.<locals>.foor))r
rr-)rZ
decoratorsr*rrr�test_dottedUs	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)rrrrrasz@TestDecorators.test_argforms.<locals>.noteargs.<locals>.decorater)rrrr)rrr�noteargs`sz.TestDecorators.test_argforms.<locals>.noteargs�Now�is�the�timeZonerZtwo�cSsdS)Nr)rrrrr�f1hsz(TestDecorators.test_argforms.<locals>.f1r)�terry�gilliamZericZidleZjohnZcleesecSsdS)N�Trrrrr�f2msz(TestDecorators.test_argforms.<locals>.f2r?cSsdS)Nrrrrr�f3ssz(TestDecorators.test_argforms.<locals>.f3)r7r8r9r:)r=r>)rr;)�dictr-r4)rr6rrr<r@rArrr�
test_argforms\s'zTestDecorators.test_argformscCsKtd�dd��}|j|dd�d�|jt|dd�dS)Nzargs[1] is not NonecSs||S)Nr)�a�brrr�fxsz&TestDecorators.test_dbcheck.<locals>.frr;�)rr-r1r)rrFrrr�test_dbcheckwszTestDecorators.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)r/rrr�double�sz+TestDecorators.test_memoize.<locals>.doublerIrr;�rrG��
)r'r"r-r
rB)rrrIrrr�test_memoize~szTestDecorators.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(): passZtestz@f1 @f2
def f(): passcSs
t�dS)N)�NotImplementedError)rrrr�unimp�sz)TestDecorators.test_errors.<locals>.unimpZnullvalrPZundefznullval.attrz$@%s
def f(): pass
assert f() is None)	rr1�SyntaxErrorrB�	NameErrorr$�AttributeErrorrOr)rrZcodestrrP�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)r
rrr	r*rrrrr+�sr+r)rrZ)r,r-r*rXrYr[)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]r_r)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-)rr`r*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)rb)rdr)rc)rdr�make_decorator�sz6TestDecorators.test_eval_order.<locals>.make_decoratorcs1eZdZdd�Z��fdd�ZdS)z8TestDecorators.test_eval_order.<locals>.NameLookupTracercSs
||_dS)N)�index)rrfrrrr�szATestDecorators.test_eval_order.<locals>.NameLookupTracer.__init__csu|dkrd�}}n;|dkrAdt|j�}}ndsWtd|���jd||jf�|S)NreZevalname�argZevalargsFzUnknown attrname %sz%s%d)�strrf�AssertionErrorrb)rZfname�opnamer%)rcrerr�__getattr__�szDTestDecorators.test_eval_order.<locals>.NameLookupTracer.__getattr__N)r
rrrrkr)rcrerr�NameLookupTracer�srlrr;rGZ	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,�maprergr-)rrlZc1Zc2Zc3Zexpected_actionsr*rmr)rcrer�test_eval_order�s&!			$<zTestDecorators.test_eval_orderN)
r
rrr.r2r3rCrHrMrWr\rarorrrrr(Fs
r(c@s4eZdZdd�Zdd�Zdd�ZdS)�TestClassDecoratorscCs?dd�}|Gdd�dt��}|j|jd�dS)NcSs
d|_|S)N�Hello)�extra)r/rrr�plains	z.TestClassDecorators.test_simple.<locals>.plainc@seZdZdS)z*TestClassDecorators.test_simple.<locals>.CN)r
rrrrrrr+sr+rq)r,r-rr)rrsr+rrr�test_simpleszTestClassDecorators.test_simplecCsQdd�}dd�}||Gdd�dt���}|j|jd�dS)NcSs
d|_|S)NrL)rr)r/rrr�tens	z,TestClassDecorators.test_double.<locals>.tencSs|jd7_|S)N�)rr)r/rrr�add_fivesz1TestClassDecorators.test_double.<locals>.add_fivec@seZdZdS)z*TestClassDecorators.test_double.<locals>.CN)r
rrrrrrr+sr+�)r,r-rr)rrurwr+rrrr\szTestClassDecorators.test_doublecCsQdd�}dd�}||Gdd�dt���}|j|jd�dS)NcSs
d|_|S)N�first)rr)r/rrr�
applied_first$s	z5TestClassDecorators.test_order.<locals>.applied_firstcSs
d|_|S)N�second)rr)r/rrr�applied_second's	z6TestClassDecorators.test_order.<locals>.applied_secondc@seZdZdS)z)TestClassDecorators.test_order.<locals>.CN)r
rrrrrrr+*sr+r{)r,r-rr)rrzr|r+rrrra#szTestClassDecorators.test_orderN)r
rrrtr\rarrrrrps
rp�__main__)Zunittestr	r,r
rrrr"r'ZTestCaser(rpr
�mainrrrr�<module>s

�#