1# test MicroPython-specific features of struct
2
3try:
4    import ustruct as struct
5except:
6    try:
7        import struct
8    except ImportError:
9        print("SKIP")
10        raise SystemExit
11
12class A():
13    pass
14
15# pack and unpack objects
16o = A()
17s = struct.pack("<O", o)
18o2 = struct.unpack("<O", s)
19print(o is o2[0])
20
21# pack can accept less arguments than required for the format spec
22print(struct.pack('<2I', 1))
23
24# pack and unpack pointer to a string
25# This requires uctypes to get the address of the string and instead of
26# putting this in a dedicated test that can be skipped we simply pass
27# if the import fails.
28try:
29    import uctypes
30    o = uctypes.addressof('abc')
31    s = struct.pack("<S", o)
32    o2 = struct.unpack("<S", s)
33    assert o2[0] == 'abc'
34except ImportError:
35    pass
36