1# test simple async with execution 2 3class AContext: 4 async def __aenter__(self): 5 print('enter') 6 return 1 7 async def __aexit__(self, exc_type, exc, tb): 8 print('exit', exc_type, exc) 9 10async def f(): 11 async with AContext(): 12 print('body') 13 14o = f() 15try: 16 o.send(None) 17except StopIteration: 18 print('finished') 19 20async def g(): 21 async with AContext() as ac: 22 print(ac) 23 raise ValueError('error') 24 25o = g() 26try: 27 o.send(None) 28except ValueError: 29 print('ValueError') 30 31# test raising BaseException to make sure it is handled by the async-with 32async def h(): 33 async with AContext(): 34 raise BaseException 35o = h() 36try: 37 o.send(None) 38except BaseException: 39 print('BaseException') 40