Пример #1
0
 def callback_errback(self):
     testruns = (['callback', True], ['errback', False])
     for kwarg, success in testruns:
         l = []
         callback = lambda obj, l=l: l.append(obj)
         aresult = AsyncResult(**{kwarg: callback})
         assert not aresult.ready
         aresult.set('foo', success=success)
         Assert(len(l)) == 1
         Assert(l[0]) == 'foo'
Пример #2
0
    def wait(self):
        aresult = AsyncResult()

        def setter(aresult):
            time.sleep(1)
            aresult.set('foo')
        t = Thread(target=setter, args=(aresult, ))
        t.start()
        with Assert.not_raising(TimeoutError):
            aresult.wait(2)
Пример #3
0
    def repr(self):
        aresult = AsyncResult()
        Assert(repr(aresult)) == 'AsyncResult()'

        aresult = AsyncResult(callback=1)
        Assert(repr(aresult)) == 'AsyncResult(callback=1)'

        aresult = AsyncResult(errback=1)
        Assert(repr(aresult)) == 'AsyncResult(errback=1)'

        aresult = AsyncResult(callback=1, errback=2)
        Assert(repr(aresult)) == 'AsyncResult(callback=1, errback=2)'
Пример #4
0
    def get(self):
        aresult = AsyncResult()

        with Assert.raises(TimeoutError):
            aresult.get(0.1)

        def setter(aresult):
            time.sleep(1)
            aresult.set('foo')
        t = Thread(target=setter, args=(aresult, ))
        t.start()
        with Assert.not_raising(TimeoutError):
            Assert(aresult.get(2)) == 'foo'

        aresult.set('foo')
        Assert(aresult.get()) == 'foo'

        aresult = AsyncResult()
        aresult.set(ValueError(), success=False)
        with Assert.raises(ValueError):
            aresult.get()