tests: Replace umodule with module everywhere.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared
2022-08-18 16:57:45 +10:00
parent 5e50975a6d
commit 4216bc7d13
295 changed files with 1006 additions and 1428 deletions

View File

@@ -1,11 +1,8 @@
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
a = array.array('B', [1, 2, 3])
print(a, len(a))

View File

@@ -1,12 +1,9 @@
# test array + array
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
a1 = array.array('I', [1])
a2 = array.array('I', [2])

View File

@@ -1,13 +1,10 @@
# test construction of array.array from different objects
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# tuple, list
print(array('b', (1, 2)))

View File

@@ -1,11 +1,8 @@
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# construct from something with unknown length (requires generators)
print(array('i', (i for i in range(10))))

View File

@@ -1,13 +1,10 @@
# test construction of array.array from different objects
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# raw copy from bytes, bytearray
print(array('h', b'12'))

View File

@@ -1,13 +1,10 @@
# test array types QqLl that require big-ints
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(array('L', [0, 2**32-1]))
print(array('l', [-2**31, 0, 2**31-1]))

View File

@@ -1,12 +1,9 @@
# test MicroPython-specific features of array.array
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# arrays of objects
a = array.array('O')

View File

@@ -1,9 +1,6 @@
# test await expression
try:
import usys as sys
except ImportError:
import sys
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f

View File

@@ -1,9 +1,6 @@
# test waiting within "async for" __anext__ function
try:
import usys as sys
except ImportError:
import sys
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f

View File

@@ -1,9 +1,6 @@
# test waiting within async with enter/exit functions
try:
import usys as sys
except ImportError:
import sys
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f

View File

@@ -1,10 +1,7 @@
# test attrtuple
# we can't test this type directly so we use sys.implementation object
try:
import usys as sys
except ImportError:
import sys
import sys
t = sys.implementation
# It can be just a normal tuple on small ports

View File

@@ -7,10 +7,7 @@ print(callable([]))
print(callable("dfsd"))
# modules should not be callabe
try:
import usys as sys
except ImportError:
import sys
import sys
print(callable(sys))
# builtins should be callable

View File

@@ -4,10 +4,7 @@
print('__name__' in dir())
# dir of module
try:
import usys as sys
except ImportError:
import sys
import sys
print('version' in dir(sys))
# dir of type

View File

@@ -1,12 +1,9 @@
# test construction of bytearray from different objects
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# arrays
print(bytearray(array('b', [1, 2])))

View File

@@ -1,12 +1,9 @@
# test construction of bytearray from different objects
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# arrays
print(bytearray(array('h', [1, 2])))

View File

@@ -1,12 +1,9 @@
# test bytes + other
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# should be byteorder-neutral
print(b"123" + array.array('h', [0x1515]))

View File

@@ -1,11 +1,8 @@
# test bytes + other
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(b"123" + array.array('i', [1]))

View File

@@ -1,11 +1,8 @@
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(array.array('b', [1, 2]) in b'\x01\x02\x03')
# CPython gives False here

View File

@@ -1,12 +1,9 @@
# test construction of bytes from different objects
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# arrays
print(bytes(array('b', [1, 2])))

View File

@@ -1,13 +1,10 @@
# test construction of bytes from different objects
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# arrays
print(bytes(array('h', [1, 2])))

View File

@@ -1,13 +1,10 @@
# test using an OrderedDict as the locals to construct a class
try:
from ucollections import OrderedDict
from collections import OrderedDict
except ImportError:
try:
from collections import OrderedDict
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
if not hasattr(int, "__dict__"):
print("SKIP")

View File

@@ -5,11 +5,8 @@
try:
from collections import namedtuple
except ImportError:
try:
from ucollections import namedtuple
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
_DefragResultBase = namedtuple('DefragResult', [ 'foo', 'bar' ])

View File

@@ -1,8 +1,5 @@
try:
try:
from ucollections import deque
except ImportError:
from collections import deque
from collections import deque
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,10 +1,7 @@
# Tests for deques with "check overflow" flag and other extensions
# wrt to CPython.
try:
try:
from ucollections import deque
except ImportError:
from collections import deque
from collections import deque
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,48 +1,48 @@
# test that fixed dictionaries cannot be modified
try:
import uerrno
import errno
except ImportError:
print("SKIP")
raise SystemExit
# Save a copy of uerrno.errorcode, so we can check later
# Save a copy of errno.errorcode, so we can check later
# that it hasn't been modified.
errorcode_copy = uerrno.errorcode.copy()
errorcode_copy = errno.errorcode.copy()
try:
uerrno.errorcode.popitem()
errno.errorcode.popitem()
except TypeError:
print("TypeError")
try:
uerrno.errorcode.pop(0)
errno.errorcode.pop(0)
except TypeError:
print("TypeError")
try:
uerrno.errorcode.setdefault(0, 0)
errno.errorcode.setdefault(0, 0)
except TypeError:
print("TypeError")
try:
uerrno.errorcode.update([(1, 2)])
errno.errorcode.update([(1, 2)])
except TypeError:
print("TypeError")
try:
del uerrno.errorcode[1]
del errno.errorcode[1]
except TypeError:
print("TypeError")
try:
uerrno.errorcode[1] = 'foo'
errno.errorcode[1] = 'foo'
except TypeError:
print("TypeError")
try:
uerrno.errorcode.clear()
errno.errorcode.clear()
except TypeError:
print("TypeError")
assert uerrno.errorcode == errorcode_copy
assert errno.errorcode == errorcode_copy

View File

@@ -1,25 +1,25 @@
# test errno's and uerrno module
# test errno's and errno module
try:
import uerrno
import errno
except ImportError:
print("SKIP")
raise SystemExit
# check that constants exist and are integers
print(type(uerrno.EIO))
print(type(errno.EIO))
# check that errors are rendered in a nice way
msg = str(OSError(uerrno.EIO))
msg = str(OSError(errno.EIO))
print(msg[:7], msg[-5:])
msg = str(OSError(uerrno.EIO, "details"))
msg = str(OSError(errno.EIO, "details"))
print(msg[:7], msg[-14:])
msg = str(OSError(uerrno.EIO, "details", "more details"))
msg = str(OSError(errno.EIO, "details", "more details"))
print(msg[:1], msg[-28:])
# check that unknown errno is still rendered
print(str(OSError(9999)))
# this tests a failed constant lookup in errno
errno = uerrno
errno = errno
print(errno.__name__)

View File

@@ -3,4 +3,4 @@
[Errno ] EIO: details
( , 'details', 'more details')
9999
uerrno
errno

View File

@@ -105,10 +105,7 @@ x = 4611686018427387904 # big
x = -4611686018427387904 # big
# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones
try:
import usys as sys
except ImportError:
import sys
import sys
print(sys.maxsize + 1 - 1 == sys.maxsize)
# test extraction of big int value via mp_obj_get_int_maybe

View File

@@ -1,4 +1,4 @@
import uio as io
import io
try:
io.BytesIO

View File

@@ -1,10 +1,6 @@
# Make sure that write operations on io.BytesIO don't
# change original object it was constructed from.
try:
import uio as io
except ImportError:
import io
import io
b = b"foobar"
a = io.BytesIO(b)

View File

@@ -1,9 +1,5 @@
# Extended stream operations on io.BytesIO
try:
import uio as io
except ImportError:
import io
import io
a = io.BytesIO(b"foobar")
a.seek(10)
print(a.read(10))

View File

@@ -1,8 +1,4 @@
try:
import uio as io
except ImportError:
import io
import io
a = io.BytesIO(b"foobar")
try:
a.seek(-10)

View File

@@ -1,8 +1,4 @@
try:
import uio as io
except:
import io
import io
try:
io.IOBase
except AttributeError:

View File

@@ -1,8 +1,4 @@
try:
import uio as io
except ImportError:
import io
import io
a = io.StringIO()
print('io.StringIO' in repr(a))
print(a.getvalue())

View File

@@ -1,10 +1,7 @@
# Checks that an instance type inheriting from a native base that uses
# MP_TYPE_FLAG_ITER_IS_STREAM will still have a getiter.
try:
import uio as io
except ImportError:
import io
import io
a = io.StringIO()
a.write("hello\nworld\nmicro\npython\n")

View File

@@ -1,8 +1,4 @@
try:
import uio as io
except ImportError:
import io
import io
# test __enter__/__exit__
with io.StringIO() as b:
b.write("foo")

View File

@@ -1,14 +1,14 @@
# This tests extended (MicroPython-specific) form of write:
# write(buf, len) and write(buf, offset, len)
import uio
import io
try:
uio.BytesIO
io.BytesIO
except AttributeError:
print('SKIP')
raise SystemExit
buf = uio.BytesIO()
buf = io.BytesIO()
buf.write(b"foo", 2)
print(buf.getvalue())

View File

@@ -5,13 +5,10 @@ except:
print("SKIP")
raise SystemExit
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# test reading from bytes
b = b'1234'

View File

@@ -5,13 +5,10 @@ except:
print("SKIP")
raise SystemExit
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(list(memoryview(b'\x7f\x80\x81\xff')))
print(list(memoryview(array('b', [0x7f, -0x80]))))

View File

@@ -5,13 +5,10 @@ except:
print("SKIP")
raise SystemExit
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(list(memoryview(array('i', [0x7f000000, -0x80000000]))))
print(list(memoryview(array('I', [0x7f000000, 0x80000000, 0x81000000, 0xffffffff]))))

View File

@@ -4,13 +4,10 @@ except:
print("SKIP")
raise SystemExit
try:
from uarray import array
from array import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
for code in ['b', 'h', 'i', 'q', 'f', 'd']:
print(memoryview(array(code)).itemsize)

View File

@@ -7,13 +7,10 @@ except (NameError, TypeError):
raise SystemExit
try:
import uarray as array
import array
except ImportError:
try:
import array
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# test slice assignment between memoryviews
b1 = bytearray(b'1234')

View File

@@ -1,6 +1,6 @@
# uPy behaviour only: builtin modules are read-only
import usys
import sys
try:
usys.x = 1
sys.x = 1
except AttributeError:
print("AttributeError")

View File

@@ -1,8 +1,5 @@
try:
try:
from ucollections import namedtuple
except ImportError:
from collections import namedtuple
from collections import namedtuple
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,5 @@
try:
try:
from ucollections import namedtuple
except ImportError:
from collections import namedtuple
from collections import namedtuple
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,11 +1,8 @@
try:
from collections import OrderedDict
except ImportError:
try:
from ucollections import OrderedDict
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
d = OrderedDict([(10, 20), ("b", 100), (1, 2)])
print(len(d))

View File

@@ -1,11 +1,8 @@
try:
from collections import OrderedDict
except ImportError:
try:
from ucollections import OrderedDict
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
x = OrderedDict()
y = OrderedDict()

View File

@@ -29,9 +29,9 @@ test_syntax("del ()") # can't delete empty tuple (in 3.6 we can)
# from basics/sys1.py
# uPy prints version 3.4
import usys
print(usys.version[:3])
print(usys.version_info[0], usys.version_info[1])
import sys
print(sys.version[:3])
print(sys.version_info[0], sys.version_info[1])
# from basics/exception1.py
# in 3.7 no comma is printed if there is only 1 arg (in 3.4-3.6 one is printed)

View File

@@ -51,10 +51,7 @@ print("1/" <= "1")
# this tests an internal string that doesn't have a hash with a string
# that does have a hash, but the lengths of the two strings are different
try:
import usys as sys
except ImportError:
import sys
import sys
print(sys.version == 'a long string that has a hash')
# this special string would have a hash of 0 but is incremented to 1

View File

@@ -1,11 +1,8 @@
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
import struct
except ImportError:
print("SKIP")
raise SystemExit
print(struct.calcsize("<bI"))
print(struct.unpack("<bI", b"\x80\0\0\x01\0"))

View File

@@ -1,11 +1,8 @@
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
import struct
except ImportError:
print("SKIP")
raise SystemExit
# check maximum pack on 32-bit machine
print(struct.pack("<I", 2**32 - 1))

View File

@@ -1,13 +1,10 @@
# test ustruct with a count specified before the type
# test struct with a count specified before the type
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
import struct
except ImportError:
print("SKIP")
raise SystemExit
print(struct.calcsize('0s'))
print(struct.unpack('0s', b''))

View File

@@ -1,13 +1,10 @@
# test ustruct and endian specific things
# test struct and endian specific things
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
import struct
except ImportError:
print("SKIP")
raise SystemExit
# unpack/unpack_from with unaligned native type
buf = b'0123456789'

View File

@@ -1,13 +1,10 @@
# test MicroPython-specific features of struct
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
import struct
except ImportError:
print("SKIP")
raise SystemExit
class A():
pass

View File

@@ -4,10 +4,7 @@
# and is callable (has call). The only one available is machine.Signal, which
# in turns needs PinBase.
try:
try:
import umachine as machine
except ImportError:
import machine
import machine
machine.PinBase
machine.Signal
except:

View File

@@ -29,7 +29,6 @@ except Exception as bad:
print(type(bad), bad.args[0])
try:
def gen():
yield

View File

@@ -1,10 +1,6 @@
# test sys module
try:
import usys as sys
except ImportError:
import sys
import sys
print(sys.__name__)
print(type(sys.path))
print(type(sys.argv))

View File

@@ -1,10 +1,6 @@
# test sys module's exit function
try:
import usys as sys
except ImportError:
import sys
import sys
try:
sys.exit
except AttributeError:

View File

@@ -1,9 +1,6 @@
# test sys.getsizeof() function
try:
import usys as sys
except ImportError:
import sys
import sys
try:
sys.getsizeof
except AttributeError:
@@ -19,7 +16,7 @@ print(sys.getsizeof(A()) > 0)
# Only test deque if we have it
try:
from ucollections import deque
from collections import deque
assert sys.getsizeof(deque((), 1)) > 0
except ImportError:
pass

View File

@@ -1,10 +1,6 @@
# test sys.path
try:
import usys as sys
except ImportError:
import sys
import sys
# check that this script was executed from a file of the same name
if "__file__" not in globals() or "sys_path.py" not in __file__:
print("SKIP")

View File

@@ -1,12 +1,8 @@
# test sys.tracebacklimit
try:
try:
import usys as sys
import uio as io
except ImportError:
import sys
import io
import sys
import io
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,35 +1,35 @@
Traceback (most recent call last):
File , line 62, in ftop
File , line 57, in f3
File , line 53, in f2
File , line 49, in f1
File , line 45, in f0
File , line 58, in ftop
File , line 53, in f3
File , line 49, in f2
File , line 45, in f1
File , line 41, in f0
ValueError: value
limit 4
Traceback (most recent call last):
File , line 62, in ftop
File , line 57, in f3
File , line 53, in f2
File , line 49, in f1
File , line 58, in ftop
File , line 53, in f3
File , line 49, in f2
File , line 45, in f1
ValueError: value
limit 3
Traceback (most recent call last):
File , line 62, in ftop
File , line 57, in f3
File , line 53, in f2
File , line 58, in ftop
File , line 53, in f3
File , line 49, in f2
ValueError: value
limit 2
Traceback (most recent call last):
File , line 62, in ftop
File , line 57, in f3
File , line 58, in ftop
File , line 53, in f3
ValueError: value
limit 1
Traceback (most recent call last):
File , line 62, in ftop
File , line 58, in ftop
ValueError: value
limit 0