tests/extmod: Add some uctypes tests to improve coverage of that module.
This commit is contained in:
parent
35a759dc1d
commit
d35c6ffc84
|
@ -17,3 +17,6 @@ S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
|
|||
print(S.arr)
|
||||
# But not INT8, because value range is different
|
||||
print(type(S.arr2))
|
||||
|
||||
# convert to buffer
|
||||
print(bytearray(S))
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
bytearray(b'01')
|
||||
<class 'struct'>
|
||||
bytearray(b'0123')
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
data = bytearray(b'01234567')
|
||||
|
||||
print(uctypes.bytes_at(uctypes.addressof(data), 4))
|
||||
print(uctypes.bytearray_at(uctypes.addressof(data), 4))
|
|
@ -0,0 +1,2 @@
|
|||
b'0123'
|
||||
bytearray(b'0123')
|
|
@ -0,0 +1,37 @@
|
|||
# test general errors with uctypes
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
data = bytearray(b"01234567")
|
||||
|
||||
# del subscr not supported
|
||||
S = uctypes.struct(uctypes.addressof(data), {})
|
||||
try:
|
||||
del S[0]
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# list is an invalid descriptor
|
||||
S = uctypes.struct(uctypes.addressof(data), [])
|
||||
try:
|
||||
S.x
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# can't access attribute with invalid descriptor
|
||||
S = uctypes.struct(uctypes.addressof(data), {'x':[]})
|
||||
try:
|
||||
S.x
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
|
||||
# can't assign to aggregate
|
||||
S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)})
|
||||
try:
|
||||
S.x = 1
|
||||
except TypeError:
|
||||
print('TypeError')
|
|
@ -0,0 +1,4 @@
|
|||
TypeError
|
||||
TypeError
|
||||
TypeError
|
||||
TypeError
|
|
@ -40,3 +40,8 @@ assert uctypes.sizeof(S.arr4) == 6
|
|||
print(uctypes.sizeof(S.sub))
|
||||
assert uctypes.sizeof(S.sub) == 1
|
||||
|
||||
# invalid descriptor
|
||||
try:
|
||||
print(uctypes.sizeof([]))
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
TypeError
|
||||
6
|
||||
1
|
||||
TypeError
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(uctypes.sizeof({'f':uctypes.FLOAT32}))
|
||||
print(uctypes.sizeof({'f':uctypes.FLOAT64}))
|
|
@ -0,0 +1,2 @@
|
|||
4
|
||||
8
|
Loading…
Reference in New Issue