def testOrdering(self): t = Target() p1 = send(t).one(1) p2 = send(t).two(3, k="extra") self.failIf(t.calls) def _check1(res): # we can't check t.calls here: the when() clause is not # guaranteed to fire before the second send. self.failUnlessEqual(res, 2) when(p1).addCallback(_check1) def _check2(res): self.failUnlessEqual(res, None) when(p2).addCallback(_check2) def _check3(res): self.failUnlessEqual(t.calls, [ ("one", 1), ("two", 3, 2, { "k": "extra" }), ]) fireEventually().addCallback(_check3)
def testBadName(self): t = Target() p1 = send(t).missing(0) def _check(res): self.failUnless(isinstance(res, Failure)) self.failUnless(res.check(AttributeError)) when(p1).addBoth(_check)
def testBadName(self): t = Target() p1 = send(t).missing(0) def _check(res): self.assertTrue(isinstance(res, Failure)) self.assertTrue(res.check(AttributeError)) when(p1).addBoth(_check)
def testResolveAfter(self): t = Target() p,r = makePromise() p = send(p).one(2) def _check(res): self.failUnlessEqual(res, 3) when(p).addCallback(_check) r(t)
def testResolveAfter(self): t = Target() p,r = makePromise() p = send(p).one(2) def _check(res): self.assertEqual(res, 3) when(p).addCallback(_check) r(t)
def testFailure(self): t = Target() p1 = send(t).fail(0) def _check(res): self.failUnless(isinstance(res, Failure)) self.failUnless(res.check(KaboomError)) p1._then(lambda res: self.fail("we were supposed to fail")) p1._except(_check) when(p1).addBoth(_check)
def testOrdering(self): t = Target() p1 = send(t).one(1) p2 = send(t).two(3, k="extra") self.failIf(t.calls) def _check1(res): # we can't check t.calls here: the when() clause is not # guaranteed to fire before the second send. self.failUnlessEqual(res, 2) when(p1).addCallback(_check1) def _check2(res): self.failUnlessEqual(res, None) when(p2).addCallback(_check2) def _check3(res): self.failUnlessEqual(t.calls, [("one", 1), ("two", 3, 2, {"k": "extra"}), ]) fireEventually().addCallback(_check3)
def testSend(self): t = Target() p = send(t).one(1) self.failIf(t.calls) def _check(res): self.failUnlessEqual(res, 2) self.failUnlessEqual(t.calls, [("one", 1)]) p._then(_check) when(p).addCallback(_check) # check it twice to test both syntaxes
def testResolveFailure(self): p,r = makePromise() p = send(p).one(2) def _check(res): self.failUnless(isinstance(res, Failure)) self.failUnless(res.check(KaboomError)) when(p).addBoth(_check) f = Failure(KaboomError("oops")) r(f)
def testFailure(self): t = Target() p1 = send(t).fail(0) def _check(res): self.assertTrue(isinstance(res, Failure)) self.assertTrue(res.check(KaboomError)) p1._then(lambda res: self.fail("we were supposed to fail")) p1._except(_check) when(p1).addBoth(_check)
def testSend(self): t = Target() p = send(t).one(1) self.assertFalse(t.calls) def _check(res): self.assertEqual(res, 2) self.assertEqual(t.calls, [("one", 1)]) p._then(_check) when(p).addCallback(_check) # check it twice to test both syntaxes
def testResolveFailure(self): p,r = makePromise() p = send(p).one(2) def _check(res): self.assertTrue(isinstance(res, Failure)) self.assertTrue(res.check(KaboomError)) when(p).addBoth(_check) f = Failure(KaboomError("oops")) r(f)
def testResolveBefore(self): t = Target() p, r = makePromise() r(t) p = send(p).one(2) def _check(res): self.failUnlessEqual(res, 3) when(p).addCallback(_check)