2017-12-19 05:48:41 +00:00
|
|
|
# test general errors with uctypes
|
|
|
|
|
|
|
|
try:
|
|
|
|
import uctypes
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
data = bytearray(b"01234567")
|
|
|
|
|
|
|
|
# del subscr not supported
|
2020-03-23 02:26:08 +00:00
|
|
|
S = uctypes.struct(uctypes.addressof(data), {})
|
2017-12-19 05:48:41 +00:00
|
|
|
try:
|
|
|
|
del S[0]
|
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|
2017-12-19 05:48:41 +00:00
|
|
|
|
|
|
|
# list is an invalid descriptor
|
2020-03-23 02:26:08 +00:00
|
|
|
S = uctypes.struct(uctypes.addressof(data), [])
|
2017-12-19 05:48:41 +00:00
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
S.x
|
2017-12-19 05:48:41 +00:00
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|
2017-12-19 05:48:41 +00:00
|
|
|
|
|
|
|
# can't access attribute with invalid descriptor
|
2020-03-23 02:26:08 +00:00
|
|
|
S = uctypes.struct(uctypes.addressof(data), {"x": []})
|
2017-12-19 05:48:41 +00:00
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
S.x
|
2017-12-19 05:48:41 +00:00
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|
2017-12-19 05:48:41 +00:00
|
|
|
|
|
|
|
# can't assign to aggregate
|
2020-03-23 02:26:08 +00:00
|
|
|
S = uctypes.struct(uctypes.addressof(data), {"x": (uctypes.ARRAY | 0, uctypes.INT8 | 2)})
|
2017-12-19 05:48:41 +00:00
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
S.x = 1
|
2017-12-19 05:48:41 +00:00
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|
2018-12-10 03:29:41 +00:00
|
|
|
|
|
|
|
# unsupported unary op
|
|
|
|
try:
|
|
|
|
hash(S)
|
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|