File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed
Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -1269,6 +1269,7 @@ async def __aenter__(self):
12691269 def __aexit__ (self , * e ):
12701270 return 444
12711271
1272+ # Exit with exception
12721273 async def foo ():
12731274 async with CM ():
12741275 1 / 0
@@ -1296,19 +1297,58 @@ async def __aenter__(self):
12961297 def __aexit__ (self , * e ):
12971298 return 456
12981299
1300+ # Normal exit
12991301 async def foo ():
13001302 nonlocal CNT
13011303 async with CM ():
13021304 CNT += 1
1305+ with self .assertRaisesRegex (
1306+ TypeError ,
1307+ "'async with' received an object from __aexit__ "
1308+ "that does not implement __await__: int" ):
1309+ run_async (foo ())
1310+ self .assertEqual (CNT , 1 )
13031311
1312+ # Exit with 'break'
1313+ async def foo ():
1314+ nonlocal CNT
1315+ for i in range (2 ):
1316+ async with CM ():
1317+ CNT += 1
1318+ break
1319+ with self .assertRaisesRegex (
1320+ TypeError ,
1321+ "'async with' received an object from __aexit__ "
1322+ "that does not implement __await__: int" ):
1323+ run_async (foo ())
1324+ self .assertEqual (CNT , 2 )
13041325
1326+ # Exit with 'continue'
1327+ async def foo ():
1328+ nonlocal CNT
1329+ for i in range (2 ):
1330+ async with CM ():
1331+ CNT += 1
1332+ continue
13051333 with self .assertRaisesRegex (
13061334 TypeError ,
13071335 "'async with' received an object from __aexit__ "
13081336 "that does not implement __await__: int" ):
13091337 run_async (foo ())
1338+ self .assertEqual (CNT , 3 )
13101339
1311- self .assertEqual (CNT , 1 )
1340+ # Exit with 'return'
1341+ async def foo ():
1342+ nonlocal CNT
1343+ async with CM ():
1344+ CNT += 1
1345+ return
1346+ with self .assertRaisesRegex (
1347+ TypeError ,
1348+ "'async with' received an object from __aexit__ "
1349+ "that does not implement __await__: int" ):
1350+ run_async (foo ())
1351+ self .assertEqual (CNT , 4 )
13121352
13131353
13141354 def test_with_9 (self ):
You can’t perform that action at this time.
0 commit comments