diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-06-08 16:01:38 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-06-19 17:33:03 +1000 |
commit | 6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54 (patch) | |
tree | 08f41a4d0cd48fa5c0bc49519832ac2faba6923a /tests/extmod/asyncio_task_done.py | |
parent | 2fbc08c462e247e7f78460783c9a07c76c5b762e (diff) | |
download | micropython-6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54.tar.gz micropython-6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54.zip |
tests: Rename uasyncio to asyncio.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/extmod/asyncio_task_done.py')
-rw-r--r-- | tests/extmod/asyncio_task_done.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/extmod/asyncio_task_done.py b/tests/extmod/asyncio_task_done.py new file mode 100644 index 0000000000..7cc493a122 --- /dev/null +++ b/tests/extmod/asyncio_task_done.py @@ -0,0 +1,63 @@ +# Test the Task.done() method + +try: + import asyncio +except ImportError: + print("SKIP") + raise SystemExit + + +async def task(t, exc=None): + print("task start") + if t >= 0: + await asyncio.sleep(t) + if exc: + raise exc + print("task done") + + +async def main(): + # Task that finishes immediately. + print("=" * 10) + t = asyncio.create_task(task(-1)) + print(t.done()) + await asyncio.sleep(0) + print(t.done()) + await t + print(t.done()) + + # Task that starts, runs and finishes. + print("=" * 10) + t = asyncio.create_task(task(0.01)) + print(t.done()) + await asyncio.sleep(0) + print(t.done()) + await t + print(t.done()) + + # Task that raises immediately. + print("=" * 10) + t = asyncio.create_task(task(-1, ValueError)) + print(t.done()) + await asyncio.sleep(0) + print(t.done()) + try: + await t + except ValueError as er: + print(repr(er)) + print(t.done()) + + # Task that raises after a delay. + print("=" * 10) + t = asyncio.create_task(task(0.01, ValueError)) + print(t.done()) + await asyncio.sleep(0) + print(t.done()) + try: + await t + except ValueError as er: + print(repr(er)) + print(t.done()) + + +asyncio.run(main()) |