Beispiel #1
0
    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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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
Beispiel #9
0
 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)
Beispiel #10
0
 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)
Beispiel #11
0
 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
Beispiel #12
0
 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)
Beispiel #13
0
    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)