(self)
| 2319 | class 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 | |
| 2361 | class OriginTrackingTest(unittest.TestCase): |
nothing calls this directly
no test coverage detected