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:
@@ -1,5 +1,4 @@
|
|||||||
# Test get_event_loop()
|
# Test get_event_loop()
|
||||||
# Note: CPython deprecated get_event_loop() so this test needs a .exp
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -7,6 +6,11 @@ except ImportError:
|
|||||||
print("SKIP")
|
print("SKIP")
|
||||||
raise SystemExit
|
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():
|
async def main():
|
||||||
print("start")
|
print("start")
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
start
|
|
||||||
end
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
# Test Loop.new_event_loop()
|
# Test Loop.new_event_loop()
|
||||||
# Note: CPython deprecated get_event_loop() so this test needs a .exp
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -7,6 +6,11 @@ except ImportError:
|
|||||||
print("SKIP")
|
print("SKIP")
|
||||||
raise SystemExit
|
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():
|
async def task():
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
start
|
|
||||||
task 0
|
|
||||||
stop
|
|
||||||
start
|
|
||||||
task 0
|
|
||||||
stop
|
|
||||||
Reference in New Issue
Block a user