Exemplo n.º 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)
Exemplo n.º 2
0
 def test_addBothSuccess(self):
     """
     addBoth adds a callback to be run on success.
     """
     l = []
     sd = SynchronousDeferred("foo")
     self.assertEquals(sd.addBoth(l.append), sd)
     self.assertEquals(l, ["foo"])
Exemplo n.º 3
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])
Exemplo n.º 4
0
 def test_errbackResultChangesValue(self):
     """
     The result of an errback affects the result returned from
     C{synchronize}.
     """
     sd = SynchronousDeferred(SynchronousFailure(RuntimeError()))
     sd.addErrback(lambda r: 42)
     self.assertEquals(sd.synchronize(), 42)
Exemplo n.º 5
0
 def test_addCallbacksOnlyCallsOne(self):
     """
     If the callback raises an exception, the errback won't be called.
     """
     sd = SynchronousDeferred("foo")
     failures = []
     sd.addCallbacks(lambda r: 1/0, failures.append)
     self.assertEquals(failures, [])
Exemplo n.º 6
0
 def test_addErrback(self):
     """
     C{addErrback} immediately calls the errback when the current result is
     a failure.
     """
     failure = SynchronousFailure(RuntimeError())
     sd = SynchronousDeferred(failure)
     l = []
     self.assertEquals(sd.addErrback(l.append), sd)
     self.assertEquals(l, [failure])
Exemplo n.º 7
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])
Exemplo n.º 8
0
 def test_addBothSuccessExtraArgs(self):
     """
     addBoth takes extra arguments, and they get passed in the success case.
     """
     sd = SynchronousDeferred("foo")
     l = []
     def cb(r, extra, more=None):
         l.append((r, extra, more))
     sd.addBoth(cb, 1, more="heyo")
     self.assertEquals(l, [("foo", 1, "heyo")])
Exemplo n.º 9
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])
Exemplo n.º 10
0
 def test_addBothFailureExctraArgs(self):
     """
     addBoth adds a callback to be run on success.
     """
     failure = SynchronousFailure(RuntimeError())
     sd = SynchronousDeferred(failure)
     l = []
     def eb(r, extra, more=None):
         l.append((r, extra, more))
     sd.addBoth(eb, 1, more="heyo")
     self.assertEquals(l, [(failure, 1, "heyo")])
Exemplo n.º 11
0
 def test_addCallbacksExtraArgumentsOnCallback(self):
     """
     addCallbacks takes some extra arguments to pass to its callback.
     """
     sd = SynchronousDeferred("foo")
     l = []
     def cb(r, extra, more=None):
         l.append((r, extra, more))
     sd.addCallbacks(cb, lambda ignored: None,
                     (1,), {},
                     {"more": "heyo"}, {})
     self.assertEquals(l, [("foo", 1, "heyo")])
Exemplo n.º 12
0
 def test_addCallbacksCallsErrback(self):
     """
     C{addCallbacks} calls the errback passed to it, and not the callback,
     if the current result is a failure.
     """
     failure = SynchronousFailure(RuntimeError())
     sd = SynchronousDeferred(failure)
     successes = []
     failures = []
     sd.addCallbacks(successes.append, failures.append)
     self.assertEquals(successes, [])
     self.assertEquals(failures, [failure])
Exemplo n.º 13
0
 def test_addCallbacksCallsCallback(self):
     """
     C{addCallbacks} calls the callback passed to it, and not the errback,
     if the current result is a success.
     """
     sd = SynchronousDeferred("foo")
     successes = []
     failures = []
     self.assertEquals(sd.addCallbacks(successes.append, failures.append),
                       sd)
     self.assertEquals(successes, ["foo"])
     self.assertEquals(failures, [])
Exemplo n.º 14
0
 def test_errorRaisingErrback(self):
     """
     If an errback raises an exception, errbacks will be called.
     """
     sd = SynchronousDeferred(SynchronousFailure(RuntimeError()))
     def errback(ignored):
         1/0
     sd.addErrback(errback)
     l = []
     sd.addErrback(l.append)
     self.assertEquals(len(l), 1)
     self.assertTrue(l[0].check(ZeroDivisionError))
Exemplo n.º 15
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))
Exemplo n.º 16
0
 def test_addCallbacksExtraArgumentsOnErrback(self):
     """
     addCallbacks takes some extra arguments to pass to its errback.
     """
     failure = SynchronousFailure(RuntimeError())
     sd = SynchronousDeferred(failure)
     l = []
     def eb(r, extra, more=None):
         l.append((r, extra, more))
     sd.addCallbacks(lambda ignored: None, eb,
                     (), (1,),
                     {}, {"more": "heyo"})
     self.assertEquals(l, [(failure, 1, "heyo")])