code stringlengths 1 1.05M | repo_name stringlengths 6 83 | path stringlengths 3 242 | language stringclasses 222
values | license stringclasses 20
values | size int64 1 1.05M |
|---|---|---|---|---|---|
# This test is exactly like uctypes_le.py, but uses native structure layout.
# Codepaths for packed vs native structures are different. This test only works
# on little-endian machine (no matter if 32 or 64 bit).
import usys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if usys.by... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_native_le.py | Python | apache-2.0 | 2,540 |
# test printing of uctypes objects
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
# we use an address of "0" because we just want to print something deterministic
# and don't actually need to set/get any values in the struct
desc = {"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 1)}
S ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_print.py | Python | apache-2.0 | 619 |
import usys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if usys.byteorder != "little":
print("SKIP")
raise SystemExit
desc = {
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
"ptr16": (uctypes.PTR | 0, uctypes.UINT16),
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_ptr_le.py | Python | apache-2.0 | 836 |
import usys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if usys.byteorder != "little":
print("SKIP")
raise SystemExit
desc = {
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
"ptr16": (uctypes.PTR | 0, uctypes.UINT16),
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_ptr_native_le.py | Python | apache-2.0 | 776 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
# arr is array at offset 0, of UINT8 elements, array size is 2
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2": (uctypes.ARRAY | 0, 2,... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_sizeof.py | Python | apache-2.0 | 1,286 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
print(uctypes.sizeof({"f": uctypes.FLOAT32}))
print(uctypes.sizeof({"f": uctypes.FLOAT64}))
print(uctypes.sizeof({"f": (uctypes.ARRAY | 0, uctypes.FLOAT32 | 2)}))
print(uctypes.sizeof({"f": (uctypes.ARRAY | 0, uctypes.FLOAT64 | 2)}))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_sizeof_float.py | Python | apache-2.0 | 318 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"f1": 0 | uctypes.UINT32,
"f2": 4 | uctypes.UINT8,
}
# uctypes.NATIVE is default
print(uctypes.sizeof(desc) == uctypes.sizeof(desc, uctypes.NATIVE))
# Here we assume that that we run on a platform with convential ABI... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_sizeof_layout.py | Python | apache-2.0 | 835 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
S1 = {}
assert uctypes.sizeof(S1) == 0
S2 = {"a": uctypes.UINT8 | 0}
assert uctypes.sizeof(S2) == 1
S3 = {
"a": uctypes.UINT8 | 0,
"b": uctypes.UINT8 | 1,
}
assert uctypes.sizeof(S3) == 2
S4 = {
"a": uctypes.UINT8 | 0,
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_sizeof_native.py | Python | apache-2.0 | 1,081 |
try:
from ucollections import OrderedDict
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = OrderedDict(
{
# arr is array at offset 0, of UINT8 elements, array size is 2
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
# arr2 is array at offset 0, size 2... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_sizeof_od.py | Python | apache-2.0 | 1,402 |
try:
import uhashlib
except ImportError:
print("SKIP")
raise SystemExit
for algo_name in ("md5", "sha1", "sha256"):
algo = getattr(uhashlib, algo_name, None)
if not algo:
continue
# Running .digest() several times in row is not supported.
h = algo(b"123")
h.digest()
try:
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uhashlib_final.py | Python | apache-2.0 | 855 |
try:
import uhashlib as 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
try:
hashlib.md5
except AttributeError:
# MD5 is only av... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uhashlib_md5.py | Python | apache-2.0 | 451 |
try:
import uhashlib as 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
try:
hashlib.sha1
except AttributeError:
# SHA1 is only ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uhashlib_sha1.py | Python | apache-2.0 | 457 |
try:
import uhashlib as 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
h = hashlib.sha256()
print(h.digest())
h = hashlib.sha256()
h.... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uhashlib_sha256.py | Python | apache-2.0 | 824 |
try:
import uheapq as heapq
except:
try:
import heapq
except ImportError:
print("SKIP")
raise SystemExit
try:
heapq.heappop([])
except IndexError:
print("IndexError")
try:
heapq.heappush((), 1)
except TypeError:
print("TypeError")
def pop_and_print(h):
l = []
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uheapq1.py | Python | apache-2.0 | 645 |
try:
from uio import StringIO
import ujson as json
except:
try:
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
s = StringIO()
json.dump(False, s)
print(s.getvalue())
s = StringIO()
json.dump({"a": (2, [3, None])}, s)
print(s.getva... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dump.py | Python | apache-2.0 | 646 |
# test ujson.dump in combination with uio.IOBase
try:
import uio as io
import ujson as json
except ImportError:
try:
import io, json
except ImportError:
print("SKIP")
raise SystemExit
if not hasattr(io, "IOBase"):
print("SKIP")
raise SystemExit
# a user stream that on... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dump_iobase.py | Python | apache-2.0 | 688 |
try:
from uio import StringIO
import ujson as json
except:
try:
from io import StringIO
import json
except ImportError:
print("SKIP")
raise SystemExit
for sep in [
None,
(", ", ": "),
(",", ": "),
(",", ":"),
[", ", ": "],
[",", ": "],
[",", "... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dump_separators.py | Python | apache-2.0 | 1,454 |
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(False))
print(json.dumps(True))
print(json.dumps(None))
print(json.dumps(1))
print(json.dumps("abc"))
print(json.dumps("\x00\x01\x7e"))
print(json.dumps... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dumps.py | Python | apache-2.0 | 781 |
# test uPy ujson behaviour that's not valid in CPy
try:
import ujson
except ImportError:
print("SKIP")
raise SystemExit
print(ujson.dumps(b"1234"))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dumps_extra.py | Python | apache-2.0 | 162 |
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(1.2))
print(json.dumps({1.5: "hi"}))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dumps_float.py | Python | apache-2.0 | 205 |
try:
import ujson as json
from ucollections import OrderedDict
except ImportError:
try:
import json
from collections import OrderedDict
except ImportError:
print("SKIP")
raise SystemExit
print(json.dumps(OrderedDict(((1, 2), (3, 4)))))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dumps_ordereddict.py | Python | apache-2.0 | 285 |
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
for sep in [
None,
(", ", ": "),
(",", ": "),
(",", ":"),
[", ", ": "],
[",", ": "],
[",", ":"],
]:
print(json.dumps(False, separators=se... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_dumps_separators.py | Python | apache-2.0 | 1,849 |
try:
from uio import StringIO
import ujson as json
except:
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... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_load.py | Python | apache-2.0 | 371 |
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
def my_print(o):
if isinstance(o, dict):
print("sorted dict", sorted(o.items()))
else:
print(o)
my_print(json.loads("null"))
my_print(json.loa... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_loads.py | Python | apache-2.0 | 1,770 |
# test loading from bytes and bytearray (introduced in Python 3.6)
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
print(json.loads(b"[1,2]"))
print(json.loads(bytearray(b"[null]")))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_loads_bytes.py | Python | apache-2.0 | 287 |
try:
import ujson as json
except ImportError:
try:
import json
except ImportError:
print("SKIP")
raise SystemExit
def my_print(o):
print("%.3f" % o)
my_print(json.loads("1.2"))
my_print(json.loads("1e2"))
my_print(json.loads("-2.3"))
my_print(json.loads("-2e3"))
my_print(json... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ujson_loads_float.py | Python | apache-2.0 | 367 |
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
# check getrandbits returns a value within the bit range
for b in (1, 2, 3, 4, 16, 32):
for i in range(50):
assert random.getrandbits(b) < (1 << b)
# ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/urandom_basic.py | Python | apache-2.0 | 722 |
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
try:
random.randint
except AttributeError:
print("SKIP")
raise SystemExit
print("randrange")
for i in range(50):
assert 0 <= random.randrange(4) <... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/urandom_extra.py | Python | apache-2.0 | 1,308 |
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
try:
random.randint
except AttributeError:
print("SKIP")
raise SystemExit
print("random")
for i in range(50):
assert 0 <= random.random() < 1
pri... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/urandom_extra_float.py | Python | apache-2.0 | 482 |
# test urandom.seed() without any arguments
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
try:
random.seed()
except ValueError:
# no default seed on this platform
print("SKIP")
raise SystemExi... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/urandom_seed_default.py | Python | apache-2.0 | 579 |
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
r = re.compile(".+")
m = r.match("abc")
print(m.group(0))
try:
m.group(1)
except IndexError:
print("IndexError")
# conversion of re and match to string
str(r)
str(m)
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure1.py | Python | apache-2.0 | 2,723 |
# test printing debugging info when compiling
try:
import ure
ure.DEBUG
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
ure.compile("^a|b[0-9]\w$", ure.DEBUG)
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_debug.py | Python | apache-2.0 | 198 |
# test errors in regex
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
def test_re(r):
try:
re.compile(r)
print("OK")
except: # uPy and CPy use different errors, so just ignore the type
pr... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_error.py | Python | apache-2.0 | 453 |
# test groups, and nested groups
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
def print_groups(match):
print("----")
try:
i = 0
while True:
print(match.group(i))
i += 1
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_group.py | Python | apache-2.0 | 661 |
# test match.groups()
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
m = re.match(".", "a")
m.groups
except AttributeError:
print("SKIP")
raise SystemExit
m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_groups.py | Python | apache-2.0 | 652 |
# Test overflow in ure.compile output code.
try:
import ure as re
except ImportError:
print("SKIP")
raise SystemExit
def test_re(r):
try:
re.compile(r)
except:
print("Error")
# too many chars in []
test_re("[" + "a" * 256 + "]")
# too many groups
test_re("(a)" * 256)
# jump to... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_limit.py | Python | apache-2.0 | 550 |
# test named char classes
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
def print_groups(match):
print("----")
try:
i = 0
while True:
print(m.group(i))
i += 1
except I... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_namedclass.py | Python | apache-2.0 | 623 |
# test match.span(), and nested spans
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
m = re.match(".", "a")
m.span
except AttributeError:
print("SKIP")
raise SystemExit
def print_spans(match):
p... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_span.py | Python | apache-2.0 | 794 |
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
r = re.compile(" ")
s = r.split("a b c foobar")
print(s)
r = re.compile(" +")
s = r.split("a b c foobar")
print(s)
r = re.compile(" +")
s = r.split("a b c foobar",... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_split.py | Python | apache-2.0 | 527 |
# test splitting with pattern matches that can be empty
#
# CPython 3.5 issues a FutureWarning for these tests because their
# behaviour will change in a future version. MicroPython just stops
# splitting as soon as an empty match is found.
try:
import ure as re
except ImportError:
print("SKIP")
raise Sys... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_split_empty.py | Python | apache-2.0 | 493 |
try:
import ure as re
except ImportError:
print("SKIP")
raise SystemExit
r = re.compile("( )")
try:
s = r.split("a b c foobar")
except NotImplementedError:
print("NotImplementedError")
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_split_notimpl.py | Python | apache-2.0 | 206 |
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
re.match("(a*)*", "aaa")
except RuntimeError:
print("RuntimeError")
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_stack_overflow.py | Python | apache-2.0 | 226 |
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
re.sub
except AttributeError:
print("SKIP")
raise SystemExit
def multiply(m):
return str(int(m.group(0)) * 2)
print(re.sub("\d+", multiply, "10 20 30 ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_sub.py | Python | apache-2.0 | 1,627 |
# test re.sub with unmatched groups, behaviour changed in CPython 3.5
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
re.sub
except AttributeError:
print("SKIP")
raise SystemExit
# first group matches, se... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ure_sub_unmatched.py | Python | apache-2.0 | 419 |
try:
import usocket as socket, uselect as select, uerrno as errno
except ImportError:
try:
import socket, select, errno
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
poll... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uselect_poll_basic.py | Python | apache-2.0 | 1,015 |
# test select.poll on UDP sockets
try:
import usocket as socket, uselect as select
except ImportError:
try:
import socket, select
except ImportError:
print("SKIP")
raise SystemExit
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0]... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uselect_poll_udp.py | Python | apache-2.0 | 741 |
# Test basic, stand-alone TCP socket functionality
try:
import usocket as socket, uerrno as errno
except ImportError:
try:
import socket, errno
except ImportError:
print("SKIP")
raise SystemExit
# recv() on a fresh socket should raise ENOTCONN
s = socket.socket()
try:
s.recv(1)... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/usocket_tcp_basic.py | Python | apache-2.0 | 394 |
# test non-blocking UDP sockets
try:
import usocket as socket, uerrno as errno
except ImportError:
try:
import socket, errno
except ImportError:
print("SKIP")
raise SystemExit
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1])... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/usocket_udp_nonblock.py | Python | apache-2.0 | 426 |
# very basic test of ssl module, just to test the methods exist
try:
import uio as io
import ussl as ssl
except ImportError:
print("SKIP")
raise SystemExit
# create in client mode
try:
ss = ssl.wrap_socket(io.BytesIO(), server_hostname="test.example.com")
except OSError as er:
print("wrap_sock... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ussl_basic.py | Python | apache-2.0 | 1,277 |
# Test ussl with key/cert passed in
try:
import uio as io
import ussl as ssl
except ImportError:
print("SKIP")
raise SystemExit
key = b"0\x82\x019\x02\x01\x00\x02A\x00\xf9\xe0}\xbd\xd7\x9cI\x18\x06\xc3\xcb\xb5\xec@r\xfbD\x18\x80\xaaWoZ{\xcc\xa3\xeb!\"\x0fY\x9e]-\xee\xe4\t!BY\x9f{7\xf3\xf2\x8f}}\r|.\xa... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ussl_keycert.py | Python | apache-2.0 | 1,409 |
# test utime resolutions
try:
import utime
except ImportError:
print("SKIP")
raise SystemExit
def gmtime_time():
return utime.gmtime(utime.time())
def localtime_time():
return utime.localtime(utime.time())
def test():
TEST_TIME = 2500
EXPECTED_MAP = (
# (function name, min. nu... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/utime_res.py | Python | apache-2.0 | 1,756 |
# test utime.time_ns()
try:
import utime
utime.sleep_us
utime.time_ns
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
t0 = utime.time_ns()
utime.sleep_us(5000)
t1 = utime.time_ns()
# Check that time_ns increases.
print(t0 < t1)
# Check that time_ns counts correctly, but be... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/utime_time_ns.py | Python | apache-2.0 | 447 |
# Test for utimeq module which implements task queue with support for
# wraparound time (utime.ticks_ms() style).
try:
from utime import ticks_add, ticks_diff
from utimeq import utimeq
except ImportError:
print("SKIP")
raise SystemExit
DEBUG = 0
MAX = ticks_add(0, -1)
MODULO_HALF = MAX // 2 + 1
if DE... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/utimeq1.py | Python | apache-2.0 | 2,896 |
try:
from utimeq import utimeq
except ImportError:
print("SKIP")
raise SystemExit
h = utimeq(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
# holds for more same-key values, as the underlying heap structure
# is n... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/utimeq_stable.py | Python | apache-2.0 | 482 |
try:
import uzlib as zlib
import uio as io
except ImportError:
print("SKIP")
raise SystemExit
# Raw DEFLATE bitstream
buf = io.BytesIO(b"\xcbH\xcd\xc9\xc9\x07\x00")
inp = zlib.DecompIO(buf, -8)
print(buf.seek(0, 1))
print(inp.read(1))
print(buf.seek(0, 1))
print(inp.read(2))
print(inp.read())
print(bu... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uzlib_decompio.py | Python | apache-2.0 | 691 |
try:
import uzlib as zlib
import uio as io
except ImportError:
print("SKIP")
raise SystemExit
# gzip bitstream
buf = io.BytesIO(
b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
)
inp = zlib.DecompIO(buf, 16 + 8)
print(buf.seek(0, 1))
print(in... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uzlib_decompio_gz.py | Python | apache-2.0 | 1,561 |
try:
import zlib
except ImportError:
try:
import uzlib as zlib
except ImportError:
print("SKIP")
raise SystemExit
PATTERNS = [
# Packed results produced by CPy's zlib.compress()
(b"0", b"x\x9c3\x00\x00\x001\x001"),
(b"a", b"x\x9cK\x04\x00\x00b\x00b"),
(b"0" * 100, b"... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uzlib_decompress.py | Python | apache-2.0 | 1,985 |
# test VFS functionality without any particular filesystem type
try:
import uos
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class Filesystem:
def __init__(self, id, fail=0):
self.id = id
self.fail = fail
def mount(self, readonly, mkfs):
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_basic.py | Python | apache-2.0 | 4,068 |
# Test for behaviour of combined standard and extended block device
try:
import uos
uos.VfsFat
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks *... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_blockdev.py | Python | apache-2.0 | 1,595 |
try:
import uerrno
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMFS:
SEC_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.SEC_SIZE)
def readblock... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_fileio1.py | Python | apache-2.0 | 2,292 |
try:
import uerrno
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMFS:
SEC_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.SEC_SIZE)
def readblock... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_fileio2.py | Python | apache-2.0 | 2,625 |
# Test VfsFat class and its finaliser
try:
import uerrno, uos
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
def __init__(self, blocks, sec_size=512):
self.sec_size = sec_size
self.data = bytearray(blocks * self.sec_size)
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_finaliser.py | Python | apache-2.0 | 2,174 |
try:
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMFS:
SEC_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_more.py | Python | apache-2.0 | 2,584 |
# Test for VfsFat using a RAM device, mtime feature
try:
import utime, uos
utime.time
utime.sleep
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(bl... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_mtime.py | Python | apache-2.0 | 1,932 |
try:
import uerrno
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMFS_OLD:
SEC_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.SEC_SIZE)
def readb... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_oldproto.py | Python | apache-2.0 | 1,150 |
try:
import uerrno
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMFS:
SEC_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.SEC_SIZE)
def readblock... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_ramdisk.py | Python | apache-2.0 | 2,172 |
# test making a FAT filesystem on a very large block device
try:
import uos
except ImportError:
print("SKIP")
raise SystemExit
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
class RAMBDevSparse:
SEC_SIZE = 512
def __init__(self, blocks):
self.blocks =... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_fat_ramdisklarge.py | Python | apache-2.0 | 1,664 |
# Test for VfsLittle using a RAM device
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs.py | Python | apache-2.0 | 3,777 |
# Test for VfsLittle using a RAM device, testing error handling from corrupt block device
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.d... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs_corrupt.py | Python | apache-2.0 | 2,568 |
# Test for VfsLittle using a RAM device, testing error handling
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.data = bytearray(blocks * s... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs_error.py | Python | apache-2.0 | 2,689 |
# Test for VfsLittle using a RAM device, file IO
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.data = bytearray(blocks * self.ERASE_BLOCK... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs_file.py | Python | apache-2.0 | 2,626 |
# Test for VfsLittle using a RAM device, with mount/umount
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.data = bytearray(blocks * self.E... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs_mount.py | Python | apache-2.0 | 2,447 |
# Test for VfsLfs using a RAM device, mtime feature
try:
import utime, uos
utime.time
utime.sleep
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.data = bytearray(... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs_mtime.py | Python | apache-2.0 | 2,861 |
# Test for VfsLfs using a RAM device, when the first superblock does not exist
try:
import uos
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
def __init__(self, block_size, data):
self.block_size = block_size
self.data = dat... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_lfs_superblock.py | Python | apache-2.0 | 2,238 |
# Test for VfsPosix
try:
import uos
uos.VfsPosix
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# We need a directory for testing that doesn't already exist.
# Skip the test if it does exist.
temp_dir = "micropy_test_dir"
try:
uos.stat(temp_dir)
print("SKIP")
raise S... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_posix.py | Python | apache-2.0 | 1,649 |
# test VFS functionality with a user-defined filesystem
# also tests parts of uio.IOBase implementation
import usys
try:
import uio
uio.IOBase
import uos
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class UserFile(uio.IOBase):
def __init__(self, mode, ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/vfs_userfs.py | Python | apache-2.0 | 1,821 |
try:
import uio
import uerrno
import uwebsocket
except ImportError:
print("SKIP")
raise SystemExit
# put raw data in the stream and do a websocket read
def ws_read(msg, sz):
ws = uwebsocket.websocket(uio.BytesIO(msg))
return ws.read(sz)
# do a websocket write and then return the raw data ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/websocket_basic.py | Python | apache-2.0 | 1,450 |
# check if async/await keywords are supported
async def foo():
await 1
print("async")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/async_check.py | Python | apache-2.0 | 92 |
try:
bytearray
print("bytearray")
except NameError:
print("no")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/bytearray.py | Python | apache-2.0 | 76 |
try:
import usys as sys
except ImportError:
import sys
print(sys.byteorder)
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/byteorder.py | Python | apache-2.0 | 85 |
try:
complex
print("complex")
except NameError:
print("no")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/complex.py | Python | apache-2.0 | 72 |
x = const(1)
print(x)
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/const.py | Python | apache-2.0 | 22 |
try:
extra_coverage
print("coverage")
except NameError:
print("no")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/coverage.py | Python | apache-2.0 | 80 |
# detect how many bits of precision the floating point implementation has
try:
float
except NameError:
print(0)
else:
if float("1.0000001") == float("1.0"):
print(30)
elif float("1e300") == float("inf"):
print(32)
else:
print(64)
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/float.py | Python | apache-2.0 | 275 |
# check whether f-strings (PEP-498) are supported
a = 1
print(f"a={a}")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/fstring.py | Python | apache-2.0 | 72 |
# Check whether arbitrary-precision integers (MPZ) are supported
print(1000000000000000000000000000000000000000000000)
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/int_big.py | Python | apache-2.0 | 119 |
# this test for the availability of native emitter
@micropython.native
def f():
pass
f()
print("native")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/native_check.py | Python | apache-2.0 | 111 |
# Check for emacs keys in REPL
t = +11
t == 2
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/repl_emacs_check.py | Python | apache-2.0 | 48 |
# just check if ctrl+w is supported, because it makes sure that
# both MICROPY_REPL_EMACS_WORDS_MOVE and MICROPY_REPL_EXTRA_WORDS_MOVE are enabled.
t = 1231
t == 1
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/repl_words_move_check.py | Python | apache-2.0 | 165 |
class Foo:
def __radd__(self, other):
pass
try:
5 + Foo()
except TypeError:
print("TypeError")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/reverse_ops.py | Python | apache-2.0 | 117 |
# check if set literal syntax is supported
print({1})
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/set_check.py | Python | apache-2.0 | 54 |
try:
slice
print("slice")
except NameError:
print("no")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/slice.py | Python | apache-2.0 | 68 |
try:
import uio
print("uio")
except ImportError:
print("no")
| YifuLiu/AliOS-Things | components/py_engine/tests/feature_check/uio_module.py | Python | apache-2.0 | 74 |
# test construction of array from array with float type
try:
from uarray import array
except ImportError:
try:
from array import array
except ImportError:
print("SKIP")
raise SystemExit
print(array("f", array("h", [1, 2])))
print(array("d", array("f", [1, 2])))
| YifuLiu/AliOS-Things | components/py_engine/tests/float/array_construct.py | Python | apache-2.0 | 300 |
# test builtin abs function with float args
for val in (
"1.0",
"-1.0",
"0.0",
"-0.0",
"nan",
"-nan",
"inf",
"-inf",
):
print(val, abs(float(val)))
| YifuLiu/AliOS-Things | components/py_engine/tests/float/builtin_float_abs.py | Python | apache-2.0 | 185 |
# test builtin hash function with float args
# these should hash to an integer with a specific value
for val in (
"0.0",
"-0.0",
"1.0",
"2.0",
"-12.0",
"12345.0",
):
print(val, hash(float(val)))
# just check that these values are hashable
for val in (
"0.1",
"-0.1",
"10.3",
... | YifuLiu/AliOS-Things | components/py_engine/tests/float/builtin_float_hash.py | Python | apache-2.0 | 418 |
# test builtin min and max functions with float args
try:
min
max
except:
print("SKIP")
raise SystemExit
print(min(0, 1.0))
print(min(1.0, 0))
print(min(0, -1.0))
print(min(-1.0, 0))
print(max(0, 1.0))
print(max(1.0, 0))
print(max(0, -1.0))
print(max(-1.0, 0))
print(min(1.5, -1.5))
print(min(-1.5, 1.... | YifuLiu/AliOS-Things | components/py_engine/tests/float/builtin_float_minmax.py | Python | apache-2.0 | 585 |
# test builtin pow function with float args
print(pow(0.0, 0.0))
print(pow(0, 1.0))
print(pow(1.0, 1))
print(pow(2.0, 3.0))
print(pow(2.0, -4.0))
print(pow(0.0, float("inf")))
print(pow(0.0, float("-inf")))
print(pow(0.0, float("nan")))
| YifuLiu/AliOS-Things | components/py_engine/tests/float/builtin_float_pow.py | Python | apache-2.0 | 239 |
# test round() with floats
# check basic cases
tests = [
[0.0],
[1.0],
[0.1],
[-0.1],
[123.4],
[123.6],
[-123.4],
[-123.6],
[1.234567, 5],
[1.23456, 1],
[1.23456, 0],
[1234.56, -2],
]
for t in tests:
print(round(*t))
# check .5 cases
for i in range(11):
print(ro... | YifuLiu/AliOS-Things | components/py_engine/tests/float/builtin_float_round.py | Python | apache-2.0 | 563 |
# test round() with floats that return large integers
for x in (-1e25, 1e25):
print("%.3g" % round(x))
| YifuLiu/AliOS-Things | components/py_engine/tests/float/builtin_float_round_intbig.py | Python | apache-2.0 | 108 |