Blame SOURCES/0001-Avoid-manual-async-loop-management.patch

c53138
From 484399f482675d7a45c68adbedfadef338da2b31 Mon Sep 17 00:00:00 2001
c53138
From: Carl George <carlwgeorge@gmail.com>
c53138
Date: Sat, 7 Dec 2024 01:52:41 -0600
c53138
Subject: [PATCH] Avoid manual async loop management
c53138
c53138
Python 3.14 removes the implicit creation of an event loop when running
c53138
asyncio.get_event_loop().  Rather than manually managing the loop
c53138
creation, switch the async tests to use the higher level asyncio.run()
c53138
interface, as recommended by the standard library docs.
c53138
c53138
https://docs.python.org/dev/whatsnew/3.14.html#id4
c53138
c53138
Resolves #741
c53138
---
c53138
 tests/sh_test.py | 24 ++++++++++++------------
c53138
 1 file changed, 12 insertions(+), 12 deletions(-)
c53138
c53138
diff --git a/tests/sh_test.py b/tests/sh_test.py
c53138
index d12c3dc..8a87fd6 100644
c53138
--- a/tests/sh_test.py
c53138
+++ b/tests/sh_test.py
c53138
@@ -1707,7 +1707,6 @@ print("hello")
c53138
         )
c53138
 
c53138
         alternating = []
c53138
-        q = AQueue()
c53138
 
c53138
         async def producer(q):
c53138
             alternating.append(1)
c53138
@@ -1722,9 +1721,11 @@ print("hello")
c53138
             self.assertEqual(msg, "hello")
c53138
             alternating.append(2)
c53138
 
c53138
-        loop = asyncio.get_event_loop()
c53138
-        fut = asyncio.gather(producer(q), consumer(q))
c53138
-        loop.run_until_complete(fut)
c53138
+        async def main():
c53138
+            q = AQueue()
c53138
+            await asyncio.gather(producer(q), consumer(q))
c53138
+
c53138
+        asyncio.run(main())
c53138
         self.assertListEqual(alternating, [1, 2, 1, 2])
c53138
 
c53138
     def test_async_exc(self):
c53138
@@ -1733,8 +1734,7 @@ print("hello")
c53138
         async def producer():
c53138
             await python(py.name, _async=True)
c53138
 
c53138
-        loop = asyncio.get_event_loop()
c53138
-        self.assertRaises(sh.ErrorReturnCode_34, loop.run_until_complete, producer())
c53138
+        self.assertRaises(sh.ErrorReturnCode_34, asyncio.run, producer())
c53138
 
c53138
     def test_async_iter(self):
c53138
         py = create_tmp_test(
c53138
@@ -1743,7 +1743,6 @@ for i in range(5):
c53138
     print(i)
c53138
 """
c53138
         )
c53138
-        q = AQueue()
c53138
 
c53138
         # this list will prove that our coroutines are yielding to eachother as each
c53138
         # line is produced
c53138
@@ -1763,9 +1762,11 @@ for i in range(5):
c53138
                     return
c53138
                 alternating.append(2)
c53138
 
c53138
-        loop = asyncio.get_event_loop()
c53138
-        res = asyncio.gather(producer(q), consumer(q))
c53138
-        loop.run_until_complete(res)
c53138
+        async def main():
c53138
+            q = AQueue()
c53138
+            await asyncio.gather(producer(q), consumer(q))
c53138
+
c53138
+        asyncio.run(main())
c53138
         self.assertListEqual(alternating, [1, 2, 1, 2, 1, 2, 1, 2, 1, 2])
c53138
 
c53138
     def test_async_iter_exc(self):
c53138
@@ -1783,8 +1784,7 @@ exit(34)
c53138
             async for line in python(py.name, _async=True):
c53138
                 lines.append(int(line.strip()))
c53138
 
c53138
-        loop = asyncio.get_event_loop()
c53138
-        self.assertRaises(sh.ErrorReturnCode_34, loop.run_until_complete, producer())
c53138
+        self.assertRaises(sh.ErrorReturnCode_34, asyncio.run, producer())
c53138
 
c53138
     def test_handle_both_out_and_err(self):
c53138
         py = create_tmp_test(
c53138
-- 
c53138
2.47.1
c53138