summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/extmod/uctypes_bytearray.py3
-rw-r--r--tests/extmod/uctypes_bytearray.py.exp1
-rw-r--r--tests/extmod/uctypes_byteat.py10
-rw-r--r--tests/extmod/uctypes_byteat.py.exp2
-rw-r--r--tests/extmod/uctypes_error.py37
-rw-r--r--tests/extmod/uctypes_error.py.exp4
-rw-r--r--tests/extmod/uctypes_sizeof.py5
-rw-r--r--tests/extmod/uctypes_sizeof.py.exp1
-rw-r--r--tests/extmod/uctypes_sizeof_float.py8
-rw-r--r--tests/extmod/uctypes_sizeof_float.py.exp2
10 files changed, 73 insertions, 0 deletions
diff --git a/tests/extmod/uctypes_bytearray.py b/tests/extmod/uctypes_bytearray.py
index 61c7da271..77c93c376 100644
--- a/tests/extmod/uctypes_bytearray.py
+++ b/tests/extmod/uctypes_bytearray.py
@@ -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))
diff --git a/tests/extmod/uctypes_bytearray.py.exp b/tests/extmod/uctypes_bytearray.py.exp
index 294f8a5fa..7c84edbb6 100644
--- a/tests/extmod/uctypes_bytearray.py.exp
+++ b/tests/extmod/uctypes_bytearray.py.exp
@@ -1,2 +1,3 @@
bytearray(b'01')
<class 'struct'>
+bytearray(b'0123')
diff --git a/tests/extmod/uctypes_byteat.py b/tests/extmod/uctypes_byteat.py
new file mode 100644
index 000000000..ab2535db8
--- /dev/null
+++ b/tests/extmod/uctypes_byteat.py
@@ -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))
diff --git a/tests/extmod/uctypes_byteat.py.exp b/tests/extmod/uctypes_byteat.py.exp
new file mode 100644
index 000000000..e1ae4d053
--- /dev/null
+++ b/tests/extmod/uctypes_byteat.py.exp
@@ -0,0 +1,2 @@
+b'0123'
+bytearray(b'0123')
diff --git a/tests/extmod/uctypes_error.py b/tests/extmod/uctypes_error.py
new file mode 100644
index 000000000..95ba0fad4
--- /dev/null
+++ b/tests/extmod/uctypes_error.py
@@ -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')
diff --git a/tests/extmod/uctypes_error.py.exp b/tests/extmod/uctypes_error.py.exp
new file mode 100644
index 000000000..802c260d2
--- /dev/null
+++ b/tests/extmod/uctypes_error.py.exp
@@ -0,0 +1,4 @@
+TypeError
+TypeError
+TypeError
+TypeError
diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py
index 5a6adb437..e42e06c92 100644
--- a/tests/extmod/uctypes_sizeof.py
+++ b/tests/extmod/uctypes_sizeof.py
@@ -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")
diff --git a/tests/extmod/uctypes_sizeof.py.exp b/tests/extmod/uctypes_sizeof.py.exp
index fb74def60..b35b11aa0 100644
--- a/tests/extmod/uctypes_sizeof.py.exp
+++ b/tests/extmod/uctypes_sizeof.py.exp
@@ -4,3 +4,4 @@
TypeError
6
1
+TypeError
diff --git a/tests/extmod/uctypes_sizeof_float.py b/tests/extmod/uctypes_sizeof_float.py
new file mode 100644
index 000000000..1ba8871bd
--- /dev/null
+++ b/tests/extmod/uctypes_sizeof_float.py
@@ -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}))
diff --git a/tests/extmod/uctypes_sizeof_float.py.exp b/tests/extmod/uctypes_sizeof_float.py.exp
new file mode 100644
index 000000000..de7818072
--- /dev/null
+++ b/tests/extmod/uctypes_sizeof_float.py.exp
@@ -0,0 +1,2 @@
+4
+8