예제 #1
0
    async def test_internal_state(self):
        promise = Promise(success_sleep(), loop=self.loop)
        self.assertEqual(promise.loop, self.loop)
        self.assertEqual(promise.done(), False)
        self.assertEqual(promise.cancelled(), False)

        await promise

        self.assertEqual(promise.loop, self.loop)
        self.assertEqual(promise.done(), True)
        self.assertEqual(promise.cancelled(), False)
예제 #2
0
    async def test_promise_cancellation_after_result(self):
        p = Promise()
        counter = Counter()

        p.cancel()
        with self.assertRaises(CancelledError):
            await (p.then(lambda x: counter.update(["then"])).catch(
                lambda exc: counter.update(["catch"])).lastly(
                    lambda: counter.update(["lastly"])))

        self.assertTrue(p.done())
        self.assertTrue(p.cancelled())
        self.assertEqual(counter["then"], 0)
        self.assertEqual(counter["catch"], 0)
        self.assertEqual(counter["lastly"], 0)
예제 #3
0
 def test_initialization(self):
     promise = Promise(self.fut)
     self.assertEqual(promise.loop, getattr(self.fut, "_loop"))
     self.assertEqual(promise.done(), self.fut.done())
     self.assertEqual(promise.cancelled(), self.fut.cancelled())