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,8 +1,5 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
import binascii
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,5 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
import binascii
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,5 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
import binascii
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,5 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
import binascii
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,5 @@
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
import binascii
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,13 +1,13 @@
try:
import btree
import uio
import uerrno
import io
import errno
except ImportError:
print("SKIP")
raise SystemExit
# f = open("_test.db", "w+b")
f = uio.BytesIO()
f = io.BytesIO()
db = btree.open(f, pagesize=512)
mv = memoryview(b"bar1foo1")
@@ -68,7 +68,7 @@ print(db.seq(1, b"qux"))
try:
db.seq(b"foo1")
except OSError as e:
print(e.errno == uerrno.EINVAL)
print(e.errno == errno.EINVAL)
print(list(db.keys()))
print(list(db.values()))

View File

@@ -1,15 +1,15 @@
# Test that errno's propagate correctly through btree module.
try:
import btree, uio, uerrno
import btree, io, errno
uio.IOBase
io.IOBase
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class Device(uio.IOBase):
class Device(io.IOBase):
def __init__(self, read_ret=0, ioctl_ret=0):
self.read_ret = read_ret
self.ioctl_ret = ioctl_ret
@@ -25,18 +25,24 @@ class Device(uio.IOBase):
# Invalid pagesize; errno comes from btree library
try:
import btree, io, errno
db = btree.open(Device(), pagesize=511)
except OSError as er:
print("OSError", er.errno == uerrno.EINVAL)
print("OSError", er.errno == errno.EINVAL)
# Valid pagesize, device returns error on read; errno comes from Device.readinto
try:
import btree, io, errno
db = btree.open(Device(-1000), pagesize=512)
except OSError as er:
print(repr(er))
# Valid pagesize, device returns error on seek; errno comes from Device.ioctl
try:
import btree, io, errno
db = btree.open(Device(0, -1001), pagesize=512)
except OSError as er:
print(repr(er))

View File

@@ -1,7 +1,7 @@
# Test btree interaction with the garbage collector.
try:
import btree, uio, gc
import btree, io, gc
except ImportError:
print("SKIP")
raise SystemExit
@@ -9,7 +9,7 @@ except ImportError:
N = 80
# Create a BytesIO but don't keep a reference to it.
db = btree.open(uio.BytesIO(), pagesize=512)
db = btree.open(io.BytesIO(), pagesize=512)
# Overwrite lots of the Python stack to make sure no reference to the BytesIO remains.
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

View File

@@ -4,7 +4,7 @@ try:
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,5 +1,5 @@
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -4,7 +4,7 @@ try:
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -7,7 +7,7 @@ try:
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,6 +1,6 @@
# Inplace operations (input and output buffer is the same)
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,6 +1,6 @@
# Operations with pre-allocated output buffer
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -4,7 +4,7 @@ try:
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -4,7 +4,7 @@ try:
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
from cryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,11 +1,11 @@
try:
import framebuf, usys
import framebuf, sys
except ImportError:
print("SKIP")
raise SystemExit
# This test and its .exp file is based on a little-endian architecture.
if usys.byteorder != "little":
if sys.byteorder != "little":
print("SKIP")
raise SystemExit

View File

@@ -1,6 +1,6 @@
# Test blit between different color spaces
try:
import framebuf, usys
import framebuf, sys
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,13 +1,13 @@
# test subclassing framebuf.FrameBuffer
try:
import framebuf, usys
import framebuf, sys
except ImportError:
print("SKIP")
raise SystemExit
# This test and its .exp file is based on a little-endian architecture.
if usys.byteorder != "little":
if sys.byteorder != "little":
print("SKIP")
raise SystemExit

View File

@@ -1,12 +1,12 @@
try:
import uhashlib
import hashlib
except ImportError:
print("SKIP")
raise SystemExit
for algo_name in ("md5", "sha1", "sha256"):
algo = getattr(uhashlib, algo_name, None)
algo = getattr(hashlib, algo_name, None)
if not algo:
continue

View File

@@ -0,0 +1,18 @@
try:
import hashlib
except ImportError:
# This is neither uPy, nor cPy, so must be uPy with
# hashlib module disabled.
print("SKIP")
raise SystemExit
try:
hashlib.md5
except AttributeError:
# MD5 is only available on some ports
print("SKIP")
raise SystemExit
md5 = hashlib.md5(b"hello")
md5.update(b"world")
print(md5.digest())

View File

@@ -0,0 +1,18 @@
try:
import hashlib
except ImportError:
# This is neither uPy, nor cPy, so must be uPy with
# hashlib module disabled.
print("SKIP")
raise SystemExit
try:
hashlib.sha1
except AttributeError:
# SHA1 is only available on some ports
print("SKIP")
raise SystemExit
sha1 = hashlib.sha1(b"hello")
sha1.update(b"world")
print(sha1.digest())

View File

@@ -1,13 +1,10 @@
try:
import uhashlib as hashlib
import hashlib
except ImportError:
try:
import hashlib
except ImportError:
# This is neither uPy, nor cPy, so must be uPy with
# uhashlib module disabled.
print("SKIP")
raise SystemExit
# This is neither uPy, nor cPy, so must be uPy with
# hashlib module disabled.
print("SKIP")
raise SystemExit
h = hashlib.sha256()

View File

@@ -1,11 +1,8 @@
try:
import uheapq as heapq
except:
try:
import heapq
except ImportError:
print("SKIP")
raise SystemExit
import heapq
except ImportError:
print("SKIP")
raise SystemExit
try:
heapq.heappop([])

View File

@@ -1,13 +1,9 @@
try:
from uio import StringIO
import ujson as json
except:
try:
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
s = StringIO()
json.dump(False, s)

View File

@@ -1,14 +1,10 @@
# test ujson.dump in combination with uio.IOBase
# test json.dump in combination with io.IOBase
try:
import uio as io
import ujson as json
import io, json
except ImportError:
try:
import io, json
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
if not hasattr(io, "IOBase"):
print("SKIP")

View File

@@ -1,13 +1,9 @@
try:
from uio import StringIO
import ujson as json
except:
try:
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
for sep in [
None,

View File

@@ -1,11 +1,8 @@
try:
import ujson as json
import json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(json.dumps(False))
print(json.dumps(True))

View File

@@ -0,0 +1,9 @@
# test uPy json behaviour that's not valid in CPy
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(b"1234"))

View File

@@ -0,0 +1,8 @@
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(1.2))
print(json.dumps({1.5: "hi"}))

View File

@@ -0,0 +1,8 @@
try:
import json
from collections import OrderedDict
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(OrderedDict(((1, 2), (3, 4)))))

View File

@@ -1,11 +1,8 @@
try:
import ujson as json
import json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
for sep in [
None,

11
tests/extmod/json_load.py Normal file
View File

@@ -0,0 +1,11 @@
try:
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.load(StringIO("null")))
print(json.load(StringIO('"abc\\u0064e"')))
print(json.load(StringIO("[false, true, 1, -2]")))
print(json.load(StringIO('{"a":true}')))

View File

@@ -1,11 +1,8 @@
try:
import ujson as json
import json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
def my_print(o):

View File

@@ -1,13 +1,10 @@
# test loading from bytes and bytearray (introduced in Python 3.6)
try:
import ujson as json
import json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
print(json.loads(b"[1,2]"))
print(json.loads(bytearray(b"[null]")))

View File

@@ -1,11 +1,8 @@
try:
import ujson as json
import json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
def my_print(o):

View File

@@ -1,10 +1,8 @@
# test machine module
try:
try:
import umachine as machine
except ImportError:
import machine
import machine
machine.mem8
except:
print("SKIP")

View File

@@ -1,8 +1,6 @@
try:
try:
import umachine as machine
except ImportError:
import machine
import machine
machine.PinBase
except:
print("SKIP")

View File

@@ -1,8 +1,6 @@
try:
try:
import umachine as machine
except ImportError:
import machine
import machine
machine.PinBase
machine.time_pulse_us
except:

View File

@@ -1,10 +1,8 @@
# test machine.Signal class
try:
try:
import umachine as machine
except ImportError:
import machine
import machine
machine.PinBase
machine.Signal
except:

View File

@@ -1,7 +1,7 @@
# test machine.Timer
try:
import utime, umachine as machine
import time, machine as machine
machine.Timer
except:
@@ -29,10 +29,10 @@ t.deinit()
# create one-shot timer with callback and wait for it to print (should be just once)
t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot"))
utime.sleep_ms(5)
time.sleep_ms(5)
t.deinit()
# create periodic timer with callback and wait for it to print
t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic"))
utime.sleep_ms(14)
time.sleep_ms(14)
t.deinit()

View File

@@ -1,11 +1,8 @@
try:
import urandom as random
import random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# check getrandbits returns a value within the bit range
for b in (1, 2, 3, 4, 16, 32):

View File

@@ -1,11 +1,8 @@
try:
import urandom as random
import random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
random.randint

View File

@@ -1,11 +1,8 @@
try:
import urandom as random
import random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
random.randint

View File

@@ -1,13 +1,10 @@
# test urandom.seed() without any arguments
# test random.seed() without any arguments
try:
import urandom as random
import random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
random.seed()

View File

@@ -1,11 +1,8 @@
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
r = re.compile(".+")
m = r.match("abc")

View File

@@ -1,10 +1,10 @@
# test printing debugging info when compiling
try:
import ure
import re
ure.DEBUG
re.DEBUG
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
ure.compile("^a|b[0-9]\w$", ure.DEBUG)
re.compile("^a|b[0-9]\w$", re.DEBUG)

View File

@@ -1,13 +1,10 @@
# test errors in regex
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
def test_re(r):

View File

@@ -1,13 +1,10 @@
# test groups, and nested groups
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
def print_groups(match):

View File

@@ -1,13 +1,10 @@
# test match.groups()
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
m = re.match(".", "a")

View File

@@ -1,7 +1,7 @@
# Test overflow in ure.compile output code.
# Test overflow in re.compile output code.
try:
import ure as re
import re
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,13 +1,10 @@
# test named char classes
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
def print_groups(match):

View File

@@ -1,13 +1,10 @@
# test match.span(), and nested spans
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
m = re.match(".", "a")

View File

@@ -1,11 +1,8 @@
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
r = re.compile(" ")
s = r.split("a b c foobar")

View File

@@ -5,7 +5,7 @@
# splitting as soon as an empty match is found.
try:
import ure as re
import re
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,5 +1,5 @@
try:
import ure as re
import re
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -0,0 +1,10 @@
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
re.match("(a*)*", "aaa")
except RuntimeError:
print("RuntimeError")

View File

@@ -1,11 +1,8 @@
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
re.sub

View File

@@ -1,13 +1,10 @@
# test re.sub with unmatched groups, behaviour changed in CPython 3.5
try:
import ure as re
import re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
try:
re.sub

View File

@@ -1,13 +1,10 @@
try:
import usocket as socket, uselect as select, uerrno as errno
except ImportError:
try:
import socket, select, errno
import socket, select, errno
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
poller = select.poll()

View File

@@ -1,15 +1,12 @@
# test select.poll on UDP sockets
try:
import usocket as socket, uselect as select
except ImportError:
try:
import socket, select
import socket, select
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

View File

@@ -1,13 +1,10 @@
# Test basic, stand-alone TCP socket functionality
try:
import usocket as socket, uerrno as errno
import socket, errno
except ImportError:
try:
import socket, errno
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
# recv() on a fresh socket should raise ENOTCONN
s = socket.socket()

View File

@@ -1,13 +1,10 @@
# test non-blocking UDP sockets
try:
import usocket as socket, uerrno as errno
import socket, errno
except ImportError:
try:
import socket, errno
except ImportError:
print("SKIP")
raise SystemExit
print("SKIP")
raise SystemExit
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

View File

@@ -1,8 +1,8 @@
# very basic test of ssl module, just to test the methods exist
try:
import uio as io
import ussl as ssl
import io
import ssl
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,8 @@
# Test ussl with key/cert passed in
# Test ssl with key/cert passed in
try:
import uio as io
import ussl as ssl
import io
import ssl
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,8 +1,8 @@
try:
import uselect
import ussl
import select
import ssl
import io
import ubinascii as binascii
import binascii
except ImportError:
print("SKIP")
raise SystemExit
@@ -121,9 +121,9 @@ client_io, server_io = _Pipe.new_pair()
client_io.block_reads = True
client_io.block_writes = True
client_sock = ussl.wrap_socket(client_io, do_handshake=False)
client_sock = ssl.wrap_socket(client_io, do_handshake=False)
server_sock = ussl.wrap_socket(server_io, key=key, cert=cert, server_side=True, do_handshake=False)
server_sock = ssl.wrap_socket(server_io, key=key, cert=cert, server_side=True, do_handshake=False)
# Do a test read, at this point the TLS handshake wants to write,
# so it returns None:
@@ -175,7 +175,7 @@ assert server_sock.read(3) == b"bar"
# Polling on a closed socket errors out:
client_io, _ = _Pipe.new_pair()
client_sock = ussl.wrap_socket(client_io, do_handshake=False)
client_sock = ssl.wrap_socket(client_io, do_handshake=False)
client_sock.close()
assert_poll(
client_sock, client_io, _MP_STREAM_POLL_RD, None, _MP_STREAM_POLL_NVAL
@@ -184,7 +184,7 @@ assert_poll(
# Errors propagates to poll:
client_io, server_io = _Pipe.new_pair()
client_sock = ussl.wrap_socket(client_io, do_handshake=False)
client_sock = ssl.wrap_socket(client_io, do_handshake=False)
# The server returns garbage:
server_io.write(b"fooba") # Needs to be exactly 5 bytes

View File

@@ -1,5 +1,5 @@
try:
from utime import ticks_diff, ticks_add
from time import ticks_diff, ticks_add
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,5 +1,5 @@
try:
from utime import ticks_diff, ticks_add
from time import ticks_diff, ticks_add
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,23 +1,23 @@
try:
import utime
import time
utime.sleep_ms, utime.sleep_us, utime.ticks_diff, utime.ticks_ms, utime.ticks_us, utime.ticks_cpu
time.sleep_ms, time.sleep_us, time.ticks_diff, time.ticks_ms, time.ticks_us, time.ticks_cpu
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
utime.sleep_ms(1)
utime.sleep_us(1)
time.sleep_ms(1)
time.sleep_us(1)
t0 = utime.ticks_ms()
t1 = utime.ticks_ms()
print(0 <= utime.ticks_diff(t1, t0) <= 1)
t0 = time.ticks_ms()
t1 = time.ticks_ms()
print(0 <= time.ticks_diff(t1, t0) <= 1)
t0 = utime.ticks_us()
t1 = utime.ticks_us()
print(0 <= utime.ticks_diff(t1, t0) <= 500)
t0 = time.ticks_us()
t1 = time.ticks_us()
print(0 <= time.ticks_diff(t1, t0) <= 500)
# ticks_cpu may not be implemented, at least make sure it doesn't decrease
t0 = utime.ticks_cpu()
t1 = utime.ticks_cpu()
print(utime.ticks_diff(t1, t0) >= 0)
t0 = time.ticks_cpu()
t1 = time.ticks_cpu()
print(time.ticks_diff(t1, t0) >= 0)

View File

@@ -1,18 +1,18 @@
# test utime resolutions
# test time resolutions
try:
import utime
import time
except ImportError:
print("SKIP")
raise SystemExit
def gmtime_time():
return utime.gmtime(utime.time())
return time.gmtime(time.time())
def localtime_time():
return utime.localtime(utime.time())
return time.localtime(time.time())
def test():
@@ -32,12 +32,12 @@ def test():
# call time functions
results_map = {}
end_time = utime.ticks_ms() + TEST_TIME
while utime.ticks_diff(end_time, utime.ticks_ms()) > 0:
utime.sleep_ms(100)
end_time = time.ticks_ms() + TEST_TIME
while time.ticks_diff(end_time, time.ticks_ms()) > 0:
time.sleep_ms(100)
for func_name, _ in EXPECTED_MAP:
try:
time_func = getattr(utime, func_name, None) or globals()[func_name]
time_func = getattr(time, func_name, None) or globals()[func_name]
now = time_func() # may raise AttributeError
except (KeyError, AttributeError):
continue

View File

@@ -1,18 +1,18 @@
# test utime.time_ns()
# test time.time_ns()
try:
import utime
import time
utime.sleep_us
utime.time_ns
time.sleep_us
time.time_ns
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
t0 = utime.time_ns()
utime.sleep_us(5000)
t1 = utime.time_ns()
t0 = time.time_ns()
time.sleep_us(5000)
t1 = time.time_ns()
# Check that time_ns increases.
print(t0 < t1)

View File

@@ -1,8 +1,8 @@
# Test for utimeq module which implements task queue with support for
# wraparound time (utime.ticks_ms() style).
# Test for timeq module which implements task queue with support for
# wraparound time (time.ticks_ms() style).
try:
from utime import ticks_add, ticks_diff
from utimeq import utimeq
from time import ticks_add, ticks_diff
from timeq import timeq
except ImportError:
print("SKIP")
raise SystemExit
@@ -24,7 +24,7 @@ else:
# Try not to crash on invalid data
h = utimeq(10)
h = timeq(10)
try:
h.push(1)
assert False
@@ -45,7 +45,7 @@ except TypeError:
pass
# pushing on full queue
h = utimeq(1)
h = timeq(1)
h.push(1, 0, 0)
try:
h.push(2, 0, 0)
@@ -68,7 +68,7 @@ assert h.peektime() == 1
# peektime with empty queue
try:
utimeq(1).peektime()
timeq(1).peektime()
assert False
except IndexError:
pass
@@ -92,7 +92,7 @@ def add(h, v):
dprint("-----")
h = utimeq(10)
h = timeq(10)
add(h, 0)
add(h, MAX)
add(h, MAX - 1)
@@ -107,7 +107,7 @@ for i in range(len(l) - 1):
def edge_case(edge, offset):
h = utimeq(10)
h = timeq(10)
add(h, ticks_add(0, offset))
add(h, ticks_add(edge, offset))
dprint(h)

View File

@@ -1,10 +1,10 @@
try:
from utimeq import utimeq
from timeq import timeq
except ImportError:
print("SKIP")
raise SystemExit
h = utimeq(10)
h = timeq(10)
# Check that for 2 same-key items, the queue is stable (pops items
# in the same order they were pushed). Unfortunately, this no longer

View File

@@ -7,15 +7,12 @@ except ImportError:
print("SKIP")
raise SystemExit
import time
try:
import utime
ticks = utime.ticks_ms
ticks_diff = utime.ticks_diff
except:
import time
if hasattr(time, "ticks_ms"):
ticks = time.ticks_ms
ticks_diff = time.ticks_diff
else:
ticks = lambda: int(time.time() * 1000)
ticks_diff = lambda t1, t0: t1 - t0

View File

@@ -3,7 +3,7 @@
# - wait_for_ms
try:
import utime, uasyncio
import time, uasyncio
except ImportError:
print("SKIP")
raise SystemExit
@@ -18,13 +18,13 @@ async def task(id, t):
async def main():
# Simple sleep_ms
t0 = utime.ticks_ms()
t0 = time.ticks_ms()
await uasyncio.sleep_ms(1)
print(utime.ticks_diff(utime.ticks_ms(), t0) < 100)
print(time.ticks_diff(time.ticks_ms(), t0) < 100)
try:
# Sleep 1ms beyond maximum allowed sleep value
await uasyncio.sleep_ms(utime.ticks_add(0, -1) // 2 + 1)
await uasyncio.sleep_ms(time.ticks_add(0, -1) // 2 + 1)
except OverflowError:
print("OverflowError")

Some files were not shown because too many files have changed in this diff Show More