Skip to content

Commit 05fec17

Browse files
committed
tests/basics/struct_micropython: Add test for 'S' typecode in ustruct.
The 'S' typecode is a uPy extension so it should be grouped with the other extension (namely 'O' typecode). Testing 'S' needs uctypes which is an extmod module and not always available, so this test is made optional and will only be run on ports that have (u)struct and uctypes. Otherwise it will be silently skipped.
1 parent 77cbd17 commit 05fec17

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/basics/struct_micropython.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ class A():
1818
s = struct.pack("<O", o)
1919
o2 = struct.unpack("<O", s)
2020
print(o is o2[0])
21+
22+
# pack and unpack pointer to a string
23+
# This requires uctypes to get the address of the string and instead of
24+
# putting this in a dedicated test that can be skipped we simply pass
25+
# if the import fails.
26+
try:
27+
import uctypes
28+
o = uctypes.addressof('abc')
29+
s = struct.pack("<S", o)
30+
o2 = struct.unpack("<S", s)
31+
assert o2[0] == 'abc'
32+
except ImportError:
33+
pass

0 commit comments

Comments
 (0)