summaryrefslogtreecommitdiff
path: root/tests/extmod/umsgpack_pack.py
blob: 7ea5ae8d6a9ab4b6df932a03298fe5fca4226432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
try:
    from uio import BytesIO
    import umsgpack as msgpack
except:
    try:
        from io import BytesIO
        import msgpack
    except ImportError:
        print("SKIP")
        raise SystemExit

b = BytesIO()
msgpack.pack(False, s)
print(b.getvalue())

b = BytesIO()
msgpack.pack({"a": (-1, 0, 2, [3, None], 128)}, b)
print(b.getvalue())

# pack to a small-int not allowed
try:
    msgpack.pack(123, 1)
except (AttributeError, OSError):  # CPython and uPy have different errors
    print("Exception")

# pack to an object not allowed
try:
    msgpack.pack(123, {})
except (AttributeError, OSError):  # CPython and uPy have different errors
    print("Exception")