tests/extmod: Add some uctypes tests to improve coverage of that module.

pull/3495/head
Damien George 2017-12-19 16:48:41 +11:00
rodzic 35a759dc1d
commit d35c6ffc84
10 zmienionych plików z 73 dodań i 0 usunięć

Wyświetl plik

@ -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))

Wyświetl plik

@ -1,2 +1,3 @@
bytearray(b'01')
<class 'struct'>
bytearray(b'0123')

Wyświetl plik

@ -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))

Wyświetl plik

@ -0,0 +1,2 @@
b'0123'
bytearray(b'0123')

Wyświetl plik

@ -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')

Wyświetl plik

@ -0,0 +1,4 @@
TypeError
TypeError
TypeError
TypeError

Wyświetl plik

@ -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")

Wyświetl plik

@ -4,3 +4,4 @@
TypeError
6
1
TypeError

Wyświetl plik

@ -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}))

Wyświetl plik

@ -0,0 +1,2 @@
4
8