async def test_nested_timeouts(self):
     loop = asyncio.get_running_loop()
     cancelled = False
     with self.assertRaises(TimeoutError):
         deadline = loop.time() + 0.01
         async with asyncio.timeout_at(deadline) as cm1:
             # Only the topmost context manager should raise TimeoutError
             try:
                 async with asyncio.timeout_at(deadline) as cm2:
                     await asyncio.sleep(10)
             except asyncio.CancelledError:
                 cancelled = True
                 raise
     self.assertTrue(cancelled)
     self.assertTrue(cm1.expired())
     self.assertTrue(cm2.expired())
    async def test_timeout_at_basic(self):
        loop = asyncio.get_running_loop()

        with self.assertRaises(TimeoutError):
            deadline = loop.time() + 0.01
            async with asyncio.timeout_at(deadline) as cm:
                await asyncio.sleep(10)
        self.assertTrue(cm.expired())
        self.assertEqual(deadline, cm.when())
    async def test_timeout_at_disabled(self):
        loop = asyncio.get_running_loop()
        t0 = loop.time()
        async with asyncio.timeout_at(None) as cm:
            await asyncio.sleep(0.01)
        t1 = loop.time()

        self.assertFalse(cm.expired())
        self.assertIsNone(cm.when())
        # 2 sec for slow CI boxes
        self.assertLess(t1 - t0, 2)
 async def f():
     async with asyncio.timeout_at(deadline1) as cm:
         fut.set_result(cm)
         await asyncio.sleep(50)