diff options
author | Damien George <damien.p.george@gmail.com> | 2017-03-14 18:27:43 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-03-14 18:27:43 +1100 |
commit | 05fec17d9b126ee680095110fd520162669a6ce7 (patch) | |
tree | 9b8b38d085d775ac8cae2cbb1bbc62c4194893d3 | |
parent | 77cbd173df449e8e6eb79cba75b341f1721be377 (diff) | |
download | micropython-05fec17d9b126ee680095110fd520162669a6ce7.tar.gz micropython-05fec17d9b126ee680095110fd520162669a6ce7.zip |
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.
-rw-r--r-- | tests/basics/struct_micropython.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/basics/struct_micropython.py b/tests/basics/struct_micropython.py index e3b0ea5086..53306dad67 100644 --- a/tests/basics/struct_micropython.py +++ b/tests/basics/struct_micropython.py @@ -18,3 +18,16 @@ 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 |