def testFailure(self): self.assertRaises(ZeroDivisionError, list, flow.Block(badgen())) self.assertEqual(['x',ZeroDivisionError], list(flow.Block(badgen(),ZeroDivisionError))) self.assertEqual(['x',ZeroDivisionError], list(flow.Block(flow.wrap(badgen()), ZeroDivisionError)))
def testLineBreak(self): lhs = [ "Hello World", "Happy Days Are Here" ] rhs = ["Hello ","World\nHappy", flow.Cooperate(), " Days"," Are Here\n"] mrg = flow.LineBreak(slowlist(rhs), delimiter='\n') rhs = list(flow.Block(mrg)) self.assertEqual(lhs,rhs)
def testFilter(self): def odd(val): if val % 2: return True lhs = [ 1, 3 ] mrg = flow.Filter(odd,slowlist([1,2,flow.Cooperate(),3])) rhs = list(flow.Block(mrg)) self.assertEqual(lhs,rhs)
def testDeferredWrapperImmediate(self): from twisted.internet import defer a = defer.Deferred() a.callback("test") self.assertEquals(["test"], list(flow.Block(a)))
def testBuildList(self): src = flow.wrap([1,2,3]) out = flow.Block(buildlist(src)).next() self.assertEquals(out,[1,2,3])
def testMerge(self): lhs = ['one', 1, 'two', 2, 3, 'three'] mrg = flow.Merge(slowlist(_onetwothree),slowlist([1,2,3])) rhs = list(flow.Block(mrg)) self.assertEqual(lhs,rhs)
def testZip(self): lhs = [(1,'a'),(2,'b'),(3,None)] mrg = flow.Zip([1,2,flow.Cooperate(),3],['a','b']) rhs = list(flow.Block(mrg)) self.assertEqual(lhs,rhs)
def testConsumer(self): lhs = ['Title',(1,'one'),(2,'two'),(3,'three')] rhs = list(flow.Block(consumer)) self.assertEqual(lhs,rhs)
def testProducer(self): lhs = [(1,'one'),(2,'two'),(3,'three')] rhs = list(flow.Block(producer())) self.assertEqual(lhs,rhs)
def testCallable(self): lhs = ['one','two','three'] rhs = list(flow.Block(slowlist(_onetwothree))) self.assertEqual(lhs,rhs)
def testBasicIterator(self): lhs = ['one','two','three'] rhs = list(flow.Block(slowlist(_onetwothree))) self.assertEqual(lhs,rhs)
def testBasicList(self): lhs = [1,2,3] rhs = list(flow.Block([1,2,flow.Cooperate(),3])) self.assertEqual(lhs,rhs)
def testBasic(self): lhs = ['string'] rhs = list(flow.Block('string')) self.assertEqual(lhs,rhs)