Skip to content

Commit 65574f8

Browse files
flowergrassdpgeorge
authored andcommitted
tests/basics: Add tests to improve coverage of binary.c.
1 parent ea6a958 commit 65574f8

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

tests/basics/array_micropython.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# test MicroPython-specific features of array.array
2+
import array
3+
4+
# arrays of objects
5+
a = array.array('O')
6+
a.append(1)
7+
print(a[0])
8+
9+
# arrays of pointers
10+
a = array.array('P')
11+
a.append(1)
12+
print(a[0])
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
1

tests/basics/struct1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
print(struct.unpack("<I", b"\xff\xff\xff\xff"))
6262
print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
6363

64+
# check small int overflow
65+
print(struct.unpack("<i", b'\xff\xff\xff\x7f'))
66+
print(struct.unpack("<q", b'\xff\xff\xff\xff\xff\xff\xff\x7f'))
67+
6468
# network byte order
6569
print(struct.pack('!i', 123))
6670

tests/basics/struct_micropython.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# test MicroPython-specific features of struct
2+
3+
try:
4+
import ustruct as struct
5+
except:
6+
try:
7+
import struct
8+
except ImportError:
9+
import sys
10+
print("SKIP")
11+
sys.exit()
12+
13+
class A():
14+
pass
15+
16+
# pack and unpack objects
17+
o = A()
18+
s = struct.pack("<O", o)
19+
o2 = struct.unpack("<O", s)
20+
print(o is o2[0])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
True

0 commit comments

Comments
 (0)