Exemplo n.º 1
0
 def test_start_immediate_exception_eager_part(self):
     class E(Exception): pass
     async def run():
         raise E
     try:
         _asyncio._start_immediate(run(), self.loop)
     except E:
         pass
     else:
         self.fail("Exception expected")
Exemplo n.º 2
0
    def test_start_immediate_finish_eagerly(self):
        async def run():
            return 42

        val = _asyncio._start_immediate(run(), self.loop)
        self.assertIsInstance(val, _asyncio.AwaitableValue)
        self.assertEqual(val.value, 42)
Exemplo n.º 3
0
    def test_start_immediate_exception_deferred_part(self):
        class E(Exception): pass
        async def run():
            await asyncio.sleep(0)
            raise E

        async def wait(t):
            return await t

        val = _asyncio._start_immediate(run(), self.loop)
        self.assertNotIsInstance(val, _asyncio.AwaitableValue)
        try:
            self.loop.run_until_complete(wait(val))
        except E:
            pass
        else:
            self.fail("Exception expected")
Exemplo n.º 4
0
    def test_start_immediate_deferred(self):
        started = False
        finished = False
        async def run():
            nonlocal started, finished
            started = True
            await asyncio.sleep(0)
            finished = True
            return 42

        async def wait(t):
            return await t

        val = _asyncio._start_immediate(run(), self.loop)
        self.assertTrue(started)
        self.assertFalse(finished)
        self.assertNotIsInstance(val, _asyncio.AwaitableValue)
        res = self.loop.run_until_complete(wait(val))
        self.assertTrue(finished)
        self.assertEqual(res, 42)
Exemplo n.º 5
0
 async def main():
     val = _asyncio._start_immediate(run())
     self.assertIs(val._loop, asyncio.get_running_loop())