tests/extmod: Make get_event_loop tests compatible with CPython 3.12.

Follow up to 2e852522b1: instead of having
.exp files for the get_event_loop tests, tweak them so they are compatible
with CPython 3.12.  This requires calling `asyncio.set_event_loop()` so
there is an active event loop and `asyncio.get_event_loop()` succeeds
without a warning.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-07-18 10:03:28 +10:00
parent b4b4d161c2
commit fce3cea244
4 changed files with 10 additions and 10 deletions

View File

@@ -1,5 +1,4 @@
# Test get_event_loop()
# Note: CPython deprecated get_event_loop() so this test needs a .exp
try:
import asyncio
@@ -7,6 +6,11 @@ except ImportError:
print("SKIP")
raise SystemExit
# CPython 3.12 deprecated calling get_event_loop() when there is no current event
# loop, so to make this test run on CPython requires setting the event loop.
if hasattr(asyncio, "set_event_loop"):
asyncio.set_event_loop(asyncio.new_event_loop())
async def main():
print("start")

View File

@@ -1,2 +0,0 @@
start
end

View File

@@ -1,5 +1,4 @@
# Test Loop.new_event_loop()
# Note: CPython deprecated get_event_loop() so this test needs a .exp
try:
import asyncio
@@ -7,6 +6,11 @@ except ImportError:
print("SKIP")
raise SystemExit
# CPython 3.12 deprecated calling get_event_loop() when there is no current event
# loop, so to make this test run on CPython requires setting the event loop.
if hasattr(asyncio, "set_event_loop"):
asyncio.set_event_loop(asyncio.new_event_loop())
async def task():
for i in range(4):

View File

@@ -1,6 +0,0 @@
start
task 0
stop
start
task 0
stop