mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
moductypes: Add test for accessing UINT8 array.
This commit is contained in:
15
tests/extmod/uctypes_bytearray.py
Normal file
15
tests/extmod/uctypes_bytearray.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import uctypes
|
||||
|
||||
desc = {
|
||||
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
|
||||
"arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2),
|
||||
}
|
||||
|
||||
data = bytearray(b"01234567")
|
||||
|
||||
S = uctypes.struct(desc, uctypes.addressof(data), uctypes.LITTLE_ENDIAN)
|
||||
|
||||
# Arrays of UINT8 are accessed as bytearrays
|
||||
print(S.arr)
|
||||
# But not INT8, because value range is different
|
||||
print(type(S.arr2))
|
||||
2
tests/extmod/uctypes_bytearray.py.exp
Normal file
2
tests/extmod/uctypes_bytearray.py.exp
Normal file
@@ -0,0 +1,2 @@
|
||||
bytearray(b'01')
|
||||
<class 'struct'>
|
||||
Reference in New Issue
Block a user