def testDeferredWrapper(self): a = defer.Deferred() reactor.callLater(0, lambda: a.callback("test")) b = flow.Merge(a, slowlist([1,2,flow.Cooperate(),3])) d = flow.Deferred(b) d.addCallback(self.assertEqual, [1, 2, 'test', 3]) return d
def testThreadedError(self): # is this the expected behaviour? def iterator(): yield 1 raise ValueError d = flow.Deferred(Threaded(iterator())) return self.assertFailure(d, ValueError)
def testCallbackFailure(self): cb = flow.Callback() d = flow.Deferred(buildlist(cb)) for x in range(3): cb.result(x) cb.errback(flow.Failure(IOError())) return self.assertFailure(d, IOError)
def testCallback(self): cb = flow.Callback() d = flow.Deferred(buildlist(cb)) for x in range(9): cb.result(x) cb.finish() d.addCallback(self.assertEqual, [range(9)]) return d
def testConcurrentCallback(self): ca = flow.Callback() ca.name = 'a' cb = flow.Callback() cb.name = 'b' d = flow.Deferred(testconcur(ca,cb)) ca.result(1) cb.result(2) ca.result(3) ca.result(4) ca.finish() cb.result(5) cb.finish() d.addCallback(self.assertEquals, [('a',1),('b',2),('a',3),('a',4),('b',5)]) return d
def testQueryIterator(self): try: from pyPgSQL import PgSQL dbpool = PgSQL c = dbpool.connect() r = c.cursor() r.execute("SELECT 'x'") r.fetchone() except: # PostgreSQL is not installed or bad permissions return expect = [['one'],['two'],['three']] sql = """ (SELECT 'one') UNION ALL (SELECT 'two') UNION ALL (SELECT 'three') """ d = flow.Deferred(Threaded(QueryIterator(dbpool, sql))) d.addCallback(self.assertEquals, expect) return d
def testThreadedSleep(self): expect = [5,4,3,2,1] d = flow.Deferred(Threaded(CountIterator(5))) sleep(.5) d.addCallback(self.assertEquals, expect) return d
def testZipFailure(self): lhs = [(1,'a'),(2,'b'),(3,'c')] mrg = flow.Zip([1,2,flow.Cooperate(),3],badgen()) d = flow.Deferred(mrg) return self.assertFailure(d, ZeroDivisionError)
def testDeferredTrap(self): d = flow.Deferred(badgen(), ZeroDivisionError) d.addCallback(self.assertEqual, ['x', ZeroDivisionError]) return d
def testDeferredFailure(self): d = flow.Deferred(badgen()) return self.assertFailure(d, ZeroDivisionError)
def testDeferred(self): lhs = ['Title', (1,'one'),(2,'two'),(3,'three')] d = flow.Deferred(consumer()) d.addCallback(self.assertEquals, lhs) return d