Skip to content

Commit 66d08eb

Browse files
committed
moductypes: Add test for accessing UINT8 array.
1 parent 6d287a6 commit 66d08eb

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

tests/extmod/uctypes_bytearray.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import uctypes
2+
3+
desc = {
4+
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
5+
"arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2),
6+
}
7+
8+
data = bytearray(b"01234567")
9+
10+
S = uctypes.struct(desc, uctypes.addressof(data), uctypes.LITTLE_ENDIAN)
11+
12+
# Arrays of UINT8 are accessed as bytearrays
13+
print(S.arr)
14+
# But not INT8, because value range is different
15+
print(type(S.arr2))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bytearray(b'01')
2+
<class 'struct'>

0 commit comments

Comments
 (0)