tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
This commit is contained in:
parent
488613bca6
commit
3dc324d3f1
@ -4,9 +4,9 @@
|
||||
for i in ():
|
||||
pass
|
||||
a = None
|
||||
b = 'str'
|
||||
c = 'a very long str that will not be interned'
|
||||
d = b'bytes'
|
||||
e = b'a very long bytes that will not be interned'
|
||||
b = "str"
|
||||
c = "a very long str that will not be interned"
|
||||
d = b"bytes"
|
||||
e = b"a very long bytes that will not be interned"
|
||||
f = 123456789012345678901234567890
|
||||
g = 123
|
||||
|
@ -1,5 +1,6 @@
|
||||
# cmdline: -v -v
|
||||
# test printing of all bytecodes
|
||||
# fmt: off
|
||||
|
||||
def f():
|
||||
# constants
|
||||
|
@ -7,7 +7,7 @@ arg names:
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
########
|
||||
bc=\\d\+ line=159
|
||||
bc=\\d\+ line=160
|
||||
00 MAKE_FUNCTION \.\+
|
||||
\\d\+ STORE_NAME f
|
||||
\\d\+ MAKE_FUNCTION \.\+
|
||||
@ -45,7 +45,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
|
||||
(INIT_CELL 16)
|
||||
bc=0 line=1
|
||||
########
|
||||
bc=\\d\+ line=126
|
||||
bc=\\d\+ line=127
|
||||
00 LOAD_CONST_NONE
|
||||
01 LOAD_CONST_FALSE
|
||||
02 BINARY_OP 27 __add__
|
||||
@ -320,7 +320,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
########
|
||||
bc=\\d\+ line=132
|
||||
bc=\\d\+ line=133
|
||||
00 LOAD_CONST_SMALL_INT 1
|
||||
01 DUP_TOP
|
||||
02 STORE_FAST 0
|
||||
@ -376,7 +376,7 @@ arg names: a
|
||||
(N_EXC_STACK 0)
|
||||
(INIT_CELL 0)
|
||||
########
|
||||
bc=\\d\+ line=138
|
||||
bc=\\d\+ line=139
|
||||
00 LOAD_CONST_SMALL_INT 2
|
||||
01 BUILD_TUPLE 1
|
||||
03 LOAD_NULL
|
||||
@ -393,9 +393,9 @@ arg names:
|
||||
(N_STATE 2)
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
bc=0 line=143
|
||||
bc=3 line=144
|
||||
bc=6 line=145
|
||||
bc=0 line=144
|
||||
bc=3 line=145
|
||||
bc=6 line=146
|
||||
00 LOAD_CONST_NONE
|
||||
01 YIELD_VALUE
|
||||
02 POP_TOP
|
||||
@ -418,7 +418,7 @@ arg names:
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
########
|
||||
bc=13 line=149
|
||||
bc=13 line=150
|
||||
00 LOAD_NAME __name__ (cache=0)
|
||||
04 STORE_NAME __module__
|
||||
07 LOAD_CONST_STRING 'Class'
|
||||
@ -433,7 +433,7 @@ arg names: self
|
||||
(N_STATE 4)
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
bc=0 line=156
|
||||
bc=0 line=157
|
||||
00 LOAD_GLOBAL super (cache=0)
|
||||
\\d\+ LOAD_GLOBAL __class__ (cache=0)
|
||||
\\d\+ LOAD_FAST 0
|
||||
@ -450,7 +450,7 @@ arg names: * * *
|
||||
(N_STATE 9)
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
bc=0 line=59
|
||||
bc=0 line=60
|
||||
########
|
||||
00 LOAD_NULL
|
||||
01 LOAD_FAST 2
|
||||
@ -474,7 +474,7 @@ arg names: * * *
|
||||
(N_STATE 10)
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
bc=0 line=60
|
||||
bc=0 line=61
|
||||
########
|
||||
00 BUILD_LIST 0
|
||||
02 LOAD_FAST 2
|
||||
@ -517,7 +517,7 @@ arg names: *
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
########
|
||||
bc=\\d\+ line=113
|
||||
bc=\\d\+ line=114
|
||||
00 LOAD_DEREF 0
|
||||
02 LOAD_CONST_SMALL_INT 1
|
||||
03 BINARY_OP 27 __add__
|
||||
@ -536,7 +536,7 @@ arg names: * b
|
||||
(N_EXC_STACK 0)
|
||||
bc=0 line=1
|
||||
########
|
||||
bc=\\d\+ line=139
|
||||
bc=\\d\+ line=140
|
||||
00 LOAD_FAST 1
|
||||
01 LOAD_DEREF 0
|
||||
03 BINARY_OP 27 __add__
|
||||
|
@ -6,9 +6,11 @@ workaround: Unknown
|
||||
"""
|
||||
import gc
|
||||
|
||||
class Foo():
|
||||
|
||||
class Foo:
|
||||
def __del__(self):
|
||||
print('__del__')
|
||||
print("__del__")
|
||||
|
||||
|
||||
f = Foo()
|
||||
del f
|
||||
|
@ -4,12 +4,16 @@ description: Method Resolution Order (MRO) is not compliant with CPython
|
||||
cause: Depth first non-exhaustive method resolution order
|
||||
workaround: Avoid complex class hierarchies with multiple inheritance and complex method overrides. Keep in mind that many languages don't support multiple inheritance at all.
|
||||
"""
|
||||
|
||||
|
||||
class Foo:
|
||||
def __str__(self):
|
||||
return "Foo"
|
||||
|
||||
|
||||
class C(tuple, Foo):
|
||||
pass
|
||||
|
||||
|
||||
t = C((1, 2, 3))
|
||||
print(t)
|
||||
|
@ -4,24 +4,29 @@ description: When inheriting from multiple classes super() only calls one class
|
||||
cause: See :ref:`cpydiff_core_class_mro`
|
||||
workaround: See :ref:`cpydiff_core_class_mro`
|
||||
"""
|
||||
|
||||
|
||||
class A:
|
||||
def __init__(self):
|
||||
print("A.__init__")
|
||||
|
||||
|
||||
class B(A):
|
||||
def __init__(self):
|
||||
print("B.__init__")
|
||||
super().__init__()
|
||||
|
||||
|
||||
class C(A):
|
||||
def __init__(self):
|
||||
print("C.__init__")
|
||||
super().__init__()
|
||||
|
||||
|
||||
class D(B,C):
|
||||
class D(B, C):
|
||||
def __init__(self):
|
||||
print("D.__init__")
|
||||
super().__init__()
|
||||
|
||||
|
||||
D()
|
||||
|
@ -4,15 +4,19 @@ description: Calling super() getter property in subclass will return a property
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
|
||||
|
||||
class A:
|
||||
@property
|
||||
def p(self):
|
||||
return {"a":10}
|
||||
return {"a": 10}
|
||||
|
||||
|
||||
class AA(A):
|
||||
@property
|
||||
def p(self):
|
||||
return super().p
|
||||
|
||||
|
||||
a = AA()
|
||||
print(a.p)
|
||||
|
@ -4,8 +4,11 @@ description: User-defined attributes for functions are not supported
|
||||
cause: MicroPython is highly optimized for memory usage.
|
||||
workaround: Use external dictionary, e.g. ``FUNC_X[f] = 0``.
|
||||
"""
|
||||
|
||||
|
||||
def f():
|
||||
pass
|
||||
|
||||
|
||||
f.x = 0
|
||||
print(f.x)
|
||||
|
@ -4,11 +4,15 @@ description: Context manager __exit__() not called in a generator which does not
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
|
||||
|
||||
class foo(object):
|
||||
def __enter__(self):
|
||||
print('Enter')
|
||||
print("Enter")
|
||||
|
||||
def __exit__(self, *args):
|
||||
print('Exit')
|
||||
print("Exit")
|
||||
|
||||
|
||||
def bar(x):
|
||||
with foo():
|
||||
@ -16,9 +20,11 @@ def bar(x):
|
||||
x += 1
|
||||
yield x
|
||||
|
||||
|
||||
def func():
|
||||
g = bar(0)
|
||||
for _ in range(3):
|
||||
print(next(g))
|
||||
|
||||
|
||||
func()
|
||||
|
@ -12,6 +12,7 @@ except NameError as e:
|
||||
print(e)
|
||||
try:
|
||||
from modules import foo
|
||||
print('Should not get here')
|
||||
|
||||
print("Should not get here")
|
||||
except NameError as e:
|
||||
print(e)
|
||||
|
@ -5,6 +5,7 @@ cause: MicroPython's import system is highly optimized for simplicity, minimal m
|
||||
workaround: Don't install modules belonging to the same namespace package in different directories. For MicroPython, it's recommended to have at most 3-component module search paths: for your current application, per-user (writable), system-wide (non-writable).
|
||||
"""
|
||||
import sys
|
||||
|
||||
sys.path.append(sys.path[1] + "/modules")
|
||||
sys.path.append(sys.path[1] + "/modules2")
|
||||
|
||||
|
@ -4,8 +4,11 @@ description: Local variables aren't included in locals() result
|
||||
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name.
|
||||
workaround: Unknown
|
||||
"""
|
||||
|
||||
|
||||
def test():
|
||||
val = 2
|
||||
print(locals())
|
||||
|
||||
|
||||
test()
|
||||
|
@ -6,9 +6,11 @@ workaround: Unknown
|
||||
"""
|
||||
val = 1
|
||||
|
||||
|
||||
def test():
|
||||
val = 2
|
||||
print(val)
|
||||
eval("print(val)")
|
||||
|
||||
|
||||
test()
|
||||
|
@ -1,2 +1,2 @@
|
||||
print('foo')
|
||||
print("foo")
|
||||
xxx
|
||||
|
@ -5,4 +5,5 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
import array
|
||||
print(1 in array.array('B', b'12'))
|
||||
|
||||
print(1 in array.array("B", b"12"))
|
||||
|
@ -5,6 +5,7 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
import array
|
||||
a = array.array('b', (1, 2, 3))
|
||||
|
||||
a = array.array("b", (1, 2, 3))
|
||||
del a[1]
|
||||
print(a)
|
||||
|
@ -5,5 +5,6 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
import array
|
||||
a = array.array('b', (1, 2, 3))
|
||||
|
||||
a = array.array("b", (1, 2, 3))
|
||||
print(a[3:2:2])
|
||||
|
@ -5,5 +5,6 @@ cause: Unknown
|
||||
workaround: Use regular lists. micropython-lib has implementation of collections.deque.
|
||||
"""
|
||||
import collections
|
||||
|
||||
D = collections.deque()
|
||||
print(D)
|
||||
|
@ -5,10 +5,11 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
import json
|
||||
|
||||
a = bytes(x for x in range(256))
|
||||
try:
|
||||
z = json.dumps(a)
|
||||
x = json.loads(z)
|
||||
print('Should not get here')
|
||||
print("Should not get here")
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
@ -5,12 +5,13 @@ cause: Unknown
|
||||
workaround: Use ``getenv``, ``putenv`` and ``unsetenv``
|
||||
"""
|
||||
import os
|
||||
|
||||
try:
|
||||
print(os.environ.get('NEW_VARIABLE'))
|
||||
os.environ['NEW_VARIABLE'] = 'VALUE'
|
||||
print(os.environ['NEW_VARIABLE'])
|
||||
print(os.environ.get("NEW_VARIABLE"))
|
||||
os.environ["NEW_VARIABLE"] = "VALUE"
|
||||
print(os.environ["NEW_VARIABLE"])
|
||||
except AttributeError:
|
||||
print('should not get here')
|
||||
print(os.getenv('NEW_VARIABLE'))
|
||||
os.putenv('NEW_VARIABLE', 'VALUE')
|
||||
print(os.getenv('NEW_VARIABLE'))
|
||||
print("should not get here")
|
||||
print(os.getenv("NEW_VARIABLE"))
|
||||
os.putenv("NEW_VARIABLE", "VALUE")
|
||||
print(os.getenv("NEW_VARIABLE"))
|
||||
|
@ -5,6 +5,7 @@ cause: The ``environ`` attribute is not implemented
|
||||
workaround: Unknown
|
||||
"""
|
||||
import os
|
||||
print(os.getenv('NEW_VARIABLE'))
|
||||
os.putenv('NEW_VARIABLE', 'VALUE')
|
||||
print(os.getenv('NEW_VARIABLE'))
|
||||
|
||||
print(os.getenv("NEW_VARIABLE"))
|
||||
os.putenv("NEW_VARIABLE", "VALUE")
|
||||
print(os.getenv("NEW_VARIABLE"))
|
||||
|
@ -5,9 +5,10 @@ cause: Unknown
|
||||
workaround: Test that the return value is ``None``
|
||||
"""
|
||||
import os
|
||||
|
||||
try:
|
||||
print(os.getenv('NEW_VARIABLE', 'DEFAULT'))
|
||||
print(os.getenv("NEW_VARIABLE", "DEFAULT"))
|
||||
except TypeError:
|
||||
print('should not get here')
|
||||
print("should not get here")
|
||||
# this assumes NEW_VARIABLE is never an empty variable
|
||||
print(os.getenv('NEW_VARIABLE') or 'DEFAULT')
|
||||
print(os.getenv("NEW_VARIABLE") or "DEFAULT")
|
||||
|
@ -5,8 +5,9 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
import struct
|
||||
|
||||
try:
|
||||
print(struct.pack('bb', 1))
|
||||
print('Should not get here')
|
||||
print(struct.pack("bb", 1))
|
||||
print("Should not get here")
|
||||
except:
|
||||
print('struct.error')
|
||||
print("struct.error")
|
||||
|
@ -5,8 +5,9 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
import struct
|
||||
|
||||
try:
|
||||
print(struct.pack('bb', 1, 2, 3))
|
||||
print('Should not get here')
|
||||
print(struct.pack("bb", 1, 2, 3))
|
||||
print("Should not get here")
|
||||
except:
|
||||
print('struct.error')
|
||||
print("struct.error")
|
||||
|
@ -5,5 +5,6 @@ cause: They are stored in read-only memory.
|
||||
workaround: Unknown
|
||||
"""
|
||||
import sys
|
||||
|
||||
sys.stdin = None
|
||||
print(sys.stdin)
|
||||
|
@ -5,14 +5,14 @@ cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
try:
|
||||
print(eval('1and 0'))
|
||||
print(eval("1and 0"))
|
||||
except SyntaxError:
|
||||
print('Should have worked')
|
||||
print("Should have worked")
|
||||
try:
|
||||
print(eval('1or 0'))
|
||||
print(eval("1or 0"))
|
||||
except SyntaxError:
|
||||
print('Should have worked')
|
||||
print("Should have worked")
|
||||
try:
|
||||
print(eval('1if 1else 0'))
|
||||
print(eval("1if 1else 0"))
|
||||
except SyntaxError:
|
||||
print('Should have worked')
|
||||
print("Should have worked")
|
||||
|
@ -4,4 +4,4 @@ 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, which leaves only ``format()`` for bytes formatting.
|
||||
workaround: If you are interested in CPython compatibility, don't use ``.format()`` on bytes objects.
|
||||
"""
|
||||
print(b'{}'.format(1))
|
||||
print(b"{}".format(1))
|
||||
|
@ -4,4 +4,4 @@ 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'))
|
||||
print(bytes("abc", encoding="utf8"))
|
||||
|
@ -4,4 +4,4 @@ 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])
|
||||
print(b"123"[0:3:2])
|
||||
|
@ -4,4 +4,4 @@ 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})
|
||||
print({1: 2, 3: 4}.keys() & {1})
|
||||
|
@ -8,8 +8,11 @@ workaround: Call using ``super()`` instead::
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
"""
|
||||
|
||||
|
||||
class A(Exception):
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
|
||||
|
||||
a = A()
|
||||
|
@ -4,4 +4,4 @@ description: uPy and CPython outputs formats may differ
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
print('%.1g' % -9.9)
|
||||
print("%.1g" % -9.9)
|
||||
|
@ -4,8 +4,11 @@ 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(42)
|
||||
print(a+a)
|
||||
print(a + a)
|
||||
|
@ -4,4 +4,4 @@ description: Start/end indices such as str.endswith(s, start) not implemented
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
print('abc'.endswith('c', 1))
|
||||
print("abc".endswith("c", 1))
|
||||
|
@ -4,4 +4,4 @@ description: Attributes/subscr not implemented
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
print('{a[0]}'.format(a=[1, 2]))
|
||||
print("{a[0]}".format(a=[1, 2]))
|
||||
|
@ -4,4 +4,4 @@ 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'))
|
||||
print(str(b"abc", encoding="utf8"))
|
||||
|
@ -4,4 +4,4 @@ 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 ``"{:>10}".format(s)``.
|
||||
"""
|
||||
print('abc'.ljust(10))
|
||||
print("abc".ljust(10))
|
||||
|
@ -4,4 +4,4 @@ description: None as first argument for rsplit such as str.rsplit(None, n) not i
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
print('a a a'.rsplit(None, 1))
|
||||
print("a a a".rsplit(None, 1))
|
||||
|
@ -4,4 +4,4 @@ description: Subscript with step != 1 is not yet implemented
|
||||
cause: Unknown
|
||||
workaround: Unknown
|
||||
"""
|
||||
print('abcdefghi'[0:9:2])
|
||||
print("abcdefghi"[0:9:2])
|
||||
|
@ -6,7 +6,7 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
#f = open("_test.db", "w+b")
|
||||
# f = open("_test.db", "w+b")
|
||||
f = uio.BytesIO()
|
||||
db = btree.open(f, pagesize=512)
|
||||
|
||||
|
@ -8,9 +8,11 @@ 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'}
|
||||
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):
|
||||
@ -43,33 +45,33 @@ for mapping in maps.keys():
|
||||
# hline
|
||||
fbuf.fill(0)
|
||||
fbuf.hline(0, 1, w, 1)
|
||||
print('hline', buf)
|
||||
print("hline", buf)
|
||||
|
||||
# vline
|
||||
fbuf.fill(0)
|
||||
fbuf.vline(1, 0, h, 1)
|
||||
print('vline', buf)
|
||||
print("vline", buf)
|
||||
|
||||
# rect
|
||||
fbuf.fill(0)
|
||||
fbuf.rect(1, 1, 3, 3, 1)
|
||||
print('rect', buf)
|
||||
print("rect", buf)
|
||||
|
||||
#fill rect
|
||||
# fill rect
|
||||
fbuf.fill(0)
|
||||
fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
|
||||
fbuf.fill_rect(1, 1, 3, 3, 1)
|
||||
print('fill_rect', buf)
|
||||
print("fill_rect", buf)
|
||||
|
||||
# line
|
||||
fbuf.fill(0)
|
||||
fbuf.line(1, 1, 3, 3, 1)
|
||||
print('line', buf)
|
||||
print("line", buf)
|
||||
|
||||
# line steep negative gradient
|
||||
fbuf.fill(0)
|
||||
fbuf.line(3, 3, 2, 1, 1)
|
||||
print('line', buf)
|
||||
print("line", buf)
|
||||
|
||||
# scroll
|
||||
fbuf.fill(0)
|
||||
|
@ -4,28 +4,30 @@ 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(buf[y * w * 2 : (y + 1) * w * 2])
|
||||
print("-->8--")
|
||||
|
||||
|
||||
w = 4
|
||||
h = 5
|
||||
buf = bytearray(w * h * 2)
|
||||
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
|
||||
|
||||
# fill
|
||||
fbuf.fill(0xffff)
|
||||
fbuf.fill(0xFFFF)
|
||||
printbuf()
|
||||
fbuf.fill(0x0000)
|
||||
printbuf()
|
||||
|
||||
# put pixel
|
||||
fbuf.pixel(0, 0, 0xeeee)
|
||||
fbuf.pixel(3, 0, 0xee00)
|
||||
fbuf.pixel(0, 4, 0x00ee)
|
||||
fbuf.pixel(3, 4, 0x0ee0)
|
||||
fbuf.pixel(0, 0, 0xEEEE)
|
||||
fbuf.pixel(3, 0, 0xEE00)
|
||||
fbuf.pixel(0, 4, 0x00EE)
|
||||
fbuf.pixel(3, 4, 0x0EE0)
|
||||
printbuf()
|
||||
|
||||
# get pixel
|
||||
@ -33,7 +35,7 @@ print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
|
||||
|
||||
# scroll
|
||||
fbuf.fill(0x0000)
|
||||
fbuf.pixel(2, 2, 0xffff)
|
||||
fbuf.pixel(2, 2, 0xFFFF)
|
||||
printbuf()
|
||||
fbuf.scroll(0, 1)
|
||||
printbuf()
|
||||
@ -48,11 +50,11 @@ buf2 = bytearray(w2 * h2 * 2)
|
||||
fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
|
||||
|
||||
fbuf2.fill(0x0000)
|
||||
fbuf2.pixel(0, 0, 0x0ee0)
|
||||
fbuf2.pixel(0, 2, 0xee00)
|
||||
fbuf2.pixel(1, 0, 0x00ee)
|
||||
fbuf2.pixel(1, 2, 0xe00e)
|
||||
fbuf.fill(0xffff)
|
||||
fbuf2.pixel(0, 0, 0x0EE0)
|
||||
fbuf2.pixel(0, 2, 0xEE00)
|
||||
fbuf2.pixel(1, 0, 0x00EE)
|
||||
fbuf2.pixel(1, 2, 0xE00E)
|
||||
fbuf.fill(0xFFFF)
|
||||
fbuf.blit(fbuf2, 3, 3, 0x0000)
|
||||
fbuf.blit(fbuf2, -1, -1, 0x0000)
|
||||
fbuf.blit(fbuf2, 16, 16, 0x0000)
|
||||
|
@ -4,14 +4,16 @@ 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("%u" % ((buf[(x + y * w) // 4] >> ((x & 3) << 1)) & 3), end="")
|
||||
print()
|
||||
print("-->8--")
|
||||
|
||||
|
||||
w = 8
|
||||
h = 5
|
||||
buf = bytearray(w * h // 4)
|
||||
|
@ -4,50 +4,52 @@ 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(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)
|
||||
|
||||
# fill
|
||||
fbuf.fill(0x0f)
|
||||
fbuf.fill(0x0F)
|
||||
printbuf()
|
||||
fbuf.fill(0xa0)
|
||||
fbuf.fill(0xA0)
|
||||
printbuf()
|
||||
|
||||
# put pixel
|
||||
fbuf.pixel(0, 0, 0x01)
|
||||
printbuf()
|
||||
fbuf.pixel(w-1, 0, 0x02)
|
||||
fbuf.pixel(w - 1, 0, 0x02)
|
||||
printbuf()
|
||||
fbuf.pixel(w-1, h-1, 0x03)
|
||||
fbuf.pixel(w - 1, h - 1, 0x03)
|
||||
printbuf()
|
||||
fbuf.pixel(0, h-1, 0x04)
|
||||
fbuf.pixel(0, h - 1, 0x04)
|
||||
printbuf()
|
||||
|
||||
# get pixel
|
||||
print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1))
|
||||
print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1))
|
||||
print(fbuf.pixel(0, 0), fbuf.pixel(w - 1, 0), fbuf.pixel(w - 1, h - 1), fbuf.pixel(0, h - 1))
|
||||
print(fbuf.pixel(1, 0), fbuf.pixel(w - 2, 0), fbuf.pixel(w - 2, h - 1), fbuf.pixel(1, h - 1))
|
||||
|
||||
# fill rect
|
||||
fbuf.fill_rect(0, 0, w, h, 0x0f)
|
||||
fbuf.fill_rect(0, 0, w, h, 0x0F)
|
||||
printbuf()
|
||||
fbuf.fill_rect(0, 0, w, h, 0xf0)
|
||||
fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1)
|
||||
fbuf.fill_rect(0, 0, w, h, 0xF0)
|
||||
fbuf.fill_rect(1, 0, w // 2 + 1, 1, 0xF1)
|
||||
printbuf()
|
||||
fbuf.fill_rect(1, 0, w//2+1, 1, 0x10)
|
||||
fbuf.fill_rect(1, 0, w//2, 1, 0xf1)
|
||||
fbuf.fill_rect(1, 0, w // 2 + 1, 1, 0x10)
|
||||
fbuf.fill_rect(1, 0, w // 2, 1, 0xF1)
|
||||
printbuf()
|
||||
fbuf.fill_rect(1, 0, w//2, 1, 0x10)
|
||||
fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf)
|
||||
fbuf.fill_rect(1, 0, w // 2, 1, 0x10)
|
||||
fbuf.fill_rect(0, h - 4, w // 2 + 1, 4, 0xAF)
|
||||
printbuf()
|
||||
fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0)
|
||||
fbuf.fill_rect(0, h-4, w//2, 4, 0xaf)
|
||||
fbuf.fill_rect(0, h - 4, w // 2 + 1, 4, 0xB0)
|
||||
fbuf.fill_rect(0, h - 4, w // 2, 4, 0xAF)
|
||||
printbuf()
|
||||
fbuf.fill_rect(0, h-4, w//2, 4, 0xb0)
|
||||
fbuf.fill_rect(0, h - 4, w // 2, 4, 0xB0)
|
||||
|
@ -4,14 +4,16 @@ 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("%02x" % buf[(x + y * w)], end="")
|
||||
print()
|
||||
print("-->8--")
|
||||
|
||||
|
||||
w = 8
|
||||
h = 5
|
||||
buf = bytearray(w * h)
|
||||
@ -25,7 +27,7 @@ printbuf()
|
||||
fbuf.pixel(0, 0, 0x11)
|
||||
fbuf.pixel(w - 1, 0, 0x22)
|
||||
fbuf.pixel(0, h - 1, 0x33)
|
||||
fbuf.pixel(w - 1, h - 1, 0xff)
|
||||
fbuf.pixel(w - 1, h - 1, 0xFF)
|
||||
printbuf()
|
||||
|
||||
# get pixel
|
||||
|
@ -3,9 +3,10 @@
|
||||
try:
|
||||
import framebuf
|
||||
except ImportError:
|
||||
print('SKIP')
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
class FB(framebuf.FrameBuffer):
|
||||
def __init__(self, n):
|
||||
self.n = n
|
||||
@ -14,6 +15,7 @@ class FB(framebuf.FrameBuffer):
|
||||
def foo(self):
|
||||
self.hline(0, 2, self.n, 0x0304)
|
||||
|
||||
|
||||
fb = FB(n=3)
|
||||
fb.pixel(0, 0, 0x0102)
|
||||
fb.foo()
|
||||
@ -31,12 +33,13 @@ print(bytes(fb2))
|
||||
class NotAFrameBuf:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
fb.blit(NotAFrameBuf(), 0, 0)
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
||||
try:
|
||||
fb.blit(None, 0, 0)
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
@ -10,7 +10,6 @@ except:
|
||||
|
||||
|
||||
class MyPin(machine.PinBase):
|
||||
|
||||
def __init__(self):
|
||||
print("__init__")
|
||||
self.v = False
|
||||
@ -21,6 +20,7 @@ class MyPin(machine.PinBase):
|
||||
self.v = not self.v
|
||||
return int(self.v)
|
||||
|
||||
|
||||
p = MyPin()
|
||||
|
||||
print(p.value())
|
||||
|
@ -11,7 +11,6 @@ except:
|
||||
|
||||
|
||||
class ConstPin(machine.PinBase):
|
||||
|
||||
def __init__(self, value):
|
||||
self.v = value
|
||||
|
||||
@ -23,7 +22,6 @@ class ConstPin(machine.PinBase):
|
||||
|
||||
|
||||
class TogglePin(machine.PinBase):
|
||||
|
||||
def __init__(self):
|
||||
self.v = 0
|
||||
|
||||
|
@ -11,6 +11,7 @@ except:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
class Pin(machine.PinBase):
|
||||
def __init__(self):
|
||||
self.v = 0
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
try:
|
||||
import utime, umachine as machine
|
||||
|
||||
machine.Timer
|
||||
except:
|
||||
print("SKIP")
|
||||
@ -27,11 +28,11 @@ t2.deinit()
|
||||
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'))
|
||||
t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot"))
|
||||
utime.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'))
|
||||
t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic"))
|
||||
utime.sleep_ms(14)
|
||||
t.deinit()
|
||||
|
@ -1,5 +1,6 @@
|
||||
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")
|
||||
|
@ -7,40 +7,40 @@ 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_base64(b'Zm9vYg=='))
|
||||
print(binascii.a2b_base64(b'Zm9vYmE='))
|
||||
print(binascii.a2b_base64(b'Zm9vYmFy'))
|
||||
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_base64(b"Zm9vYg=="))
|
||||
print(binascii.a2b_base64(b"Zm9vYmE="))
|
||||
print(binascii.a2b_base64(b"Zm9vYmFy"))
|
||||
|
||||
print(binascii.a2b_base64(b'AAECAwQFBgc='))
|
||||
print(binascii.a2b_base64(b'CAkKCwwNDg8='))
|
||||
print(binascii.a2b_base64(b'f4D/'))
|
||||
print(binascii.a2b_base64(b'f4D+')) # convert '+'
|
||||
print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk'))
|
||||
print(binascii.a2b_base64(b"AAECAwQFBgc="))
|
||||
print(binascii.a2b_base64(b"CAkKCwwNDg8="))
|
||||
print(binascii.a2b_base64(b"f4D/"))
|
||||
print(binascii.a2b_base64(b"f4D+")) # convert '+'
|
||||
print(binascii.a2b_base64(b"MTIzNEFCQ0RhYmNk"))
|
||||
|
||||
# Ignore invalid characters and pad sequences
|
||||
print(binascii.a2b_base64(b'Zm9v\n'))
|
||||
print(binascii.a2b_base64(b'Zm\x009v\n'))
|
||||
print(binascii.a2b_base64(b'Zm9v=='))
|
||||
print(binascii.a2b_base64(b'Zm9v==='))
|
||||
print(binascii.a2b_base64(b'Zm9v===YmFy'))
|
||||
print(binascii.a2b_base64(b"Zm9v\n"))
|
||||
print(binascii.a2b_base64(b"Zm\x009v\n"))
|
||||
print(binascii.a2b_base64(b"Zm9v=="))
|
||||
print(binascii.a2b_base64(b"Zm9v==="))
|
||||
print(binascii.a2b_base64(b"Zm9v===YmFy"))
|
||||
|
||||
try:
|
||||
print(binascii.a2b_base64(b'abc'))
|
||||
print(binascii.a2b_base64(b"abc"))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
print(binascii.a2b_base64(b'abcde='))
|
||||
print(binascii.a2b_base64(b"abcde="))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
print(binascii.a2b_base64(b'ab*d'))
|
||||
print(binascii.a2b_base64(b"ab*d"))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
try:
|
||||
print(binascii.a2b_base64(b'ab=cdef='))
|
||||
print(binascii.a2b_base64(b"ab=cdef="))
|
||||
except ValueError:
|
||||
print("ValueError")
|
||||
|
@ -7,16 +7,16 @@ 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'foob'))
|
||||
print(binascii.b2a_base64(b'fooba'))
|
||||
print(binascii.b2a_base64(b'foobar'))
|
||||
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"foob"))
|
||||
print(binascii.b2a_base64(b"fooba"))
|
||||
print(binascii.b2a_base64(b"foobar"))
|
||||
|
||||
print(binascii.b2a_base64(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
|
||||
print(binascii.b2a_base64(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
|
||||
print(binascii.b2a_base64(b'\x7f\x80\xff'))
|
||||
print(binascii.b2a_base64(b'1234ABCDabcd'))
|
||||
print(binascii.b2a_base64(b'\x00\x00>')) # convert into '+'
|
||||
print(binascii.b2a_base64(b"\x00\x01\x02\x03\x04\x05\x06\x07"))
|
||||
print(binascii.b2a_base64(b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"))
|
||||
print(binascii.b2a_base64(b"\x7f\x80\xff"))
|
||||
print(binascii.b2a_base64(b"1234ABCDabcd"))
|
||||
print(binascii.b2a_base64(b"\x00\x00>")) # convert into '+'
|
||||
|
@ -13,12 +13,12 @@ except AttributeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog')))
|
||||
print(hex(binascii.crc32(b'\x00' * 32)))
|
||||
print(hex(binascii.crc32(b'\xff' * 32)))
|
||||
print(hex(binascii.crc32(b"The quick brown fox jumps over the lazy dog")))
|
||||
print(hex(binascii.crc32(b"\x00" * 32)))
|
||||
print(hex(binascii.crc32(b"\xff" * 32)))
|
||||
print(hex(binascii.crc32(bytes(range(32)))))
|
||||
|
||||
print(hex(binascii.crc32(b' over the lazy dog', binascii.crc32(b'The quick brown fox jumps'))))
|
||||
print(hex(binascii.crc32(b'\x00' * 16, binascii.crc32(b'\x00' * 16))))
|
||||
print(hex(binascii.crc32(b'\xff' * 16, binascii.crc32(b'\xff' * 16))))
|
||||
print(hex(binascii.crc32(b" over the lazy dog", binascii.crc32(b"The quick brown fox jumps"))))
|
||||
print(hex(binascii.crc32(b"\x00" * 16, binascii.crc32(b"\x00" * 16))))
|
||||
print(hex(binascii.crc32(b"\xff" * 16, binascii.crc32(b"\xff" * 16))))
|
||||
print(hex(binascii.crc32(bytes(range(16, 32)), binascii.crc32(bytes(range(16))))))
|
||||
|
@ -7,7 +7,7 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
|
||||
print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
|
||||
print(binascii.hexlify(b'\x7f\x80\xff'))
|
||||
print(binascii.hexlify(b'1234ABCDabcd'))
|
||||
print(binascii.hexlify(b"\x00\x01\x02\x03\x04\x05\x06\x07"))
|
||||
print(binascii.hexlify(b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"))
|
||||
print(binascii.hexlify(b"\x7f\x80\xff"))
|
||||
print(binascii.hexlify(b"1234ABCDabcd"))
|
||||
|
@ -8,8 +8,8 @@ except ImportError:
|
||||
raise SystemExit
|
||||
|
||||
# two arguments supported in uPy but not CPython
|
||||
a = binascii.hexlify(b'123', ':')
|
||||
a = binascii.hexlify(b"123", ":")
|
||||
print(a)
|
||||
|
||||
# zero length buffer
|
||||
print(binascii.hexlify(b'', b':'))
|
||||
print(binascii.hexlify(b"", b":"))
|
||||
|
@ -7,17 +7,17 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(binascii.unhexlify(b'0001020304050607'))
|
||||
print(binascii.unhexlify(b'08090a0b0c0d0e0f'))
|
||||
print(binascii.unhexlify(b'7f80ff'))
|
||||
print(binascii.unhexlify(b'313233344142434461626364'))
|
||||
print(binascii.unhexlify(b"0001020304050607"))
|
||||
print(binascii.unhexlify(b"08090a0b0c0d0e0f"))
|
||||
print(binascii.unhexlify(b"7f80ff"))
|
||||
print(binascii.unhexlify(b"313233344142434461626364"))
|
||||
|
||||
try:
|
||||
a = binascii.unhexlify(b'0') # odd buffer length
|
||||
a = binascii.unhexlify(b"0") # odd buffer length
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
try:
|
||||
a = binascii.unhexlify(b'gg') # digit not hex
|
||||
a = binascii.unhexlify(b"gg") # digit not hex
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
@ -1,5 +1,6 @@
|
||||
try:
|
||||
from Crypto.Cipher import AES
|
||||
|
||||
aes = AES.new
|
||||
except ImportError:
|
||||
try:
|
||||
|
@ -10,7 +10,7 @@ def _new(k, ctr_initial):
|
||||
|
||||
|
||||
try:
|
||||
_new(b'x' * 16, b'x' * 16)
|
||||
_new(b"x" * 16, b"x" * 16)
|
||||
except ValueError as e:
|
||||
# is CTR support disabled?
|
||||
if e.args[0] == "mode":
|
||||
@ -19,9 +19,9 @@ except ValueError as e:
|
||||
raise e
|
||||
|
||||
crypto = _new(b"1234" * 4, b"5678" * 4)
|
||||
enc = crypto.encrypt(b'a')
|
||||
enc = crypto.encrypt(b"a")
|
||||
print(enc)
|
||||
enc += crypto.encrypt(b'b' * 1000)
|
||||
enc += crypto.encrypt(b"b" * 1000)
|
||||
print(enc)
|
||||
|
||||
crypto = _new(b"1234" * 4, b"5678" * 4)
|
||||
|
@ -1,5 +1,6 @@
|
||||
try:
|
||||
from Crypto.Cipher import AES
|
||||
|
||||
aes = AES.new
|
||||
except ImportError:
|
||||
try:
|
||||
|
@ -3,6 +3,7 @@
|
||||
# is optional).
|
||||
try:
|
||||
from Crypto.Cipher import AES
|
||||
|
||||
aes = AES.new
|
||||
except ImportError:
|
||||
try:
|
||||
|
@ -1,5 +1,6 @@
|
||||
try:
|
||||
from Crypto.Cipher import AES
|
||||
|
||||
aes = AES.new
|
||||
except ImportError:
|
||||
try:
|
||||
|
@ -1,5 +1,6 @@
|
||||
try:
|
||||
from Crypto.Cipher import AES
|
||||
|
||||
aes = AES.new
|
||||
except ImportError:
|
||||
try:
|
||||
|
@ -10,16 +10,16 @@ buf = b"12345678abcd"
|
||||
struct = uctypes.struct(
|
||||
uctypes.addressof(buf),
|
||||
{"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
|
||||
uctypes.LITTLE_ENDIAN
|
||||
uctypes.LITTLE_ENDIAN,
|
||||
)
|
||||
|
||||
struct.f32 = 0x7fffffff
|
||||
struct.f32 = 0x7FFFFFFF
|
||||
print(buf)
|
||||
|
||||
struct.f32 = 0x80000000
|
||||
print(buf)
|
||||
|
||||
struct.f32 = 0xff010203
|
||||
struct.f32 = 0xFF010203
|
||||
print(buf)
|
||||
|
||||
struct.f64 = 0x80000000
|
||||
@ -34,16 +34,16 @@ buf = b"12345678abcd"
|
||||
struct = uctypes.struct(
|
||||
uctypes.addressof(buf),
|
||||
{"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
|
||||
uctypes.BIG_ENDIAN
|
||||
uctypes.BIG_ENDIAN,
|
||||
)
|
||||
|
||||
struct.f32 = 0x7fffffff
|
||||
struct.f32 = 0x7FFFFFFF
|
||||
print(buf)
|
||||
|
||||
struct.f32 = 0x80000000
|
||||
print(buf)
|
||||
|
||||
struct.f32 = 0xff010203
|
||||
struct.f32 = 0xFF010203
|
||||
print(buf)
|
||||
|
||||
struct.f64 = 0x80000000
|
||||
|
@ -10,14 +10,12 @@ desc = {
|
||||
# arr2 is array at offset 0, size 2, of structures defined recursively
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
|
||||
# aligned
|
||||
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
|
||||
# unaligned
|
||||
"arr6": (uctypes.ARRAY | 1, uctypes.UINT32 | 1),
|
||||
|
||||
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
|
||||
"arr8": (uctypes.ARRAY | 1, 1, {"l": uctypes.UINT32 | 0})
|
||||
"arr8": (uctypes.ARRAY | 1, 1, {"l": uctypes.UINT32 | 0}),
|
||||
}
|
||||
|
||||
data = bytearray(5)
|
||||
@ -55,4 +53,3 @@ assert hex(S.arr6[0]) == "0xaabbccdd"
|
||||
|
||||
print(S.arr6[0] == S.arr8[0].l)
|
||||
assert S.arr6[0] == S.arr8[0].l
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
@ -15,16 +16,14 @@ desc = {
|
||||
# arr2 is array at offset 0, size 2, of structures defined recursively
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
|
||||
# aligned
|
||||
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
|
||||
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
|
||||
|
||||
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
|
||||
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
|
||||
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
|
||||
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
|
||||
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
|
||||
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64 | 1),
|
||||
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
@ -15,16 +16,14 @@ desc = {
|
||||
# arr2 is array at offset 0, size 2, of structures defined recursively
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
|
||||
# aligned
|
||||
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
|
||||
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
|
||||
|
||||
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
|
||||
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
|
||||
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
|
||||
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
|
||||
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
|
||||
"arr12": (uctypes.ARRAY | 0, uctypes.UINT64 | 1),
|
||||
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
data = bytearray(b'01234567')
|
||||
data = bytearray(b"01234567")
|
||||
|
||||
print(uctypes.bytes_at(uctypes.addressof(data), 4))
|
||||
print(uctypes.bytearray_at(uctypes.addressof(data), 4))
|
||||
|
@ -13,31 +13,31 @@ S = uctypes.struct(uctypes.addressof(data), {})
|
||||
try:
|
||||
del S[0]
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
||||
# list is an invalid descriptor
|
||||
S = uctypes.struct(uctypes.addressof(data), [])
|
||||
try:
|
||||
S.x
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
||||
# can't access attribute with invalid descriptor
|
||||
S = uctypes.struct(uctypes.addressof(data), {'x':[]})
|
||||
S = uctypes.struct(uctypes.addressof(data), {"x": []})
|
||||
try:
|
||||
S.x
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
||||
# can't assign to aggregate
|
||||
S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)})
|
||||
S = uctypes.struct(uctypes.addressof(data), {"x": (uctypes.ARRAY | 0, uctypes.INT8 | 2)})
|
||||
try:
|
||||
S.x = 1
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
||||
# unsupported unary op
|
||||
try:
|
||||
hash(S)
|
||||
except TypeError:
|
||||
print('TypeError')
|
||||
print("TypeError")
|
||||
|
@ -6,20 +6,15 @@ except ImportError:
|
||||
|
||||
desc = {
|
||||
"s0": uctypes.UINT16 | 0,
|
||||
"sub": (0, {
|
||||
"b0": uctypes.UINT8 | 0,
|
||||
"b1": uctypes.UINT8 | 1,
|
||||
}),
|
||||
"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": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
|
||||
"bitf1": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
|
||||
|
||||
"bf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf1": uctypes.BFUINT16 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf2": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf3": uctypes.BFUINT16 | 0 | 12 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
|
||||
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
|
||||
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
|
||||
}
|
||||
@ -28,10 +23,10 @@ data = bytearray(b"01")
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
|
||||
|
||||
#print(S)
|
||||
# print(S)
|
||||
print(hex(S.s0))
|
||||
assert hex(S.s0) == "0x3130"
|
||||
#print(S.sub.b0)
|
||||
# print(S.sub.b0)
|
||||
print(S.sub.b0, S.sub.b1)
|
||||
assert S.sub.b0, S.sub.b1 == (0x30, 0x31)
|
||||
|
||||
@ -73,7 +68,7 @@ assert bytes(data) == b"2Q"
|
||||
|
||||
desc2 = {
|
||||
"bf8": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN
|
||||
"bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
}
|
||||
|
||||
data2 = bytearray(b"0123")
|
||||
|
@ -15,10 +15,10 @@ data = bytearray(10)
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
|
||||
|
||||
S.f32 = 12.34
|
||||
print('%.4f' % S.f32)
|
||||
print("%.4f" % S.f32)
|
||||
|
||||
S.f64 = 12.34
|
||||
print('%.4f' % S.f64)
|
||||
print("%.4f" % S.f64)
|
||||
|
||||
S.uf64 = 12.34
|
||||
print('%.4f' % S.uf64)
|
||||
print("%.4f" % S.uf64)
|
||||
|
@ -14,7 +14,7 @@ data = bytearray(8)
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
|
||||
|
||||
S.f32 = 12.34
|
||||
print('%.4f' % S.f32)
|
||||
print("%.4f" % S.f32)
|
||||
|
||||
S.f64 = 12.34
|
||||
print('%.4f' % S.f64)
|
||||
print("%.4f" % S.f64)
|
||||
|
@ -2,6 +2,7 @@
|
||||
# Codepaths for packed vs native structures are different. This test only works
|
||||
# on little-endian machine (no matter if 32 or 64 bit).
|
||||
import sys
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
@ -15,20 +16,15 @@ if sys.byteorder != "little":
|
||||
|
||||
desc = {
|
||||
"s0": uctypes.UINT16 | 0,
|
||||
"sub": (0, {
|
||||
"b0": uctypes.UINT8 | 0,
|
||||
"b1": uctypes.UINT8 | 1,
|
||||
}),
|
||||
"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": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
|
||||
"bitf1": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
|
||||
|
||||
"bf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf1": uctypes.BFUINT16 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf2": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf3": uctypes.BFUINT16 | 0 | 12 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
|
||||
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
|
||||
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
|
||||
}
|
||||
@ -37,10 +33,10 @@ data = bytearray(b"01")
|
||||
|
||||
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
|
||||
|
||||
#print(S)
|
||||
# print(S)
|
||||
print(hex(S.s0))
|
||||
assert hex(S.s0) == "0x3130"
|
||||
#print(S.sub.b0)
|
||||
# print(S.sub.b0)
|
||||
print(S.sub.b0, S.sub.b1)
|
||||
assert S.sub.b0, S.sub.b1 == (0x30, 0x31)
|
||||
|
||||
@ -81,7 +77,7 @@ assert bytes(data) == b"2Q"
|
||||
|
||||
desc2 = {
|
||||
"bf8": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN
|
||||
"bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
}
|
||||
|
||||
data2 = bytearray(b"0123")
|
||||
|
@ -16,10 +16,10 @@ desc2 = [(uctypes.ARRAY | 0, uctypes.UINT8 | 1)]
|
||||
S2 = uctypes.struct(0, desc2)
|
||||
print(S2)
|
||||
|
||||
desc3 = ((uctypes.ARRAY | 0, uctypes.UINT8 | 1))
|
||||
desc3 = (uctypes.ARRAY | 0, uctypes.UINT8 | 1)
|
||||
S3 = uctypes.struct(0, desc3)
|
||||
print(S3)
|
||||
|
||||
desc4 = ((uctypes.PTR | 0, uctypes.UINT8 | 1))
|
||||
desc4 = (uctypes.PTR | 0, uctypes.UINT8 | 1)
|
||||
S4 = uctypes.struct(0, desc4)
|
||||
print(S4)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
@ -32,6 +33,6 @@ assert S.ptr[1] == ord("1")
|
||||
print(hex(S.ptr16[0]))
|
||||
assert hex(S.ptr16[0]) == "0x3130"
|
||||
print(S.ptr2[0].b, S.ptr2[1].b)
|
||||
print (S.ptr2[0].b, S.ptr2[1].b)
|
||||
print(S.ptr2[0].b, S.ptr2[1].b)
|
||||
print(hex(S.ptr16[0]))
|
||||
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
|
||||
try:
|
||||
import uctypes
|
||||
except ImportError:
|
||||
@ -30,6 +31,6 @@ assert S.ptr[1] == ord("1")
|
||||
print(hex(S.ptr16[0]))
|
||||
assert hex(S.ptr16[0]) == "0x3130"
|
||||
print(S.ptr2[0].b, S.ptr2[1].b)
|
||||
print (S.ptr2[0].b, S.ptr2[1].b)
|
||||
print(S.ptr2[0].b, S.ptr2[1].b)
|
||||
print(hex(S.ptr16[0]))
|
||||
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
|
||||
|
@ -11,10 +11,13 @@ desc = {
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
"arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1}),
|
||||
"sub": (0, {
|
||||
'b1': uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
'b2': uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
}),
|
||||
"sub": (
|
||||
0,
|
||||
{
|
||||
"b1": uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"b2": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
data = bytearray(b"01234567")
|
||||
|
@ -4,5 +4,5 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(uctypes.sizeof({'f':uctypes.FLOAT32}))
|
||||
print(uctypes.sizeof({'f':uctypes.FLOAT64}))
|
||||
print(uctypes.sizeof({"f": uctypes.FLOAT32}))
|
||||
print(uctypes.sizeof({"f": uctypes.FLOAT64}))
|
||||
|
@ -28,10 +28,7 @@ S5 = {
|
||||
"b": uctypes.UINT32 | 4,
|
||||
"c": uctypes.UINT8 | 8,
|
||||
"d": uctypes.UINT32 | 0,
|
||||
"sub": (4, {
|
||||
"b0": uctypes.UINT8 | 0,
|
||||
"b1": uctypes.UINT8 | 1,
|
||||
}),
|
||||
"sub": (4, {"b0": uctypes.UINT8 | 0, "b1": uctypes.UINT8 | 1,}),
|
||||
}
|
||||
|
||||
assert uctypes.sizeof(S5) == 12
|
||||
|
@ -5,18 +5,23 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
desc = OrderedDict({
|
||||
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, of structures defined recursively
|
||||
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
|
||||
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
|
||||
"arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1}),
|
||||
"sub": (0, {
|
||||
'b1': uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
'b2': uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
}),
|
||||
})
|
||||
"sub": (
|
||||
0,
|
||||
{
|
||||
"b1": uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
"b2": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
|
||||
},
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
data = bytearray(b"01234567")
|
||||
|
||||
|
@ -16,6 +16,6 @@ except AttributeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
md5 = hashlib.md5(b'hello')
|
||||
md5.update(b'world')
|
||||
md5 = hashlib.md5(b"hello")
|
||||
md5.update(b"world")
|
||||
print(md5.digest())
|
||||
|
@ -16,6 +16,6 @@ except AttributeError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
sha1 = hashlib.sha1(b'hello')
|
||||
sha1.update(b'world')
|
||||
sha1 = hashlib.sha1(b"hello")
|
||||
sha1.update(b"world")
|
||||
print(sha1.digest())
|
||||
|
@ -27,12 +27,12 @@ print(hashlib.sha256(b"\xff" * 64).digest())
|
||||
print(hashlib.sha256(b"\xff" * 56).digest())
|
||||
|
||||
# TODO: running .digest() several times in row is not supported()
|
||||
#h = hashlib.sha256(b'123')
|
||||
#print(h.digest())
|
||||
#print(h.digest())
|
||||
# h = hashlib.sha256(b'123')
|
||||
# print(h.digest())
|
||||
# print(h.digest())
|
||||
|
||||
# TODO: partial digests are not supported
|
||||
#h = hashlib.sha256(b'123')
|
||||
#print(h.digest())
|
||||
#h.update(b'456')
|
||||
#print(h.digest())
|
||||
# h = hashlib.sha256(b'123')
|
||||
# print(h.digest())
|
||||
# h.update(b'456')
|
||||
# print(h.digest())
|
||||
|
@ -17,11 +17,13 @@ try:
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
|
||||
def pop_and_print(h):
|
||||
l = []
|
||||
while h:
|
||||
l.append(str(heapq.heappop(h)))
|
||||
print(' '.join(l))
|
||||
print(" ".join(l))
|
||||
|
||||
|
||||
h = []
|
||||
heapq.heappush(h, 3)
|
||||
|
@ -21,10 +21,10 @@ print(s.getvalue())
|
||||
try:
|
||||
json.dump(123, 1)
|
||||
except (AttributeError, OSError): # CPython and uPy have different errors
|
||||
print('Exception')
|
||||
print("Exception")
|
||||
|
||||
# dump to an object not allowed
|
||||
try:
|
||||
json.dump(123, {})
|
||||
except (AttributeError, OSError): # CPython and uPy have different errors
|
||||
print('Exception')
|
||||
print("Exception")
|
||||
|
@ -7,22 +7,23 @@ except ImportError:
|
||||
try:
|
||||
import io, json
|
||||
except ImportError:
|
||||
print('SKIP')
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
if not hasattr(io, 'IOBase'):
|
||||
print('SKIP')
|
||||
if not hasattr(io, "IOBase"):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
# a user stream that only has the write method
|
||||
class S(io.IOBase):
|
||||
def __init__(self):
|
||||
self.buf = ''
|
||||
self.buf = ""
|
||||
|
||||
def write(self, buf):
|
||||
if type(buf) == bytearray:
|
||||
# uPy passes a bytearray, CPython passes a str
|
||||
buf = str(buf, 'ascii')
|
||||
buf = str(buf, "ascii")
|
||||
self.buf += buf
|
||||
return len(buf)
|
||||
|
||||
|
@ -11,8 +11,8 @@ 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("abc"))
|
||||
print(json.dumps("\x00\x01\x7e"))
|
||||
print(json.dumps([]))
|
||||
print(json.dumps([1]))
|
||||
print(json.dumps([1, 2]))
|
||||
@ -22,10 +22,10 @@ print(json.dumps((1,)))
|
||||
print(json.dumps((1, 2)))
|
||||
print(json.dumps((1, (2, 3))))
|
||||
print(json.dumps({}))
|
||||
print(json.dumps({"a":1}))
|
||||
print(json.dumps({"a":(2,[3,None])}))
|
||||
print(json.dumps({"a": 1}))
|
||||
print(json.dumps({"a": (2, [3, None])}))
|
||||
print(json.dumps('"quoted"'))
|
||||
print(json.dumps('space\n\r\tspace'))
|
||||
print(json.dumps("space\n\r\tspace"))
|
||||
print(json.dumps({None: -1}))
|
||||
print(json.dumps({False: 0}))
|
||||
print(json.dumps({True: 1}))
|
||||
|
@ -6,4 +6,4 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(ujson.dumps(b'1234'))
|
||||
print(ujson.dumps(b"1234"))
|
||||
|
@ -8,4 +8,4 @@ except ImportError:
|
||||
raise SystemExit
|
||||
|
||||
print(json.dumps(1.2))
|
||||
print(json.dumps({1.5: 'hi'}))
|
||||
print(json.dumps({1.5: "hi"}))
|
||||
|
@ -9,7 +9,7 @@ except:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(json.load(StringIO('null')))
|
||||
print(json.load(StringIO("null")))
|
||||
print(json.load(StringIO('"abc\\u0064e"')))
|
||||
print(json.load(StringIO('[false, true, 1, -2]')))
|
||||
print(json.load(StringIO("[false, true, 1, -2]")))
|
||||
print(json.load(StringIO('{"a":true}')))
|
||||
|
@ -7,23 +7,25 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
def my_print(o):
|
||||
if isinstance(o, dict):
|
||||
print('sorted dict', sorted(o.items()))
|
||||
print("sorted dict", sorted(o.items()))
|
||||
else:
|
||||
print(o)
|
||||
|
||||
my_print(json.loads('null'))
|
||||
my_print(json.loads('false'))
|
||||
my_print(json.loads('true'))
|
||||
my_print(json.loads('1'))
|
||||
my_print(json.loads('-2'))
|
||||
|
||||
my_print(json.loads("null"))
|
||||
my_print(json.loads("false"))
|
||||
my_print(json.loads("true"))
|
||||
my_print(json.loads("1"))
|
||||
my_print(json.loads("-2"))
|
||||
my_print(json.loads('"abc\\u0064e"'))
|
||||
my_print(json.loads('[]'))
|
||||
my_print(json.loads('[null]'))
|
||||
my_print(json.loads('[null,false,true]'))
|
||||
my_print(json.loads(' [ null , false , true ] '))
|
||||
my_print(json.loads('{}'))
|
||||
my_print(json.loads("[]"))
|
||||
my_print(json.loads("[null]"))
|
||||
my_print(json.loads("[null,false,true]"))
|
||||
my_print(json.loads(" [ null , false , true ] "))
|
||||
my_print(json.loads("{}"))
|
||||
my_print(json.loads('{"a":true}'))
|
||||
my_print(json.loads('{"a":null, "b":false, "c":true}'))
|
||||
my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}'))
|
||||
@ -39,36 +41,36 @@ my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}')
|
||||
|
||||
# loading nothing should raise exception
|
||||
try:
|
||||
json.loads('')
|
||||
json.loads("")
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# string which is not closed
|
||||
try:
|
||||
my_print(json.loads('"abc'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# unaccompanied closing brace
|
||||
try:
|
||||
my_print(json.loads(']'))
|
||||
my_print(json.loads("]"))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# unspecified object type
|
||||
try:
|
||||
my_print(json.loads('a'))
|
||||
my_print(json.loads("a"))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# bad property name
|
||||
try:
|
||||
my_print(json.loads('{{}:"abc"}'))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# unexpected characters after white space
|
||||
try:
|
||||
my_print(json.loads('[null] a'))
|
||||
my_print(json.loads("[null] a"))
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
@ -9,5 +9,5 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print(json.loads(b'[1,2]'))
|
||||
print(json.loads(bytearray(b'[null]')))
|
||||
print(json.loads(b"[1,2]"))
|
||||
print(json.loads(bytearray(b"[null]")))
|
||||
|
@ -7,12 +7,14 @@ 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.loads('-2e+3'))
|
||||
my_print(json.loads('-2e-3'))
|
||||
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.loads("-2e+3"))
|
||||
my_print(json.loads("-2e-3"))
|
||||
|
@ -26,4 +26,4 @@ print(random.getrandbits(16) == r)
|
||||
try:
|
||||
random.getrandbits(0)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
@ -10,10 +10,10 @@ except ImportError:
|
||||
try:
|
||||
random.randint
|
||||
except AttributeError:
|
||||
print('SKIP')
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print('randrange')
|
||||
print("randrange")
|
||||
for i in range(50):
|
||||
assert 0 <= random.randrange(4) < 4
|
||||
assert 2 <= random.randrange(2, 6) < 6
|
||||
@ -25,27 +25,27 @@ for i in range(50):
|
||||
try:
|
||||
random.randrange(0)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# empty range
|
||||
try:
|
||||
random.randrange(2, 1)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# zero step
|
||||
try:
|
||||
random.randrange(2, 1, 0)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
# empty range
|
||||
try:
|
||||
random.randrange(2, 1, 1)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
print('randint')
|
||||
print("randint")
|
||||
for i in range(50):
|
||||
assert 0 <= random.randint(0, 4) <= 4
|
||||
assert 2 <= random.randint(2, 6) <= 6
|
||||
@ -55,9 +55,9 @@ for i in range(50):
|
||||
try:
|
||||
random.randint(2, 1)
|
||||
except ValueError:
|
||||
print('ValueError')
|
||||
print("ValueError")
|
||||
|
||||
print('choice')
|
||||
print("choice")
|
||||
lst = [1, 2, 5, 6]
|
||||
for i in range(50):
|
||||
assert random.choice(lst) in lst
|
||||
@ -66,4 +66,4 @@ for i in range(50):
|
||||
try:
|
||||
random.choice([])
|
||||
except IndexError:
|
||||
print('IndexError')
|
||||
print("IndexError")
|
||||
|
@ -10,14 +10,14 @@ except ImportError:
|
||||
try:
|
||||
random.randint
|
||||
except AttributeError:
|
||||
print('SKIP')
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
print('random')
|
||||
print("random")
|
||||
for i in range(50):
|
||||
assert 0 <= random.random() < 1
|
||||
|
||||
print('uniform')
|
||||
print("uniform")
|
||||
for i in range(50):
|
||||
assert 0 <= random.uniform(0, 4) <= 4
|
||||
assert 2 <= random.uniform(2, 6) <= 6
|
||||
|
@ -70,11 +70,16 @@ print(m.group(0))
|
||||
m = re.search("w.r", "hello world")
|
||||
print(m.group(0))
|
||||
|
||||
m = re.match('a+?', 'ab'); print(m.group(0))
|
||||
m = re.match('a*?', 'ab'); print(m.group(0))
|
||||
m = re.match('^ab$', 'ab'); print(m.group(0))
|
||||
m = re.match('a|b', 'b'); print(m.group(0))
|
||||
m = re.match('a|b|c', 'c'); print(m.group(0))
|
||||
m = re.match("a+?", "ab")
|
||||
print(m.group(0))
|
||||
m = re.match("a*?", "ab")
|
||||
print(m.group(0))
|
||||
m = re.match("^ab$", "ab")
|
||||
print(m.group(0))
|
||||
m = re.match("a|b", "b")
|
||||
print(m.group(0))
|
||||
m = re.match("a|b|c", "c")
|
||||
print(m.group(0))
|
||||
|
||||
# Case where anchors fail to match
|
||||
r = re.compile("^b|b$")
|
||||
@ -87,24 +92,36 @@ except:
|
||||
print("Caught invalid regex")
|
||||
|
||||
# bytes objects
|
||||
m = re.match(rb'a+?', b'ab'); print(m.group(0))
|
||||
m = re.match(rb"a+?", b"ab")
|
||||
print(m.group(0))
|
||||
print("===")
|
||||
|
||||
# escaping
|
||||
m = re.match(r'a\.c', 'a.c'); print(m.group(0) if m else '')
|
||||
m = re.match(r'a\.b', 'abc'); print(m is None)
|
||||
m = re.match(r'a\.b', 'a\\bc'); print(m is None)
|
||||
m = re.match(r'[a\-z]', 'abc'); print(m.group(0))
|
||||
m = re.match(r'[.\]]*', '.].]a'); print(m.group(0))
|
||||
m = re.match(r'[.\]+]*', '.]+.]a'); print(m.group(0))
|
||||
m = re.match(r'[a-f0-9x\-yz]*', 'abxcd1-23'); print(m.group(0))
|
||||
m = re.match(r'[a\\b]*', 'a\\aa\\bb\\bbab'); print(m.group(0))
|
||||
m = re.search(r'[a\-z]', '-'); print(m.group(0))
|
||||
m = re.search(r'[a\-z]', 'f'); print(m is None)
|
||||
m = re.search(r'[a\]z]', 'a'); print(m.group(0))
|
||||
print(re.compile(r'[-a]').split('foo-bar'))
|
||||
print(re.compile(r'[a-]').split('foo-bar'))
|
||||
print(re.compile(r'[ax\-]').split('foo-bar'))
|
||||
print(re.compile(r'[a\-x]').split('foo-bar'))
|
||||
print(re.compile(r'[\-ax]').split('foo-bar'))
|
||||
m = re.match(r"a\.c", "a.c")
|
||||
print(m.group(0) if m else "")
|
||||
m = re.match(r"a\.b", "abc")
|
||||
print(m is None)
|
||||
m = re.match(r"a\.b", "a\\bc")
|
||||
print(m is None)
|
||||
m = re.match(r"[a\-z]", "abc")
|
||||
print(m.group(0))
|
||||
m = re.match(r"[.\]]*", ".].]a")
|
||||
print(m.group(0))
|
||||
m = re.match(r"[.\]+]*", ".]+.]a")
|
||||
print(m.group(0))
|
||||
m = re.match(r"[a-f0-9x\-yz]*", "abxcd1-23")
|
||||
print(m.group(0))
|
||||
m = re.match(r"[a\\b]*", "a\\aa\\bb\\bbab")
|
||||
print(m.group(0))
|
||||
m = re.search(r"[a\-z]", "-")
|
||||
print(m.group(0))
|
||||
m = re.search(r"[a\-z]", "f")
|
||||
print(m is None)
|
||||
m = re.search(r"[a\]z]", "a")
|
||||
print(m.group(0))
|
||||
print(re.compile(r"[-a]").split("foo-bar"))
|
||||
print(re.compile(r"[a-]").split("foo-bar"))
|
||||
print(re.compile(r"[ax\-]").split("foo-bar"))
|
||||
print(re.compile(r"[a\-x]").split("foo-bar"))
|
||||
print(re.compile(r"[\-ax]").split("foo-bar"))
|
||||
print("===")
|
||||
|
@ -1,9 +1,10 @@
|
||||
# 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)
|
||||
ure.compile("^a|b[0-9]\w$", ure.DEBUG)
|
||||
|
@ -9,6 +9,7 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
def test_re(r):
|
||||
try:
|
||||
re.compile(r)
|
||||
@ -16,11 +17,12 @@ def test_re(r):
|
||||
except: # uPy and CPy use different errors, so just ignore the type
|
||||
print("Error")
|
||||
|
||||
test_re(r'?')
|
||||
test_re(r'*')
|
||||
test_re(r'+')
|
||||
test_re(r')')
|
||||
test_re(r'[')
|
||||
test_re(r'([')
|
||||
test_re(r'([)')
|
||||
test_re(r'[a\]')
|
||||
|
||||
test_re(r"?")
|
||||
test_re(r"*")
|
||||
test_re(r"+")
|
||||
test_re(r")")
|
||||
test_re(r"[")
|
||||
test_re(r"([")
|
||||
test_re(r"([)")
|
||||
test_re(r"[a\]")
|
||||
|
@ -9,8 +9,9 @@ except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
def print_groups(match):
|
||||
print('----')
|
||||
print("----")
|
||||
try:
|
||||
i = 0
|
||||
while True:
|
||||
@ -19,14 +20,15 @@ def print_groups(match):
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
|
||||
|
||||
m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "1234hello567")
|
||||
print_groups(m)
|
||||
|
||||
m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
|
||||
m = re.match(r"([0-9]*)(([a-z]*)([0-9]*))", "1234hello567")
|
||||
print_groups(m)
|
||||
|
||||
# optional group that matches
|
||||
print_groups(re.match(r'(a)?b(c)', 'abc'))
|
||||
print_groups(re.match(r"(a)?b(c)", "abc"))
|
||||
|
||||
# optional group that doesn't match
|
||||
print_groups(re.match(r'(a)?b(c)', 'bc'))
|
||||
print_groups(re.match(r"(a)?b(c)", "bc"))
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user