예제 #1
0
 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)
예제 #2
0
 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])
예제 #3
0
 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])
예제 #4
0
 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))
예제 #5
0
 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])