σ ΥoPc@`sdZddlmZmZddlZddlmZddlmZddl m Z m Z m Z ddl m Z mZddlmZd „Zd „Zd efd „ƒYZd dd„ƒYZdeejfd„ƒYZdeejfd„ƒYZdS(sI Tests for L{twisted.internet.defer.deferredGenerator} and related APIs. i(tdivisiontabsolute_importN(treactor(tunittest(twaitForDeferredtdeferredGeneratortDeferred(tinlineCallbackst returnValue(tdefercC`s#tƒ}tjd|jdƒ|S(Nithi(RRt callLatertcallback(td((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pytgetThings c`s,tƒ‰‡fd†}tjd|ƒˆS(Nc`sˆjtdƒƒdS(NtOMG(terrbacktZeroDivisionError((R (s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pytCRAPsi(RRR (R((R s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pytgetOwies tTerminalExceptioncB`seZRS((t__name__t __module__(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR$stBaseDefgenTestscB`sMeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(s This class sets up a bunch of test cases which will test both deferredGenerator and inlineCallbacks based generators. The subclasses DeferredGeneratorTests and InlineCallbacksTests each provide the actual generator implementations tested. cC`s|jƒj|jdƒS(sΕ Test that a normal deferredGenerator works. Tests yielding a deferred which callbacks, as well as a deferred errbacks. Also ensures returning a final value works. tWOOSH(t _genBasicst addCallbackt assertEqual(tself((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt testBasics/scC`s|j|jƒtƒS(sp Ensure that a buggy generator properly signals a Failure condition on result deferred. (t assertFailuret _genBuggyR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt testBuggy8scC`s|jƒj|jdƒS(s9Test that a generator which never yields results in None.N(t _genNothingRRtNone(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt testNothing?scC`s|jƒj|jdƒS(sΝ Create a Deferred Generator which yields a Deferred which fails and handles the exception which results. Assert that the Deferred Generator does not errback its Deferred. N(t_genHandledTerminalFailureRRR"(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestHandledTerminalFailureDscC`sAtjƒ}|j|ƒ}|jtdƒƒ|j|jdƒS(s~ Just like testHandledTerminalFailure, only with a Deferred which fires asynchronously with an error. sHandled Terminal FailureN(R Rt_genHandledTerminalAsyncFailureRRRRR"(RR tdeferredGeneratorResultDeferred((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestHandledTerminalAsyncFailureLs  cC`s|jƒj|jdƒS(sj Make sure we don't blow the stack when yielding immediately available deferreds. i(t_genStackUsageRR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestStackUsageWscC`s|jƒj|jdƒS(sg Make sure we don't blow the stack when yielding immediately available values. i(t_genStackUsage2RR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestStackUsage2^s( RRt__doc__RR R#R%R(R*R,(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR's    tDeferredGeneratorTestscB`s€eZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„Z ee ƒZ d„Z RS(cc`s‡ttƒƒ}|V|jƒ}|j|dƒttƒƒ}|Vy|jƒWn)tk r}}|jt|ƒdƒnXdVdS(NR RR(RRt getResultRRRtstr(Rtxtowte((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyRks cc`sttƒƒVdddS(Nii(RR(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR}scc`sdS(N((R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR!ƒscc`sFttjtdƒƒƒ}|Vy|jƒWntk rAnXdS(NsHandled Terminal Failure(RR tfailRR/(RR1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR$‡s  cc`s7t|ƒ}|Vy|jƒWntk r2nXdS(N(RR/R(RR R1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR&‘s   cc`sFx:tdƒD],}ttjdƒƒ}|V|jƒ}q WdVdS(Niˆii(trangeRR tsucceedR/(RR1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR)›s cc`s%xtdƒD] }dVq WdVdS(Niˆii(R5(RR1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR+€s cC`s(d„}t|ƒ}|j|ƒtƒS(sZ Ensure that yielding a Deferred directly is trapped as an error. cs`s tƒVdS(N(R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt _genDeferred³s(RRt TypeError(RR7((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestDeferredYielding­s  ( RRRRRR!R$R&R)R+R9(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR.hs              tInlineCallbacksTestscB`sΘeZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„ZeeƒZd„Z ee ƒZ d„Z d„Z d „Z d „Z d „ZRS( cc`sbtƒV}|j|dƒytƒV}Wn)tk rS}|jt|ƒdƒnXtdƒdS(NR RR(RRRRR0R(RR1R2R3((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyRΎs cc`stƒVdddS(Nii(R(R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyRΛscc`sdS(N((R((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR!Ρscc`s2ytjtdƒƒV}Wntk r-nXdS(NsHandled Terminal Failure(R R4R(RR1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR$Φs cc`s#y |V}Wntk rnXdS(N(R(RR R1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR&ήs  cc`s5x$tdƒD]}tjdƒV}q WtdƒdS(Niˆii(R5R R6R(RR1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR)ηscc`s*xtdƒD] }dVq WtdƒdS(Niˆii(R5R(RR1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR+ξs cC`s+d„}t|ƒ}|ƒj|jdƒS(ss Ensure that yielding a non-deferred passes it back as the result of the yield expression. cs`sdV}tdƒdS(Ni(R(R1((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt_testόsi(RRR(RR;((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestYieldNonDeferrredχs  cC`s+d„}t|ƒ}|ƒj|jdƒS(s9Ensure a standard python return results in a None result.cs`s dVdS(Ni((((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt _noReturnsN(RRRR"(RR=((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestReturnNoValues  cC`s+d„}t|ƒ}|ƒj|jdƒS(sEnsure that returnValue works.cs`sdVtdƒdS(Nii(R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt_returnsi(RRR(RR?((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttestReturnValue s  cC`s;d„}t|ƒ}|jdt|jt|ƒƒƒdS(s£ Ensure that C{TypeError} with a message about L{inlineCallbacks} is raised when a non-generator returns something other than a generator. cS`sdS(Ni((((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyt_noYieldsRN(RtassertInR0t assertRaisesR8(RRA((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttest_nonGeneratorReturns   cC`s;d„}t|ƒ}|jdt|jt|ƒƒƒdS(s Ensure that C{TypeError} with a message about L{inlineCallbacks} is raised when a non-generator calls L{returnValue}. cS`stdƒdS(Ni(R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyRA(sRN(RRBR0RCR8(RRA((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyttest_nonGeneratorReturnValue#s   (RRRRRR!R$R&R)R+R<R>R@RDRE(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyR:»s(              ((R-t __future__RRtsysttwisted.internetRt twisted.trialRttwisted.internet.deferRRRRRR RRt ExceptionRRtTestCaseR.R:(((s</usr/lib/python2.7/dist-packages/twisted/test/test_defgen.pyts   AS