summaryrefslogtreecommitdiff
path: root/tests/micropython/ringio.py
blob: a0102ef63dafaaf5d67e6703b438a8f21d6daf1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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(type(ex))