◐ Shell
clean mode source ↗

[3.10] gh-93453: Only emit deprecation warning in asyncio.get_event_loop when a new event loop is created by ambv · Pull Request #100059 · python/cpython

Expand Up @@ -2561,8 +2561,9 @@ def test_event_loop_policy(self): def test_get_event_loop(self): policy = asyncio.DefaultEventLoopPolicy() self.assertIsNone(policy._local._loop)
loop = policy.get_event_loop() with self.assertWarns(DeprecationWarning) as cm: loop = policy.get_event_loop() self.assertEqual(cm.filename, __file__) self.assertIsInstance(loop, asyncio.AbstractEventLoop)
self.assertIs(policy._local._loop, loop) Expand All @@ -2576,7 +2577,10 @@ def test_get_event_loop_calls_set_event_loop(self): policy, "set_event_loop", wraps=policy.set_event_loop) as m_set_event_loop:
loop = policy.get_event_loop() with self.assertWarns(DeprecationWarning) as cm: loop = policy.get_event_loop() self.addCleanup(loop.close) self.assertEqual(cm.filename, __file__)
# policy._local._loop must be set through .set_event_loop() # (the unix DefaultEventLoopPolicy needs this call to attach Expand Down Expand Up @@ -2610,7 +2614,8 @@ def test_new_event_loop(self):
def test_set_event_loop(self): policy = asyncio.DefaultEventLoopPolicy() old_loop = policy.get_event_loop() old_loop = policy.new_event_loop() policy.set_event_loop(old_loop)
self.assertRaises(AssertionError, policy.set_event_loop, object())
Expand Down Expand Up @@ -2723,15 +2728,11 @@ def get_event_loop(self): asyncio.set_event_loop_policy(Policy()) loop = asyncio.new_event_loop()
with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() self.assertEqual(cm.warnings[0].filename, __file__) with self.assertRaises(TestError): asyncio.get_event_loop() asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() self.assertEqual(cm.warnings[0].filename, __file__) with self.assertRaises(TestError): asyncio.get_event_loop()
with self.assertRaisesRegex(RuntimeError, 'no running'): asyncio.get_running_loop() Expand All @@ -2745,16 +2746,11 @@ async def func(): loop.run_until_complete(func())
asyncio.set_event_loop(loop) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() self.assertEqual(cm.warnings[0].filename, __file__)
with self.assertRaises(TestError): asyncio.get_event_loop() asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() self.assertEqual(cm.warnings[0].filename, __file__) with self.assertRaises(TestError): asyncio.get_event_loop()
finally: asyncio.set_event_loop_policy(old_policy) Expand All @@ -2778,10 +2774,8 @@ def test_get_event_loop_returns_running_loop2(self): self.addCleanup(loop2.close) self.assertEqual(cm.warnings[0].filename, __file__) asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'no current'): asyncio.get_event_loop() self.assertEqual(cm.warnings[0].filename, __file__) with self.assertRaisesRegex(RuntimeError, 'no current'): asyncio.get_event_loop()
with self.assertRaisesRegex(RuntimeError, 'no running'): asyncio.get_running_loop() Expand All @@ -2795,15 +2789,11 @@ async def func(): loop.run_until_complete(func())
asyncio.set_event_loop(loop) with self.assertWarns(DeprecationWarning) as cm: self.assertIs(asyncio.get_event_loop(), loop) self.assertEqual(cm.warnings[0].filename, __file__) self.assertIs(asyncio.get_event_loop(), loop)
asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'no current'): asyncio.get_event_loop() self.assertEqual(cm.warnings[0].filename, __file__) with self.assertRaisesRegex(RuntimeError, 'no current'): asyncio.get_event_loop()
finally: asyncio.set_event_loop_policy(old_policy) Expand Down