tests/extmod/ubinascii: Add tests for bytes.hex etc.

Also make the sep test not micropython-specific.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2021-07-13 22:49:49 +10:00
parent 28aaab9590
commit f694058f2b
5 changed files with 44 additions and 25 deletions

View File

@ -0,0 +1,24 @@
if not hasattr(bytes, "fromhex"):
print("SKIP")
raise SystemExit
for x in (
b"\x00\x01\x02\x03\x04\x05\x06\x07",
b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
b"\x7f\x80\xff",
b"1234ABCDabcd",
):
print(x.hex())
print(bytearray(x).hex())
print(memoryview(x).hex())
print(x.hex(":"))
print(bytearray(x).hex(":"))
print(memoryview(x).hex(":"))
for x in (
"0001020304050607",
"08090a0b0c0d0e0f",
"7f80ff",
"313233344142434461626364",
):
print(bytes.fromhex(x))

View File

@ -7,7 +7,16 @@ except ImportError:
print("SKIP")
raise SystemExit
print(binascii.hexlify(b"\x00\x01\x02\x03\x04\x05\x06\x07"))
print(binascii.hexlify(b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"))
print(binascii.hexlify(b"\x7f\x80\xff"))
print(binascii.hexlify(b"1234ABCDabcd"))
for x in (
b"\x00\x01\x02\x03\x04\x05\x06\x07",
b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
b"\x7f\x80\xff",
b"1234ABCDabcd",
):
print(binascii.hexlify(x))
# Two-argument version (now supported in CPython)
print(binascii.hexlify(b"123", ":"))
# zero length buffer
print(binascii.hexlify(b"", b":"))

View File

@ -1,15 +0,0 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
except ImportError:
print("SKIP")
raise SystemExit
# two arguments supported in uPy but not CPython
a = binascii.hexlify(b"123", ":")
print(a)
# zero length buffer
print(binascii.hexlify(b"", b":"))

View File

@ -1,2 +0,0 @@
b'31:32:33'
b''

View File

@ -7,10 +7,13 @@ except ImportError:
print("SKIP")
raise SystemExit
print(binascii.unhexlify(b"0001020304050607"))
print(binascii.unhexlify(b"08090a0b0c0d0e0f"))
print(binascii.unhexlify(b"7f80ff"))
print(binascii.unhexlify(b"313233344142434461626364"))
for x in (
b"0001020304050607",
b"08090a0b0c0d0e0f",
b"7f80ff",
b"313233344142434461626364",
):
print(binascii.unhexlify(x))
try:
a = binascii.unhexlify(b"0") # odd buffer length