a ze+@sddlZddZGdddeZGdddeZddd Zd d Zd d ZGdddej Z Gdddej Z e dkr~e dS)Nc sfdd}|S)Ncs|j|SN)__dict__updatefunckwdsH/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_decorators.pydecorates zfuncattrs..decorater )rr r rr funcattrss r c@seZdZeddZdS)MiscDecoratorscsfdd}|S)Ncs|jd<|S)Nauthor)rrnamer r r s z'MiscDecorators.author..decorater )rr r rr r s zMiscDecorators.authorN)__name__ __module__ __qualname__ staticmethodrr r r r r sr c@seZdZddZdS) DbcheckErrorcCst|d||||fdS)Nz+dbcheck %r failed (func=%s args=%s kwds=%s)) Exception__init__)selfexprstrrargsrr r r rs zDbcheckError.__init__N)rrrrr r r r rsrcsfdd}|S)z+Decorator to implement debugging assertionscs*tdjdfdd}|S)Nz dbcheck-%sevalcs(tst|||i|Sr)rrrr)exprrrglobalslocalsr r checks z(dbcheck..decorate..check)compiler)rr rrr)rrr r szdbcheck..decorater )rrrr r r"r dbchecksr#csfdd}|S)z&Decorator to count calls to a functioncs(jd<fdd}|_|S)Nrcsd7<|i|S)Nr r)countsr func_namer r call,sz*countcalls..decorate..callrrr'r%)rr&r r )s zcountcalls..decorater )r%r r r*r countcalls's r+csifdd}j|_|S)NcsNz |WSty0|}||<|YStyH|YS0dSr)KeyError TypeError)rresrZsavedr r r'7s   zmemoize..callr(r)r r/r memoize5s r0c@sleZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdS)TestDecoratorscCs6Gdddt}||d||ddS)Nc@seZdZeddZdS)z%TestDecorators.test_single..CcSsdSN*r r r r r fooJsz)TestDecorators.test_single..C.fooN)rrrrr4r r r r CIsr5r3)object assertEqualr4rr5r r r test_singleHszTestDecorators.test_singlecCstdd}|t|ddS)NcSs|Srr xr r r notamethodPsz=TestDecorators.test_staticmethod_function..notamethodr$)r assertRaisesr-)rr<r r r test_staticmethod_functionOs z)TestDecorators.test_staticmethod_functioncCs8t}|ddd}||d||jddS)NZCleesecSsdSr2r r r r r r4Wsz'TestDecorators.test_dotted..foor3)r rr7)rZ decoratorsr4r r r test_dottedUs  zTestDecorators.test_dottedcCsdd}d}tddd}||i|dd}||d ||j||f|d d d d ddd}||d||jdtd d df|dddd}||jdifdS)Ncsfdd}|S)Ncst|df|S)Ndbval)setattrrrr r r asz@TestDecorators.test_argforms..noteargs..decorater )rrr r rr noteargs`sz.TestDecorators.test_argforms..noteargs)ZNowisZthetimer$)ZoneZtwocSsdSr2r r r r r f1hsz(TestDecorators.test_argforms..f1r3terrygilliamZidleZcleese)ZericZjohncSsdS)NTr r r r r f2msz(TestDecorators.test_argforms..f2rI)rGrHcSsdSrr r r r r f3ssz(TestDecorators.test_argforms..f3)r$rE)dictr7r@)rrBrrrFrJrKr r r test_argforms\s        zTestDecorators.test_argformscCs6tddd}||ddd|t|dddS)Nzargs[1] is not NonecSs||Srr )abr r r fxsz&TestDecorators.test_dbcheck..fr$rE)r#r7r=r)rrPr r r test_dbcheckws zTestDecorators.test_dbcheckcCsi}tt|dd}||jd||tdd||dd||dd||dd||dd||d d ||dd||d gd d g||dd ||d gd d g||dddS) NcSs|dS)NrEr r:r r r doublesz+TestDecorators.test_memoize..doublerSr)rSrEr$rQ )r0r+r7rrL)rr%rSr r r test_memoize~s  zTestDecorators.test_memoizec CsdD]N}t|dd|t$td|dddWdq1sH0YqdD]J}t|dd|t td|dWdqX1s0YqXdd }td|d }d tfd tfd tfdtffD],\}}d|}t|dd}||t ||qdS)N)zx,zx, yzx = ypassz import systestexec@ def f(): pass)z1.+2jz [1, 2][-1]z(1, 2)Truez...NonercSstdSr)NotImplementedErrorrr r r unimpsz)TestDecorators.test_errors..unimp)nullvalr`Zundefraz nullval.attrr`z$@%s def f(): pass assert f() is None) r!r= SyntaxErrorr-rZrL NameErrorAttributeErrorr_r)rZstmtrr`contextexcZcodestrcoder r r test_errorss$  4  0   zTestDecorators.test_errorscCs"dD]}td|dddqdS)N) z(x,)z(x, y)zx := yz(x := y)zx @yz(x @ y)zx[0]zw[x].y.zzw + x - (y + z)z x(y)()(z)z [w, x, y][z]zx.yr[r\rYrZ)r!)rrr r r test_expressionsszTestDecorators.test_expressionscCsVGdddt}||d||jjd||jjd||jjddS)Nc@s*eZdZedddeddddZdS) z%TestDecorators.test_double..Cr$haha)abcxyzr3)boohcSsdSr2r )rr r r r4sz)TestDecorators.test_double..C.fooN)rrrr r4r r r r r5s r5r3r$rj)r6r7r4rkrlrmr8r r r test_doubles zTestDecorators.test_doublecCs4dd}|d|ddd}||dddS)Ncsfdd}|S)zDecorator factory that returns a decorator that replaces the passed-in function with one that returns the value of 'num'cs fddS)NcsSrr r numr r zJTestDecorators.test_order..callnum..deco..r rror r decosz8TestDecorators.test_order..callnum..decor )rprsr ror callnums z*TestDecorators.test_order..callnumrEr$cSsdSr2r r r r r r4sz&TestDecorators.test_order..fooz,Application order of decorators is incorrect)r7)rrtr4r r r test_orders  zTestDecorators.test_ordercsgfddGfdddt}t|gd\}}}gd}g||j||j||jdd}||d ||gd d }||j||j||j|}||d ||dS) Ncs dfdd}|S)NZmakedeccsd|S)NZcalldecappendr)actionstagr r r szHTestDecorators.test_eval_order..make_decorator..decoraterv)ryr )rx)ryr make_decoratorsz6TestDecorators.test_eval_order..make_decoratorcs"eZdZddZfddZdS)z8TestDecorators.test_eval_order..NameLookupTracercSs ||_dSr)index)rr{r r r rszATestDecorators.test_eval_order..NameLookupTracer.__init__csF|dkrd}}n|dkr.dt|j}}nd||jf|S)NrzZevalnameargZevalargsz%s%d)strr{rw)rZfnameopnamer.rxrzr r __getattr__s  zDTestDecorators.test_eval_order..NameLookupTracer.__getattr__N)rrrrrr rr r NameLookupTracersr)r$rErQ) Z evalname1Z evalargs1Zmakedec1Z evalname2Z evalargs2Zmakedec2Z evalname3Z evalargs3Zmakedec3Zcalldec3Zcalldec2Zcalldec1cSsdSr2r r r r r r4sz+TestDecorators.test_eval_order..foor3cSsdSr2r r r r r bar rrz+TestDecorators.test_eval_order..bar)r6maprzr|r7)rrc1c2Zc3Zexpected_actionsr4rr rr test_eval_orders"     (zTestDecorators.test_eval_ordercsGdddGfdddfddGfddd}||d ||d ||d ||d dS) Nc@seZdZddZddZdS)zOTestDecorators.test_wrapped_descriptor_inside_classmethod..BoundWrappercSs ||_dSr __wrapped__rwrappedr r r rszXTestDecorators.test_wrapped_descriptor_inside_classmethod..BoundWrapper.__init__c_s|j|i|Srr)rrkwargsr r r __call__szXTestDecorators.test_wrapped_descriptor_inside_classmethod..BoundWrapper.__call__N)rrrrrr r r r BoundWrappersrcs eZdZddZfddZdS)zJTestDecorators.test_wrapped_descriptor_inside_classmethod..WrappercSs ||_dSrrrr r r rszSTestDecorators.test_wrapped_descriptor_inside_classmethod..Wrapper.__init__cs|j||}|Sr)r__get__)rinstanceownerZbound_functionrr r rszRTestDecorators.test_wrapped_descriptor_inside_classmethod..Wrapper.__get__N)rrrrrr rr r Wrappersrcs|Srr )r)rr r decorator szLTestDecorators.test_wrapped_descriptor_inside_classmethod..decoratorcs,eZdZeddZeddZdS)zHTestDecorators.test_wrapped_descriptor_inside_classmethod..ClasscSsdS)Nspamr clsr r r inner$szNTestDecorators.test_wrapped_descriptor_inside_classmethod..Class.innercSsdS)Neggsr rr r r outer*szNTestDecorators.test_wrapped_descriptor_inside_classmethod..Class.outerN)rrr classmethodrrr )rr r Class#s  rrr)r7rr)rrr )rrrr *test_wrapped_descriptor_inside_classmethods z9TestDecorators.test_wrapped_descriptor_inside_classmethodN)rrrr9r>r?rMrRrWrhrirnrurrr r r r r1Fs =r1c@s$eZdZddZddZddZdS)TestClassDecoratorscCs.dd}|Gdddt}||jddS)NcSs d|_|S)NHelloextrar:r r r plain:sz.TestClassDecorators.test_simple..plainc@s eZdZdS)z*TestClassDecorators.test_simple..CNrrrr r r r r5=sr5rr6r7r)rrr5r r r test_simple9szTestClassDecorators.test_simplecCs:dd}dd}||Gdddt}||jddS)NcSs d|_|S)NrVrr:r r r tenBsz,TestClassDecorators.test_double..tencSs|jd7_|S)Nrr:r r r add_fiveEsz1TestClassDecorators.test_double..add_fivec@s eZdZdS)z*TestClassDecorators.test_double..CNrr r r r r5Isr5r)rrrr5r r r rnAs zTestClassDecorators.test_doublecCs:dd}dd}||Gdddt}||jddS)NcSs d|_|S)Nfirstrr:r r r applied_firstOsz5TestClassDecorators.test_order..applied_firstcSs d|_|S)Nsecondrr:r r r applied_secondRsz6TestClassDecorators.test_order..applied_secondc@s eZdZdS)z)TestClassDecorators.test_order..CNrr r r r r5Usr5rr)rrrr5r r r ruNs zTestClassDecorators.test_orderN)rrrrrnrur r r r r7s r__main__)NN)Zunittestr r6r rrr#r+r0ZTestCaser1rrmainr r r r s  r#