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 |
|---|---|---|---|---|---|
"""
categories: Syntax,Operators
description: MicroPython allows using := to assign to the variable of a comprehension, CPython raises a SyntaxError.
cause: MicroPython is optimised for code size and doesn't check this case.
workaround: Do not rely on this behaviour if writing CPython compatible code.
"""
print([i := -... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/syntax_assign_expr.py | Python | apache-2.0 | 342 |
"""
categories: Syntax,Spaces
description: uPy requires spaces between literal numbers and keywords, CPy doesn't
cause: Unknown
workaround: Unknown
"""
try:
print(eval("1and 0"))
except SyntaxError:
print("Should have worked")
try:
print(eval("1or 0"))
except SyntaxError:
print("Should have worked")
try... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/syntax_spaces.py | Python | apache-2.0 | 405 |
"""
categories: Syntax,Unicode
description: Unicode name escapes are not implemented
cause: Unknown
workaround: Unknown
"""
print("\N{LATIN SMALL LETTER A}")
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/syntax_unicode_nameesc.py | Python | apache-2.0 | 158 |
"""
categories: Types,bytearray
description: Array slice assignment with unsupported RHS
cause: Unknown
workaround: Unknown
"""
b = bytearray(4)
b[0:1] = [1, 2]
print(b)
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_bytearray_sliceassign.py | Python | apache-2.0 | 170 |
"""
categories: Types,bytes
description: bytes objects support .format() method
cause: MicroPython strives to be a more regular implementation, so if both `str` and `bytes` support ``__mod__()`` (the % operator), it makes sense to support ``format()`` for both too. Support for ``__mod__`` can also be compiled out, whic... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_bytes_format.py | Python | apache-2.0 | 498 |
"""
categories: Types,bytes
description: bytes() with keywords not implemented
cause: Unknown
workaround: Pass the encoding as a positional parameter, e.g. ``print(bytes('abc', 'utf-8'))``
"""
print(bytes("abc", encoding="utf8"))
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_bytes_keywords.py | Python | apache-2.0 | 230 |
"""
categories: Types,bytes
description: Bytes subscription with step != 1 not implemented
cause: MicroPython is highly optimized for memory usage.
workaround: Use explicit loop for this very rare operation.
"""
print(b"123"[0:3:2])
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_bytes_subscrstep.py | Python | apache-2.0 | 233 |
"""
categories: Types,dict
description: Dictionary keys view does not behave as a set.
cause: Not implemented.
workaround: Explicitly convert keys to a set before using set operations.
"""
print({1: 2, 3: 4}.keys() & {1})
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_dict_keys_set.py | Python | apache-2.0 | 222 |
"""
categories: Types,Exception
description: All exceptions have readable ``value`` and ``errno`` attributes, not just ``StopIteration`` and ``OSError``.
cause: MicroPython is optimised to reduce code size.
workaround: Only use ``value`` on ``StopIteration`` exceptions, and ``errno`` on ``OSError`` exceptions. Do not ... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_exception_attrs.py | Python | apache-2.0 | 424 |
"""
categories: Types,Exception
description: Exception chaining not implemented
cause: Unknown
workaround: Unknown
"""
try:
raise TypeError
except TypeError:
raise ValueError
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_exception_chaining.py | Python | apache-2.0 | 183 |
"""
categories: Types,Exception
description: User-defined attributes for builtin exceptions are not supported
cause: MicroPython is highly optimized for memory usage.
workaround: Use user-defined exception subclasses.
"""
e = Exception()
e.x = 0
print(e.x)
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_exception_instancevar.py | Python | apache-2.0 | 257 |
"""
categories: Types,Exception
description: Exception in while loop condition may have unexpected line number
cause: Condition checks are optimized to happen at the end of loop body, and that line number is reported.
workaround: Unknown
"""
l = ["-foo", "-bar"]
i = 0
while l[i][0] == "-":
print("iter")
i += 1... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_exception_loops.py | Python | apache-2.0 | 321 |
"""
categories: Types,Exception
description: Exception.__init__ method does not exist.
cause: Subclassing native classes is not fully supported in MicroPython.
workaround: Call using ``super()`` instead::
class A(Exception):
def __init__(self):
super().__init__()
"""
class A(Exception):
d... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_exception_subclassinit.py | Python | apache-2.0 | 382 |
"""
categories: Types,float
description: uPy and CPython outputs formats may differ
cause: Unknown
workaround: Unknown
"""
print("%.1g" % -9.9)
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_float_rounding.py | Python | apache-2.0 | 144 |
"""
categories: Types,int
description: ``bit_length`` method doesn't exist.
cause: bit_length method is not implemented.
workaround: Avoid using this method on MicroPython.
"""
x = 255
print("{} is {} bits long.".format(x, x.bit_length()))
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_int_bit_length.py | Python | apache-2.0 | 241 |
"""
categories: Types,int
description: No int conversion for int-derived types available
cause: Unknown
workaround: Avoid subclassing builtin types unless really needed. Prefer https://en.wikipedia.org/wiki/Composition_over_inheritance .
"""
class A(int):
__add__ = lambda self, other: A(int(self) + other)
a = A... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_int_subclassconv.py | Python | apache-2.0 | 338 |
"""
categories: Types,list
description: List delete with step != 1 not implemented
cause: Unknown
workaround: Use explicit loop for this rare operation.
"""
l = [1, 2, 3, 4]
del l[0:4:2]
print(l)
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_list_delete_subscrstep.py | Python | apache-2.0 | 196 |
"""
categories: Types,list
description: List slice-store with non-iterable on RHS is not implemented
cause: RHS is restricted to be a tuple or list
workaround: Use ``list(<iter>)`` on RHS to convert the iterable to a list
"""
l = [10, 20]
l[0:1] = range(4)
print(l)
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_list_store_noniter.py | Python | apache-2.0 | 266 |
"""
categories: Types,list
description: List store with step != 1 not implemented
cause: Unknown
workaround: Use explicit loop for this rare operation.
"""
l = [1, 2, 3, 4]
l[0:4:2] = [5, 6]
print(l)
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_list_store_subscrstep.py | Python | apache-2.0 | 200 |
"""
categories: Types,str
description: Start/end indices such as str.endswith(s, start) not implemented
cause: Unknown
workaround: Unknown
"""
print("abc".endswith("c", 1))
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_str_endswith.py | Python | apache-2.0 | 173 |
"""
categories: Types,str
description: Attributes/subscr not implemented
cause: Unknown
workaround: Unknown
"""
print("{a[0]}".format(a=[1, 2]))
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_str_formatsubscr.py | Python | apache-2.0 | 145 |
"""
categories: Types,str
description: str(...) with keywords not implemented
cause: Unknown
workaround: Input the encoding format directly. eg ``print(bytes('abc', 'utf-8'))``
"""
print(str(b"abc", encoding="utf8"))
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_str_keywords.py | Python | apache-2.0 | 217 |
"""
categories: Types,str
description: str.ljust() and str.rjust() not implemented
cause: MicroPython is highly optimized for memory usage. Easy workarounds available.
workaround: Instead of ``s.ljust(10)`` use ``"%-10s" % s``, instead of ``s.rjust(10)`` use ``"% 10s" % s``. Alternatively, ``"{:<10}".format(s)`` or ``"... | YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_str_ljust_rjust.py | Python | apache-2.0 | 368 |
"""
categories: Types,str
description: None as first argument for rsplit such as str.rsplit(None, n) not implemented
cause: Unknown
workaround: Unknown
"""
print("a a a".rsplit(None, 1))
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_str_rsplitnone.py | Python | apache-2.0 | 187 |
"""
categories: Types,str
description: Subscript with step != 1 is not yet implemented
cause: Unknown
workaround: Unknown
"""
print("abcdefghi"[0:9:2])
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_str_subscrstep.py | Python | apache-2.0 | 152 |
"""
categories: Types,tuple
description: Tuple load with step != 1 not implemented
cause: Unknown
workaround: Unknown
"""
print((1, 2, 3, 4)[0:4:2])
| YifuLiu/AliOS-Things | components/py_engine/tests/cpydiff/types_tuple_subscrstep.py | Python | apache-2.0 | 149 |
try:
from esp32 import Partition as p
import micropython
except ImportError:
print("SKIP")
raise SystemExit
# try some vanilla OSError to get std error code
try:
open("this filedoesnotexist", "r")
print("FAILED TO RAISE")
except OSError as e:
print(e)
# try to make nvs partition bootable, ... | YifuLiu/AliOS-Things | components/py_engine/tests/esp32/check_err_str.py | Python | apache-2.0 | 944 |
# Test the esp32's esp32.idf_heap_info to return sane data
try:
import esp32
except ImportError:
print("SKIP")
raise SystemExit
# region tuple is: (size, free, largest free, min free)
# we check that each region's size is > 0 and that the free amounts are smaller than the size
def chk_heap(kind, regions):
... | YifuLiu/AliOS-Things | components/py_engine/tests/esp32/esp32_idf_heap_info.py | Python | apache-2.0 | 915 |
# Test the esp32 NVS class - access to esp-idf's Non-Volatile-Storage
from esp32 import NVS
nvs = NVS("mp-test")
# test setting and gettin an integer kv
nvs.set_i32("key1", 1234)
print(nvs.get_i32("key1"))
nvs.set_i32("key2", -503)
print(nvs.get_i32("key2"))
print(nvs.get_i32("key1"))
# test setting and getting a b... | YifuLiu/AliOS-Things | components/py_engine/tests/esp32/esp32_nvs.py | Python | apache-2.0 | 1,644 |
# Test ESP32 OTA updates, including automatic roll-back.
# Running this test requires firmware with an OTA Partition, such as the GENERIC_OTA "board".
# This test also requires patience as it copies the boot partition into the other OTA slot.
import machine
from esp32 import Partition
# start by checking that the run... | YifuLiu/AliOS-Things | components/py_engine/tests/esp32/partition_ota.py | Python | apache-2.0 | 3,535 |
# Test that the esp32's socket module performs DNS resolutions on bind and connect
import sys
if sys.implementation.name == "micropython" and sys.platform != "esp32":
print("SKIP")
raise SystemExit
try:
import usocket as socket, sys
except:
import socket, sys
def test_bind_resolves_0_0_0_0():
s ... | YifuLiu/AliOS-Things | components/py_engine/tests/esp32/resolve_on_connect.py | Python | apache-2.0 | 1,391 |
try:
import btree
import uio
import uerrno
except ImportError:
print("SKIP")
raise SystemExit
# f = open("_test.db", "w+b")
f = uio.BytesIO()
db = btree.open(f, pagesize=512)
db[b"foo3"] = b"bar3"
db[b"foo1"] = b"bar1"
db[b"foo2"] = b"bar2"
db[b"bar1"] = b"foo1"
dbstr = str(db)
print(dbstr[:7], d... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/btree1.py | Python | apache-2.0 | 1,446 |
# Test that errno's propagate correctly through btree module.
try:
import btree, uio, uerrno
uio.IOBase
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class Device(uio.IOBase):
def __init__(self, read_ret=0, ioctl_ret=0):
self.read_ret = read_ret
self.ioctl_... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/btree_error.py | Python | apache-2.0 | 1,045 |
# Test btree interaction with the garbage collector.
try:
import btree, uio, gc
except ImportError:
print("SKIP")
raise SystemExit
N = 80
# Create a BytesIO but don't keep a reference to it.
db = btree.open(uio.BytesIO(), pagesize=512)
# Overwrite lots of the Python stack to make sure no reference to th... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/btree_gc.py | Python | apache-2.0 | 747 |
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
maps = {
framebuf.MONO_VLSB: "MONO_VLSB",
framebuf.MONO_HLSB: "MONO_HLSB",
framebuf.MONO_HMSB: "MONO_HMSB",
}
for mapping in maps.keys():
for x in range(size):
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf1.py | Python | apache-2.0 | 2,168 |
try:
import framebuf, usys
except ImportError:
print("SKIP")
raise SystemExit
# This test and its .exp file is based on a little-endian architecture.
if usys.byteorder != "little":
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
print(buf[y * w * ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf16.py | Python | apache-2.0 | 1,212 |
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
for x in range(w):
print("%u" % ((buf[(x + y * w) // 4] >> ((x & 3) << 1)) & 3), end="")
print()
print("-->8--")
w = 8
h = 5
buf = bytearray(... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf2.py | Python | apache-2.0 | 1,068 |
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
print(buf[y * w // 2 : (y + 1) * w // 2])
print("-->8--")
w = 16
h = 8
buf = bytearray(w * h // 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
# f... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf4.py | Python | apache-2.0 | 1,214 |
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
for x in range(w):
print("%02x" % buf[(x + y * w)], end="")
print()
print("-->8--")
w = 8
h = 5
buf = bytearray(w * h)
fbuf = framebuf.FrameB... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf8.py | Python | apache-2.0 | 587 |
# Test blit between different color spaces
try:
import framebuf, usys
except ImportError:
print("SKIP")
raise SystemExit
# Monochrome glyph/icon
w = 8
h = 8
cbuf = bytearray(w * h // 8)
fbc = framebuf.FrameBuffer(cbuf, w, h, framebuf.MONO_HLSB)
fbc.line(0, 0, 7, 7, 1)
# RGB565 destination
wd = 16
hd = 16
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf_palette.py | Python | apache-2.0 | 766 |
# test subclassing framebuf.FrameBuffer
try:
import framebuf, usys
except ImportError:
print("SKIP")
raise SystemExit
# This test and its .exp file is based on a little-endian architecture.
if usys.byteorder != "little":
print("SKIP")
raise SystemExit
class FB(framebuf.FrameBuffer):
def __in... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/framebuf_subclass.py | Python | apache-2.0 | 1,013 |
# test machine module
try:
try:
import umachine as machine
except ImportError:
import machine
machine.mem8
except:
print("SKIP")
raise SystemExit
print(machine.mem8)
try:
machine.mem16[1]
except ValueError:
print("ValueError")
try:
machine.mem16[1] = 1
except ValueErr... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/machine1.py | Python | apache-2.0 | 713 |
try:
try:
import umachine as machine
except ImportError:
import machine
machine.PinBase
except:
print("SKIP")
raise SystemExit
class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
self.v = False
def value(self, v=None):
print("value:"... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/machine_pinbase.py | Python | apache-2.0 | 498 |
try:
try:
import umachine as machine
except ImportError:
import machine
machine.PinBase
machine.time_pulse_us
except:
print("SKIP")
raise SystemExit
class ConstPin(machine.PinBase):
def __init__(self, value):
self.v = value
def value(self, v=None):
if v... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/machine_pulse.py | Python | apache-2.0 | 826 |
# test machine.Signal class
try:
try:
import umachine as machine
except ImportError:
import machine
machine.PinBase
machine.Signal
except:
print("SKIP")
raise SystemExit
class Pin(machine.PinBase):
def __init__(self):
self.v = 0
def value(self, v=None):
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/machine_signal.py | Python | apache-2.0 | 695 |
# test machine.Timer
try:
import utime, umachine as machine
machine.Timer
except:
print("SKIP")
raise SystemExit
# create and deinit
t = machine.Timer(freq=1)
t.deinit()
# deinit again
t.deinit()
# create 2 and deinit
t = machine.Timer(freq=1)
t2 = machine.Timer(freq=1)
t.deinit()
t2.deinit()
# cr... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/machine_timer.py | Python | apache-2.0 | 832 |
try:
from utime import ticks_diff, ticks_add
except ImportError:
print("SKIP")
raise SystemExit
MAX = ticks_add(0, -1)
# Should be done like this to avoid small int overflow
MODULO_HALF = MAX // 2 + 1
# Invariants:
# if ticks_diff(a, b) = c,
# then ticks_diff(b, a) = -c
assert ticks_diff(1, 0) == 1, tick... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ticks_diff.py | Python | apache-2.0 | 1,152 |
try:
import utime
utime.sleep_ms, utime.sleep_us, utime.ticks_diff, utime.ticks_ms, utime.ticks_us, utime.ticks_cpu
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
utime.sleep_ms(1)
utime.sleep_us(1)
t0 = utime.ticks_ms()
t1 = utime.ticks_ms()
print(0 <= utime.ticks_diff(t1, t0) ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/time_ms_us.py | Python | apache-2.0 | 574 |
# Test that tasks return their value correctly to the caller
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def foo():
return 42
async def main():
# Call function directly via an await
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_await_return.py | Python | apache-2.0 | 458 |
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
try:
import utime
ticks = utime.ticks_ms
ticks_diff = utime.ticks_diff
except:
import time
ticks = lambda: int(time.time() * 1000)
ti... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_basic.py | Python | apache-2.0 | 912 |
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def forever():
print("forever start")
await asyncio.sleep(10)
async def main():
print("main start")
asyncio.create_task(forever())
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_basic2.py | Python | apache-2.0 | 413 |
# Test fairness of cancelling a task
# That tasks which continuously cancel each other don't take over the scheduler
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(id, other):
for i in r... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_cancel_fair.py | Python | apache-2.0 | 846 |
# Test fairness of cancelling a task
# That tasks which keeps being cancelled by multiple other tasks gets a chance to run
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task_a():
try:
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_cancel_fair2.py | Python | apache-2.0 | 760 |
# Test a task cancelling itself (currently unsupported)
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task():
print("task start")
global_task.cancel()
async def main():
global glob... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_cancel_self.py | Python | apache-2.0 | 568 |
# Test cancelling a task
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
await asyncio.sleep(s)
print("task done")
e... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_cancel_task.py | Python | apache-2.0 | 2,078 |
# Test cancelling a task that is waiting on a task that just finishes.
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def sleep_task():
print("sleep_task sleep")
await asyncio.sleep(0)
pr... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_cancel_wait_on_finished.py | Python | apache-2.0 | 818 |
# Test current_task() function
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(result):
result[0] = asyncio.current_task()
async def main():
result = [None]
t = asyncio.create_t... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_current_task.py | Python | apache-2.0 | 440 |
# Test Event class
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(id, ev):
print("start", id)
print(await ev.wait())
print("end", id)
async def task_delay_set(t, ev):
await... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_event.py | Python | apache-2.0 | 2,217 |
# Test fairness of Event.set()
# That tasks which continuously wait on events don't take over the scheduler
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task1(id):
for i in range(4):
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_event_fair.py | Python | apache-2.0 | 791 |
# Test general exception handling
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
# main task raising an exception
async def main():
print("main start")
raise ValueError(1)
print("main done")
t... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_exception.py | Python | apache-2.0 | 1,158 |
# Test fairness of scheduler
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(id, t):
print("task start", id)
while True:
if t > 0:
print("task work", id)
a... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_fair.py | Python | apache-2.0 | 673 |
# test uasyncio.gather() function
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def factorial(name, number):
f = 1
for i in range(2, number + 1):
print("Task {}: Compute factorial({}... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_gather.py | Python | apache-2.0 | 1,217 |
# Test get_event_loop()
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def main():
print("start")
await asyncio.sleep(0.01)
print("end")
loop = asyncio.get_event_loop()
loop.run_until_c... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_get_event_loop.py | Python | apache-2.0 | 336 |
# test that basic scheduling of tasks, and uasyncio.sleep_ms, does not use the heap
import micropython
# strict stackless builds can't call functions without allocating a frame on the heap
try:
f = lambda: 0
micropython.heap_lock()
f()
micropython.heap_unlock()
except RuntimeError:
print("SKIP")
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_heaplock.py | Python | apache-2.0 | 918 |
# Test Lock class
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task_loop(id, lock):
print("task start", id)
for i in range(3):
async with lock:
print("task have", id... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_lock.py | Python | apache-2.0 | 2,394 |
# Test that locks work when cancelling multiple waiters on the lock
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(i, lock, lock_flag):
print("task", i, "start")
try:
await l... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_lock_cancel.py | Python | apache-2.0 | 1,373 |
# Test Loop.stop() to stop the event loop
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task():
print("task")
async def main():
print("start")
# Stop the loop after next yield
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_loop_stop.py | Python | apache-2.0 | 795 |
# Test MicroPython extensions on CPython asyncio:
# - sleep_ms
# - wait_for_ms
try:
import utime, uasyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(id, t):
print("task start", id)
await uasyncio.sleep_ms(t)
print("task end", id)
return id * 2
async def main():
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_micropython.py | Python | apache-2.0 | 772 |
# Test Loop.new_event_loop()
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task():
for i in range(4):
print("task", i)
await asyncio.sleep(0)
await asyncio.sleep(0)
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_new_event_loop.py | Python | apache-2.0 | 703 |
# Test that tasks return their value correctly to the caller
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
def custom_handler(loop, context):
print("custom_handler", repr(context["exception"]))
asyn... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_set_exception_handler.py | Python | apache-2.0 | 1,381 |
# Test the Task.done() method
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(t, exc=None):
print("task start")
if t >= 0:
await asyncio.sleep(t)
if exc:
raise exc... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_task_done.py | Python | apache-2.0 | 1,332 |
# Test Event class
try:
import uasyncio as asyncio
except ImportError:
print("SKIP")
raise SystemExit
import micropython
try:
micropython.schedule
except AttributeError:
print("SKIP")
raise SystemExit
try:
# Unix port can't select/poll on user-defined types.
import uselect as selec... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_threadsafeflag.py | Python | apache-2.0 | 1,488 |
# Test asyncio.wait_for
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(id, t):
print("task start", id)
await asyncio.sleep(t)
print("task end", id)
return id * 2
async def ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_wait_for.py | Python | apache-2.0 | 2,851 |
# Test asyncio.wait_for, with forwarding cancellation
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def awaiting(t, return_if_fail):
try:
print("awaiting started")
await asyncio.... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_wait_for_fwd.py | Python | apache-2.0 | 1,657 |
# Test waiting on a task
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
try:
import utime
ticks = utime.ticks_ms
ticks_diff = utime.ticks_diff
except:
import time
ticks = lambda: int(... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uasyncio_wait_task.py | Python | apache-2.0 | 1,453 |
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
except ImportError:
print("SKIP")
raise SystemExit
print(binascii.a2b_base64(b""))
print(binascii.a2b_base64(b"Zg=="))
print(binascii.a2b_base64(b"Zm8="))
print(binascii.a2b_base64(b"Zm9v"))
print(binascii.a2b_ba... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ubinascii_a2b_base64.py | Python | apache-2.0 | 1,248 |
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
except ImportError:
print("SKIP")
raise SystemExit
print(binascii.b2a_base64(b""))
print(binascii.b2a_base64(b"f"))
print(binascii.b2a_base64(b"fo"))
print(binascii.b2a_base64(b"foo"))
print(binascii.b2a_base64(b... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ubinascii_b2a_base64.py | Python | apache-2.0 | 682 |
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
except ImportError:
print("SKIP")
raise SystemExit
try:
binascii.crc32
except AttributeError:
print("SKIP")
raise SystemExit
print(hex(binascii.crc32(b"The quick brown fox jumps over the lazy dog")))... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ubinascii_crc32.py | Python | apache-2.0 | 770 |
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
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")... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ubinascii_hexlify.py | Python | apache-2.0 | 363 |
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":"))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ubinascii_micropython.py | Python | apache-2.0 | 308 |
try:
try:
import ubinascii as binascii
except ImportError:
import binascii
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"313... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ubinascii_unhexlify.py | Python | apache-2.0 | 548 |
try:
from Crypto.Cipher import AES
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
crypto = aes(b"1234" * 4, 2, b"5678" * 4)
enc = crypto.encrypt(bytes(range(32)))
print(enc)
crypto = aes(b"1234" * 4, 2, b"567... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes128_cbc.py | Python | apache-2.0 | 355 |
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
def _new(k, ctr_initial):
return aes(k, 6, ctr_initial)
try:
_new(b"x" * 16, b"x" * 16)
except ValueError as e:
# is CTR support disabled?
if e.args[0] == "mode":
print("SKIP")
raise System... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes128_ctr.py | Python | apache-2.0 | 530 |
try:
from Crypto.Cipher import AES
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
crypto = aes(b"1234" * 4, 1)
enc = crypto.encrypt(bytes(range(32)))
print(enc)
crypto = aes(b"1234" * 4, 1)
print(crypto.decry... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes128_ecb.py | Python | apache-2.0 | 329 |
# This tests minimal configuration of ucrypto module, which is
# AES128 encryption (anything else, including AES128 decryption,
# is optional).
try:
from Crypto.Cipher import AES
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes128_ecb_enc.py | Python | apache-2.0 | 417 |
# Inplace operations (input and output buffer is the same)
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
crypto = aes(b"1234" * 4, 1)
buf = bytearray(bytes(range(32)))
crypto.encrypt(buf, buf)
print(buf)
crypto = aes(b"1234" * 4, 1)
crypto.decrypt(buf, buf)
print(buf)
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes128_ecb_inpl.py | Python | apache-2.0 | 320 |
# Operations with pre-allocated output buffer
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
crypto = aes(b"1234" * 4, 1)
enc = bytearray(32)
crypto.encrypt(bytes(range(32)), enc)
print(enc)
crypto = aes(b"1234" * 4, 1)
dec = bytearray(32)
crypto.decrypt(enc, dec)
print... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes128_ecb_into.py | Python | apache-2.0 | 326 |
try:
from Crypto.Cipher import AES
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
crypto = aes(b"1234" * 8, 2, b"5678" * 4)
enc = crypto.encrypt(bytes(range(32)))
print(enc)
crypto = aes(b"1234" * 8, 2, b"567... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes256_cbc.py | Python | apache-2.0 | 355 |
try:
from Crypto.Cipher import AES
aes = AES.new
except ImportError:
try:
from ucryptolib import aes
except ImportError:
print("SKIP")
raise SystemExit
crypto = aes(b"1234" * 8, 1)
enc = crypto.encrypt(bytes(range(32)))
print(enc)
crypto = aes(b"1234" * 8, 1)
print(crypto.decry... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/ucryptolib_aes256_ecb.py | Python | apache-2.0 | 329 |
# This test checks previously known problem values for 32-bit ports.
# It's less useful for 64-bit ports.
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
buf = b"12345678abcd"
struct = uctypes.struct(
uctypes.addressof(buf),
{"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 |... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_32bit_intbig.py | Python | apache-2.0 | 896 |
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_array_assign_le.py | Python | apache-2.0 | 1,382 |
import usys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if usys.byteorder != "little":
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 of... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_array_assign_native_le.py | Python | apache-2.0 | 2,012 |
import usys
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
if usys.byteorder != "little":
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 of... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_array_assign_native_le_intbig.py | Python | apache-2.0 | 1,205 |
# Test uctypes array, load and store, with array size > 1
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
N = 5
for endian in ("NATIVE", "LITTLE_ENDIAN", "BIG_ENDIAN"):
for type_ in ("INT8", "UINT8", "INT16", "UINT16", "INT32", "UINT32", "INT64", "UINT64"):
desc = {"arr... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_array_load_store.py | Python | apache-2.0 | 640 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
"arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2),
}
data = bytearray(b"01234567")
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
# Arrays of UINT8... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_bytearray.py | Python | apache-2.0 | 471 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
data = bytearray(b"01234567")
print(uctypes.bytes_at(uctypes.addressof(data), 4))
print(uctypes.bytearray_at(uctypes.addressof(data), 4))
| YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_byteat.py | Python | apache-2.0 | 223 |
# test general errors with uctypes
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
data = bytearray(b"01234567")
# del subscr not supported
S = uctypes.struct(uctypes.addressof(data), {})
try:
del S[0]
except TypeError:
print("TypeError")
# list is an invalid descriptor
S ... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_error.py | Python | apache-2.0 | 838 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"s0": uctypes.UINT16 | 0,
"sub": (0, {"b0": uctypes.UINT8 | 0, "b1": uctypes.UINT8 | 1}),
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"bitf0": uct... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_le.py | Python | apache-2.0 | 2,257 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"f32": uctypes.FLOAT32 | 0,
"f64": uctypes.FLOAT64 | 0,
"uf64": uctypes.FLOAT64 | 2, # unaligned
}
data = bytearray(10)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
S.f32 = 12.34
prin... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_le_float.py | Python | apache-2.0 | 810 |
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
desc = {
"f32": uctypes.FLOAT32 | 0,
"f64": uctypes.FLOAT64 | 0,
}
data = bytearray(8)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
S.f32 = 12.34
print("%.4f" % S.f32)
S.f64 = 12.34
print("%.4f" % S.f64)... | YifuLiu/AliOS-Things | components/py_engine/tests/extmod/uctypes_native_float.py | Python | apache-2.0 | 321 |