aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_events.py
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-11-04 14:21:20 +0530
committerGitHub <noreply@github.com>2024-11-04 14:21:20 +0530
commitfe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3 (patch)
treea5be0f4c827f80f43dcacc6a967a22f652d21cf1 /Lib/test/test_asyncio/test_events.py
parent0d80777981f95bbc79b146fc78b2189c82521ab9 (diff)
downloadcpython-fe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3.tar.gz
cpython-fe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3.zip
gh-126353: remove implicit creation of loop from `asyncio.get_event_loop` (#126354)
Remove implicit creation of loop from `asyncio.get_event_loop`. This is a step forward of deprecating the policy system of asyncio.
Diffstat (limited to 'Lib/test/test_asyncio/test_events.py')
-rw-r--r--Lib/test/test_asyncio/test_events.py34
1 files changed, 9 insertions, 25 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 4dcf9f0e403..2ab638dc527 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2704,33 +2704,22 @@ class PolicyTests(unittest.TestCase):
def test_get_event_loop(self):
policy = asyncio.DefaultEventLoopPolicy()
self.assertIsNone(policy._local._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)
- self.assertIs(loop, policy.get_event_loop())
- loop.close()
+ with self.assertRaises(RuntimeError):
+ loop = policy.get_event_loop()
+ self.assertIsNone(policy._local._loop)
- def test_get_event_loop_calls_set_event_loop(self):
+ def test_get_event_loop_does_not_call_set_event_loop(self):
policy = asyncio.DefaultEventLoopPolicy()
with mock.patch.object(
policy, "set_event_loop",
wraps=policy.set_event_loop) as m_set_event_loop:
- with self.assertWarns(DeprecationWarning) as cm:
+ with self.assertRaises(RuntimeError):
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
- # the child watcher correctly)
- m_set_event_loop.assert_called_with(loop)
-
- loop.close()
+ m_set_event_loop.assert_not_called()
def test_get_event_loop_after_set_none(self):
policy = asyncio.DefaultEventLoopPolicy()
@@ -2912,17 +2901,12 @@ class GetEventLoopTestsMixin:
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)
- with self.assertWarns(DeprecationWarning) as cm:
- loop2 = asyncio.get_event_loop()
- self.addCleanup(loop2.close)
- self.assertEqual(cm.filename, __file__)
- asyncio.set_event_loop(None)
with self.assertRaisesRegex(RuntimeError, 'no current'):
asyncio.get_event_loop()
- with self.assertRaisesRegex(RuntimeError, 'no running'):
- asyncio.get_running_loop()
- self.assertIs(asyncio._get_running_loop(), None)
+ asyncio.set_event_loop(None)
+ with self.assertRaisesRegex(RuntimeError, 'no current'):
+ asyncio.get_event_loop()
async def func():
self.assertIs(asyncio.get_event_loop(), loop)