kopia lustrzana https://github.com/micropython/micropython
tests/basics: Add tests to improve coverage of binary.c.
rodzic
ea6a958393
commit
65574f817a
|
@ -0,0 +1,12 @@
|
||||||
|
# test MicroPython-specific features of array.array
|
||||||
|
import array
|
||||||
|
|
||||||
|
# arrays of objects
|
||||||
|
a = array.array('O')
|
||||||
|
a.append(1)
|
||||||
|
print(a[0])
|
||||||
|
|
||||||
|
# arrays of pointers
|
||||||
|
a = array.array('P')
|
||||||
|
a.append(1)
|
||||||
|
print(a[0])
|
|
@ -0,0 +1,2 @@
|
||||||
|
1
|
||||||
|
1
|
|
@ -61,6 +61,10 @@ print(struct.unpack(">q", b"\xf2\x34\x56\x78\x90\x12\x34\x56"))
|
||||||
print(struct.unpack("<I", b"\xff\xff\xff\xff"))
|
print(struct.unpack("<I", b"\xff\xff\xff\xff"))
|
||||||
print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
|
print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
|
||||||
|
|
||||||
|
# check small int overflow
|
||||||
|
print(struct.unpack("<i", b'\xff\xff\xff\x7f'))
|
||||||
|
print(struct.unpack("<q", b'\xff\xff\xff\xff\xff\xff\xff\x7f'))
|
||||||
|
|
||||||
# network byte order
|
# network byte order
|
||||||
print(struct.pack('!i', 123))
|
print(struct.pack('!i', 123))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# 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])
|
|
@ -0,0 +1 @@
|
||||||
|
True
|
Ładowanie…
Reference in New Issue