summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-11-04 08:51:20 (GMT)
committerGitHub <noreply@github.com>2024-11-04 08:51:20 (GMT)
commitfe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3 (patch)
treea5be0f4c827f80f43dcacc6a967a22f652d21cf1 /Lib/test/test_asyncio
parent0d80777981f95bbc79b146fc78b2189c82521ab9 (diff)
downloadcpython-fe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3.zip
cpython-fe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3.tar.gz
cpython-fe5a6ab7bea927e887b7b3c2d4e8fe8eac7106c3.tar.bz2
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')
-rw-r--r--Lib/test/test_asyncio/test_events.py34
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py6
2 files changed, 11 insertions, 29 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 4dcf9f0..2ab638d 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)
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 9ae54b6..021f454 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -1195,8 +1195,7 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
if pid == 0:
# child
try:
- with self.assertWarns(DeprecationWarning):
- loop = asyncio.get_event_loop_policy().get_event_loop()
+ loop = asyncio.get_event_loop()
os.write(w, b'LOOP:' + str(id(loop)).encode())
except RuntimeError:
os.write(w, b'NO LOOP')
@@ -1207,8 +1206,7 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
else:
# parent
result = os.read(r, 100)
- self.assertEqual(result[:5], b'LOOP:', result)
- self.assertNotEqual(int(result[5:]), id(loop))
+ self.assertEqual(result, b'NO LOOP')
wait_process(pid, exitcode=0)
@hashlib_helper.requires_hashdigest('md5')