mirror of
https://github.com/python/cpython.git
synced 2025-08-15 06:10:47 +00:00
[3.9] bpo-45097: Remove incorrect deprecation warnings in asyncio. (GH-28153)
Deprecation warnings about the loop argument were incorrectly emitted in cases when the loop argument was used inside the asyncio library, not from user code.
This commit is contained in:
parent
ce83e42437
commit
c967bd523c
11 changed files with 234 additions and 181 deletions
|
@ -1077,6 +1077,84 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual(finalized, 2)
|
||||
|
||||
def test_async_gen_asyncio_shutdown_02(self):
|
||||
messages = []
|
||||
|
||||
def exception_handler(loop, context):
|
||||
messages.append(context)
|
||||
|
||||
async def async_iterate():
|
||||
yield 1
|
||||
yield 2
|
||||
|
||||
it = async_iterate()
|
||||
async def main():
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.set_exception_handler(exception_handler)
|
||||
|
||||
async for i in it:
|
||||
break
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
self.assertEqual(messages, [])
|
||||
|
||||
def test_async_gen_asyncio_shutdown_exception_01(self):
|
||||
messages = []
|
||||
|
||||
def exception_handler(loop, context):
|
||||
messages.append(context)
|
||||
|
||||
async def async_iterate():
|
||||
try:
|
||||
yield 1
|
||||
yield 2
|
||||
finally:
|
||||
1/0
|
||||
|
||||
it = async_iterate()
|
||||
async def main():
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.set_exception_handler(exception_handler)
|
||||
|
||||
async for i in it:
|
||||
break
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
message, = messages
|
||||
self.assertEqual(message['asyncgen'], it)
|
||||
self.assertIsInstance(message['exception'], ZeroDivisionError)
|
||||
self.assertIn('an error occurred during closing of asynchronous generator',
|
||||
message['message'])
|
||||
|
||||
def test_async_gen_asyncio_shutdown_exception_02(self):
|
||||
messages = []
|
||||
|
||||
def exception_handler(loop, context):
|
||||
messages.append(context)
|
||||
|
||||
async def async_iterate():
|
||||
try:
|
||||
yield 1
|
||||
yield 2
|
||||
finally:
|
||||
1/0
|
||||
|
||||
async def main():
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.set_exception_handler(exception_handler)
|
||||
|
||||
async for i in async_iterate():
|
||||
break
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
message, = messages
|
||||
self.assertIsInstance(message['exception'], ZeroDivisionError)
|
||||
self.assertIn('unhandled exception during asyncio.run() shutdown',
|
||||
message['message'])
|
||||
|
||||
def test_async_gen_expression_01(self):
|
||||
async def arange(n):
|
||||
for i in range(n):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue