[Twisted-Python] Re: Hanging test cases (Was: Evangelism notes...)

Christopher Armstrong radeex at gmail.com
Wed May 11 17:47:48 MDT 2005


On 11 May 2005 19:34:15 -0400, David Bolen <db3l at fitlinxx.com> wrote:
> Christopher Armstrong <radeex at gmail.com> writes:
> >     testCase = deferredGenerator(testCase)
> >
> > after the definition of the method, or even:
> >
> >     @deferredGenerator
> >
> > before the definition of the method.
> 
> But then who actually performs the iteration over the test case to
> trigger the generator?  Clearly some top level code needs to invoke
> the reactor.run() and at some point iterate over testCase while
> beneath a running reactor.  We're just using unittest, so something
> would need to be added to serve as the basic framework for that sort
> of test.

deferredGenerator does the iteration. This is how defgen works: you
define a generator. It should yield waitForDeferred instances. Then
you wrap that generator function with deferredGenerator.
deferredGenerator wraps that function such that, when called, returns
a Deferred (not a generator object!). The original generator will be
exhausted (doing the magic wait-for-deferred stuff along the way) and
the Deferred returned from your function will result in the last item
yielded from the generator. Since trial supports test methods
returning deferreds, this Just Works.

-- 
  Twisted   |  Christopher Armstrong: International Man of Twistery
   Radix    |    -- http://radix.twistedmatrix.com
            |  Release Manager, Twisted Project
  \\\V///   |    -- http://twistedmatrix.com
   |o O|    |  Founding Member, Hobart Hacking Society
w----v----w-+    -- http://hackingsociety.org/chapters/hash




More information about the Twisted-Python mailing list