def test_callbackResultChangesValue(self): """ The result of a callback affects the result returned from C{synchronize}. """ sd = SynchronousDeferred("foo") sd.addCallback(lambda r: 42) self.assertEquals(sd.synchronize(), 42)
def test_callbackResultChangesNextCallbackArgument(self): """ The result of a callback affects the argument passed to the next callback. """ sd = SynchronousDeferred("foo") sd.addCallback(lambda r: 42) l = [] sd.addCallback(l.append) self.assertEquals(l, [42])
def test_errbackResultChangesNextCallbackArgument(self): """ The result of an errback affects the argument passed to the next callback. """ sd = SynchronousDeferred(SynchronousFailure(RuntimeError())) sd.addErrback(lambda r: 42) l = [] sd.addCallback(l.append) self.assertEquals(l, [42])
def test_errorRaisingCallback(self): """ If a callback raises an exception, errbacks will be called. """ sd = SynchronousDeferred("foo") def callback(ignored): 1/0 sd.addCallback(callback) l = [] sd.addErrback(l.append) self.assertEquals(len(l), 1) self.assertTrue(l[0].check(ZeroDivisionError))
def test_addCallback(self): """ C{addCallback} calls the callback passed immediately and returns itself. """ l = [] sd = SynchronousDeferred(None) self.assertEquals(sd.addCallback(l.append), sd) self.assertEquals(l, [None])