blob: 4109288798448e41bae994208bbc3bda184223c4 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# 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))
try:
# Buffer may not be empty
micropython.RingIO(bytearray(0))
except ValueError as ex:
print(type(ex))
try:
# Buffer may not be too small
micropython.RingIO(bytearray(1))
except ValueError as ex:
print(type(ex))
try:
# Size may not be too small
micropython.RingIO(0)
except ValueError as ex:
print(type(ex))
|