05fec17d9b
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.
34 lines
709 B
Python
34 lines
709 B
Python
# test MicroPython-specific features of struct
|
|
|
|
try:
|
|
import ustruct as struct
|
|
except:
|
|
try:
|
|
import struct
|
|
except ImportError:
|
|
import sys
|
|
print("SKIP")
|
|
sys.exit()
|
|
|
|
class A():
|
|
pass
|
|
|
|
# pack and unpack objects
|
|
o = A()
|
|
s = struct.pack("<O", o)
|
|
o2 = struct.unpack("<O", s)
|
|
print(o is o2[0])
|
|
|
|
# pack and unpack pointer to a string
|
|
# This requires uctypes to get the address of the string and instead of
|
|
# putting this in a dedicated test that can be skipped we simply pass
|
|
# if the import fails.
|
|
try:
|
|
import uctypes
|
|
o = uctypes.addressof('abc')
|
|
s = struct.pack("<S", o)
|
|
o2 = struct.unpack("<S", s)
|
|
assert o2[0] == 'abc'
|
|
except ImportError:
|
|
pass
|