MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_asyncio_1

Method test_asyncio_1

Lib/test/test_coroutines.py:2321–2358  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2319class CoroAsyncIOCompatTest(unittest.TestCase):
2320
2321 def test_asyncio_1(self):
2322 # asyncio cannot be imported when Python is compiled without thread
2323 # support
2324 asyncio = import_helper.import_module('asyncio')
2325
2326 class MyException(Exception):
2327 pass
2328
2329 buffer = []
2330
2331 class CM:
2332 async def __aenter__(self):
2333 buffer.append(1)
2334 await asyncio.sleep(0.01)
2335 buffer.append(2)
2336 return self
2337
2338 async def __aexit__(self, exc_type, exc_val, exc_tb):
2339 await asyncio.sleep(0.01)
2340 buffer.append(exc_type.__name__)
2341
2342 async def f():
2343 async with CM():
2344 await asyncio.sleep(0.01)
2345 raise MyException
2346 buffer.append('unreachable')
2347
2348 loop = asyncio.new_event_loop()
2349 asyncio.set_event_loop(loop)
2350 try:
2351 loop.run_until_complete(f())
2352 except MyException:
2353 pass
2354 finally:
2355 loop.close()
2356 asyncio.events._set_event_loop_policy(None)
2357
2358 self.assertEqual(buffer, [1, 2, 'MyException'])
2359
2360
2361class OriginTrackingTest(unittest.TestCase):

Callers

nothing calls this directly

Calls 7

fFunction · 0.70
import_moduleMethod · 0.45
new_event_loopMethod · 0.45
set_event_loopMethod · 0.45
run_until_completeMethod · 0.45
closeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected