def test_nonDestructiveDeferredCallback(self): """ Verify the use of non-destructive deferred chaining: a chained deferred is created with a callback that returns nothing - verify that a second callback on the original deferred receives the original value. """ x = Deferred() chained = [] notchained = [] def ccb(val): chained.append(val) return 3 ndc = _ndchain(x).addCallback(ccb) def ucb(val): notchained.append(val) return 4 x.addCallback(ucb) x.callback(2) self.assertEquals(notchained, [2]) self.assertEquals(chained, [2]) self.assertEquals(ndc.result, 3) self.assertEquals(x.result, 4)
def test_nonDestructiveDeferredAbuse(self): """ Verify that the non-destructive deferred will not break its callback, even if its result is (incorrectly) called back externally. """ x = Deferred() boom = _ndchain(x) boom.callback(1) l = [] x.addCallback(lambda n : (l.append(n) or 9)) x.callback(7) self.assertEquals(l, [7]) self.assertEquals(x.result, 9) self.assertEquals(len(self.flushLoggedErrors(AlreadyCalledError)), 1)
def test_nonDestructiveDeferredAbuse(self): """ Verify that the non-destructive deferred will not break its callback, even if its result is (incorrectly) called back externally. """ x = Deferred() boom = _ndchain(x) boom.callback(1) l = [] x.addCallback(lambda n: (l.append(n) or 9)) x.callback(7) self.assertEquals(l, [7]) self.assertEquals(x.result, 9) self.assertEquals(len(self.flushLoggedErrors(AlreadyCalledError)), 1)
def test_nonDestructiveDeferredCallback(self): """ Verify the use of non-destructive deferred chaining: a chained deferred is created with a callback that returns nothing - verify that a second callback on the original deferred receives the original value. """ x = Deferred() chained = [] notchained = [] def ccb(val): chained.append(val) return 3 ndc =_ndchain(x).addCallback(ccb) def ucb(val): notchained.append(val) return 4 x.addCallback(ucb) x.callback(2) self.assertEquals(notchained, [2]) self.assertEquals(chained, [2]) self.assertEquals(ndc.result, 3) self.assertEquals(x.result, 4)