mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue 24017: More tests for 'async for' and 'async with'.
This commit is contained in:
parent
c41632a856
commit
9113dc7c97
1 changed files with 35 additions and 0 deletions
|
@ -623,6 +623,27 @@ class CoroutineTest(unittest.TestCase):
|
|||
|
||||
run_async(foo())
|
||||
|
||||
def test_with_13(self):
|
||||
CNT = 0
|
||||
|
||||
class CM:
|
||||
async def __aenter__(self):
|
||||
1/0
|
||||
|
||||
async def __aexit__(self, *e):
|
||||
return True
|
||||
|
||||
async def foo():
|
||||
nonlocal CNT
|
||||
CNT += 1
|
||||
async with CM():
|
||||
CNT += 1000
|
||||
CNT += 10000
|
||||
|
||||
with self.assertRaises(ZeroDivisionError):
|
||||
run_async(foo())
|
||||
self.assertEqual(CNT, 1)
|
||||
|
||||
def test_for_1(self):
|
||||
aiter_calls = 0
|
||||
|
||||
|
@ -859,6 +880,20 @@ class CoroutineTest(unittest.TestCase):
|
|||
run_async(main())
|
||||
self.assertEqual(I, 20555255)
|
||||
|
||||
def test_for_7(self):
|
||||
CNT = 0
|
||||
class AI:
|
||||
async def __aiter__(self):
|
||||
1/0
|
||||
async def foo():
|
||||
nonlocal CNT
|
||||
async for i in AI():
|
||||
CNT += 1
|
||||
CNT += 10
|
||||
with self.assertRaises(ZeroDivisionError):
|
||||
run_async(foo())
|
||||
self.assertEqual(CNT, 0)
|
||||
|
||||
|
||||
class CoroAsyncIOCompatTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue