mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
tests: Rename uasyncio to asyncio.
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
2fbc08c462
commit
6027c41c8f
@@ -1,13 +1,10 @@
|
||||
# Test that tasks return their value correctly to the caller
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def foo():
|
||||
@@ -1,11 +1,8 @@
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
import time
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def forever():
|
||||
@@ -2,13 +2,10 @@
|
||||
# That tasks which continuously cancel each other don't take over the scheduler
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(id, other):
|
||||
@@ -2,13 +2,10 @@
|
||||
# That tasks which keeps being cancelled by multiple other tasks gets a chance to run
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task_a():
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test a task cancelling itself (currently unsupported)
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task():
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test cancelling a task
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(s, allow_cancel):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test cancelling a task that is waiting on a task that just finishes.
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def sleep_task():
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test current_task() function
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(result):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test Event class
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(id, ev):
|
||||
@@ -2,13 +2,10 @@
|
||||
# That tasks which continuously wait on events don't take over the scheduler
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task1(id):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test general exception handling
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
# main task raising an exception
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test fairness of scheduler
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(id, t):
|
||||
@@ -1,13 +1,10 @@
|
||||
# test uasyncio.gather() function
|
||||
# test asyncio.gather() function
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def factorial(name, number):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test uasyncio.gather() function, features that are not implemented.
|
||||
# Test asyncio.gather() function, features that are not implemented.
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
def custom_handler(loop, context):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test get_event_loop()
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def main():
|
||||
@@ -1,6 +1,6 @@
|
||||
# test that the following do not use the heap:
|
||||
# - basic scheduling of tasks
|
||||
# - uasyncio.sleep_ms
|
||||
# - asyncio.sleep_ms
|
||||
# - StreamWriter.write, stream is blocked and data to write is a bytes object
|
||||
# - StreamWriter.write, when stream is not blocked
|
||||
|
||||
@@ -25,13 +25,10 @@ except RuntimeError:
|
||||
raise SystemExit
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
class TestStream:
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test Lock class
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task_loop(id, lock):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test that locks work when cancelling multiple waiters on the lock
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(i, lock, lock_flag):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test Loop.stop() to stop the event loop
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task():
|
||||
@@ -3,7 +3,7 @@
|
||||
# - wait_for_ms
|
||||
|
||||
try:
|
||||
import time, uasyncio
|
||||
import time, asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
@@ -11,7 +11,7 @@ except ImportError:
|
||||
|
||||
async def task(id, t):
|
||||
print("task start", id)
|
||||
await uasyncio.sleep_ms(t)
|
||||
await asyncio.sleep_ms(t)
|
||||
print("task end", id)
|
||||
return id * 2
|
||||
|
||||
@@ -19,25 +19,25 @@ async def task(id, t):
|
||||
async def main():
|
||||
# Simple sleep_ms
|
||||
t0 = time.ticks_ms()
|
||||
await uasyncio.sleep_ms(1)
|
||||
await asyncio.sleep_ms(1)
|
||||
print(time.ticks_diff(time.ticks_ms(), t0) < 100)
|
||||
|
||||
try:
|
||||
# Sleep 1ms beyond maximum allowed sleep value
|
||||
await uasyncio.sleep_ms(time.ticks_add(0, -1) // 2 + 1)
|
||||
await asyncio.sleep_ms(time.ticks_add(0, -1) // 2 + 1)
|
||||
except OverflowError:
|
||||
print("OverflowError")
|
||||
|
||||
# When task finished before the timeout
|
||||
print(await uasyncio.wait_for_ms(task(1, 5), 50))
|
||||
print(await asyncio.wait_for_ms(task(1, 5), 50))
|
||||
|
||||
# When timeout passes and task is cancelled
|
||||
try:
|
||||
print(await uasyncio.wait_for_ms(task(2, 50), 5))
|
||||
except uasyncio.TimeoutError:
|
||||
print(await asyncio.wait_for_ms(task(2, 50), 5))
|
||||
except asyncio.TimeoutError:
|
||||
print("timeout")
|
||||
|
||||
print("finish")
|
||||
|
||||
|
||||
uasyncio.run(main())
|
||||
asyncio.run(main())
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test Loop.new_event_loop()
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task():
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test that tasks return their value correctly to the caller
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
def custom_handler(loop, context):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test the Task.done() method
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(t, exc=None):
|
||||
@@ -1,7 +1,7 @@
|
||||
# Test Event class
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test asyncio.wait_for
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(id, t):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test asyncio.wait_for, with forwarding cancellation
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def awaiting(t, return_if_fail):
|
||||
@@ -1,13 +1,10 @@
|
||||
# Test waiting on a task
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
import asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
import time
|
||||
Reference in New Issue
Block a user