diff options
Diffstat (limited to 'tests/micropython')
| -rw-r--r-- | tests/micropython/ringio.py | 48 | ||||
| -rw-r--r-- | tests/micropython/ringio.py.exp | 16 | ||||
| -rw-r--r-- | tests/micropython/ringio_async.py | 36 | ||||
| -rw-r--r-- | tests/micropython/ringio_async.py.exp | 4 |
4 files changed, 104 insertions, 0 deletions
diff --git a/tests/micropython/ringio.py b/tests/micropython/ringio.py new file mode 100644 index 000000000..45774bc2e --- /dev/null +++ b/tests/micropython/ringio.py @@ -0,0 +1,48 @@ +# Check that micropython.RingIO works correctly. + +import micropython + +try: + micropython.RingIO +except AttributeError: + print("SKIP") + raise SystemExit + +rb = micropython.RingIO(16) +print(rb) + +print(rb.any()) + +rb.write(b"\x00") +print(rb.any()) + +rb.write(b"\x00") +print(rb.any()) + +print(rb.read(2)) +print(rb.any()) + + +rb.write(b"\x00\x01") +print(rb.read()) + +print(rb.read(1)) + +# Try to write more data than can fit at one go. +print(rb.write(b"\x00\x01" * 10)) +print(rb.write(b"\x00")) +print(rb.read()) + + +ba = bytearray(17) +rb = micropython.RingIO(ba) +print(rb) +print(rb.write(b"\x00\x01" * 10)) +print(rb.write(b"\x00")) +print(rb.read()) + +try: + # Size must be int. + micropython.RingIO(None) +except TypeError as ex: + print(ex) diff --git a/tests/micropython/ringio.py.exp b/tests/micropython/ringio.py.exp new file mode 100644 index 000000000..b27ea472c --- /dev/null +++ b/tests/micropython/ringio.py.exp @@ -0,0 +1,16 @@ +<RingIO> +0 +1 +2 +b'\x00\x00' +0 +b'\x00\x01' +b'' +16 +0 +b'\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01' +<RingIO> +16 +0 +b'\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01' +can't convert NoneType to int diff --git a/tests/micropython/ringio_async.py b/tests/micropython/ringio_async.py new file mode 100644 index 000000000..2a4befc35 --- /dev/null +++ b/tests/micropython/ringio_async.py @@ -0,0 +1,36 @@ +# Check that micropython.RingIO works correctly with asyncio.Stream. + +import micropython + +try: + import asyncio + + asyncio.StreamWriter + micropython.RingIO +except (AttributeError, ImportError): + print("SKIP") + raise SystemExit + +rb = micropython.RingIO(16) +rba = asyncio.StreamWriter(rb) + +data = b"ABC123" * 20 +print("w", len(data)) + + +async def data_writer(): + global data + rba.write(data) + await rba.drain() + + +async def main(): + task = asyncio.create_task(data_writer()) + await asyncio.sleep_ms(10) + read = await rba.readexactly(len(data)) + print(read) + print("r", len(read)) + print(read == data) + + +asyncio.run(main()) diff --git a/tests/micropython/ringio_async.py.exp b/tests/micropython/ringio_async.py.exp new file mode 100644 index 000000000..dfeb71d89 --- /dev/null +++ b/tests/micropython/ringio_async.py.exp @@ -0,0 +1,4 @@ +w 120 +b'ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123' +r 120 +True |
