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
# Test calling non-special method inherited from native type class mylist(list): pass l = mylist([1, 2, 3]) print(l) print([e for e in l]) class mylist2(list): def __iter__(self): return iter([10, 20, 30]) l = mylist2([1, 2, 3]) print(l) print([e for e in l])
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_specmeth.py
Python
apache-2.0
282
# Test subclassing built-in str class S(str): pass s = S('hello') print(s == 'hello') print('hello' == s) print(s == 'Hello') print('Hello' == s)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_str.py
Python
apache-2.0
152
# test syntax errors try: exec except NameError: print("SKIP") raise SystemExit def test_syntax(code): try: exec(code) print("no SyntaxError") except IndentationError: print("IndentationError") except SyntaxError: print("SyntaxError") # non-newline after line-c...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/syntaxerror.py
Python
apache-2.0
2,900
# With MICROPY_CPYTHON_COMPAT, the "return" statement can only appear in a # function. # Otherwise (in minimal builds), it ends execution of a module/class. try: exec except NameError: print("SKIP") raise SystemExit try: exec('return; print("this should not be executed.")') # if we get here then M...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/syntaxerror_return.py
Python
apache-2.0
472
# test sys module try: import usys as sys except ImportError: import sys print(sys.__name__) print(type(sys.path)) print(type(sys.argv)) print(sys.byteorder in ('little', 'big')) try: print(sys.maxsize > 100) except AttributeError: # Effectively skip subtests print(True) try: print(sys.imple...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/sys1.py
Python
apache-2.0
570
# test sys module's exit function try: import usys as sys except ImportError: import sys try: sys.exit except AttributeError: print("SKIP") raise SystemExit try: raise SystemExit except SystemExit as e: print("SystemExit", e.args) try: sys.exit() except SystemExit as e: print("Sy...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/sys_exit.py
Python
apache-2.0
418
# test sys.getsizeof() function try: import usys as sys except ImportError: import sys try: sys.getsizeof except AttributeError: print('SKIP') raise SystemExit print(sys.getsizeof([1, 2]) >= 2) print(sys.getsizeof({1: 2}) >= 2) class A: pass print(sys.getsizeof(A()) > 0) # Only test deque if...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/sys_getsizeof.py
Python
apache-2.0
444
# Test true-ish value handling if not False: print("False") if not None: print("None") if not 0: print("0") if not "": print("Empty string") if "foo": print("Non-empty string") if not (): print("Empty tuple") if ("",): print("Non-empty tuple") if not []: print("Empty list") if [0]:...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/true_value.py
Python
apache-2.0
423
# basic exceptions x = 1 try: x.a() except: print(x) try: raise IndexError except IndexError: print("caught")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try1.py
Python
apache-2.0
127
# nested try's try: print("try 1") try: print("try 2") foo() except: print("except 2") bar() except: print("except 1") try: print("try 1") try: print("try 2") foo() except TypeError: print("except 2") bar() except NameError: print...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try2.py
Python
apache-2.0
838
# nested exceptions def f(): try: foo() except: print("except 1") try: baz() except: print("except 2") bar() try: f() except: print("f except")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try3.py
Python
apache-2.0
226
# triple nested exceptions def f(): try: foo() except: print("except 1") try: bar() except: print("except 2") try: baz() except: print("except 3") bak() try: f() except: print("f...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try4.py
Python
apache-2.0
330
try: raise ValueError(534) except ValueError as e: print(type(e), e.args) # Var bound in except block is automatically deleted try: e except NameError: print("NameError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_as_var.py
Python
apache-2.0
188
# test continue within exception handler def f(): lst = [1, 2, 3] for x in lst: print('a', x) try: if x == 2: raise Exception except Exception: continue print('b', x) f()
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_continue.py
Python
apache-2.0
252
# test try-else statement # base case try: print(1) except: print(2) else: print(3) # basic case that should skip else try: print(1) raise Exception except: print(2) else: print(3) # uncaught exception should skip else try: try: print(1) raise ValueError except Typ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_else.py
Python
apache-2.0
1,052
# test try-else-finally statement # base case try: print(1) except: print(2) else: print(3) finally: print(4) # basic case that should skip else try: print(1) raise Exception except: print(2) else: print(3) finally: print(4) # uncaught exception should skip else try: try: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_else_finally.py
Python
apache-2.0
1,290
# test bad exception match try: try: a except 1: pass except TypeError: print("TypeError") try: try: a except (1,): pass except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_error.py
Python
apache-2.0
216
# test deep unwind via break from nested try-except (22 of them) while True: print(1) try: try: try: try: try: try: try: try: try: try: try: try: try: try: try: try: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_except_break.py
Python
apache-2.0
1,366
print("noexc-finally") try: print("try") finally: print("finally") print("noexc-finally-finally") try: print("try1") try: print("try2") finally: print("finally2") finally: print("finally1") print() print("noexc-finally-func-finally") def func2(): try: print("try2") ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally1.py
Python
apache-2.0
1,587
# check that the Python stack does not overflow when the finally # block itself uses more stack than the rest of the function def f1(a, b): pass def test1(): val = 1 try: raise ValueError() finally: f1(2, 2) # use some stack print(val) # check that the local variable is the same ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally2.py
Python
apache-2.0
685
# test break within (nested) finally # basic case with break in finally def f(): for _ in range(2): print(1) try: pass finally: print(2) break print(3) print(4) print(5) f() # where the finally swallows an exception def f(): l...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_break.py
Python
apache-2.0
2,065
def foo(x): for i in range(x): for j in range(x): try: print(x, i, j, 1) finally: try: try: print(x, i, j, 2) finally: try: 1 / 0 ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_break2.py
Python
apache-2.0
530
def foo(x): for i in range(x): try: pass finally: try: try: print(x, i) finally: try: 1 / 0 finally: return 42 finally: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_continue.py
Python
apache-2.0
389
# Test various loop types, some may be implemented/optimized differently while True: try: break finally: print('finally 1') for i in [1, 5, 10]: try: continue finally: print('finally 2') for i in range(3): try: continue finally: print('finally 3...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_loops.py
Python
apache-2.0
1,447
def func1(): try: return "it worked" finally: print("finally 1") print(func1()) def func2(): try: return "it worked" finally: print("finally 2") def func3(): try: s = func2() return s + ", did this work?" finally: print("finally 3") pr...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_return.py
Python
apache-2.0
1,471
# test 'return' within the finally block # it should swallow the exception # simple case def f(): try: raise ValueError() finally: print('finally') return 0 print('got here') print(f()) # nested, return in outer def f(): try: try: raise ValueError fi...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_return2.py
Python
apache-2.0
1,834
# test 'return' within the finally block, with nested finally's # only inactive finally's should be executed, and only once # basic nested finally's, the print should only be executed once def f(): try: raise TypeError finally: print(1) try: raise ValueError finally:...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_return3.py
Python
apache-2.0
2,049
# test try-finally with return, where unwinding return has to go through # another try-finally which may affect the behaviour of the return # case where a simple try-finally executes during an unwinding return def f(x): try: try: if x: return 42 finally: try:...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_return4.py
Python
apache-2.0
1,761
def foo(x): for i in range(x): try: pass finally: try: try: print(x, i) finally: try: 1 / 0 finally: return 42 finally: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_finally_return5.py
Python
apache-2.0
388
# Reraising last exception with raise w/o args def f(): try: raise ValueError("val", 3) except: raise try: f() except ValueError as e: print(repr(e)) # Can reraise only in except block try: raise except RuntimeError: print("RuntimeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_reraise.py
Python
apache-2.0
283
# Reraise not the latest occurred exception def f(): try: raise ValueError("val", 3) except: try: print(1) raise TypeError except: print(2) try: print(3) try: print(4) ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_reraise2.py
Python
apache-2.0
746
# test use of return with try-except def f(): try: print(1) return except: print(2) print(3) f() def f(l, i): try: return l[i] except IndexError: print('IndexError') return -1 print(f([1], 0)) print(f([], 0))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/try_return.py
Python
apache-2.0
280
# basic tuple functionality x = (1, 2, 3 * 4) print(x) try: x[0] = 4 except TypeError: print("TypeError") print(x) try: x.append(5) except AttributeError: print("AttributeError") print(x + (10, 100, 10000)) # inplace add operator x += (10, 11, 12) print(x) # construction of tuple from large iterator ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/tuple1.py
Python
apache-2.0
560
print(() == ()) print(() > ()) print(() < ()) print(() == (1,)) print((1,) == ()) print(() > (1,)) print((1,) > ()) print(() < (1,)) print((1,) < ()) print(() >= (1,)) print((1,) >= ()) print(() <= (1,)) print((1,) <= ()) print((1,) == (1,)) print((1,) != (1,)) print((1,) == (2,)) print((1,) == (1, 0,)) print((1,) > ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/tuple_compare.py
Python
apache-2.0
1,152
a = (1, 2, 3) a = a + a + a b = (0, 0, a, 0, a, 0) print(a.count(2)) print(b.count(a))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/tuple_count.py
Python
apache-2.0
87
a = (1, 2, 3) print(a.index(1)) print(a.index(2)) print(a.index(3)) print(a.index(3, 2)) try: print(a.index(3, 2, 2)) except ValueError: print("Raised ValueError") else: print("Did not raise ValueError") a = a + a b = (0, 0, a) print(a.index(2)) print(b.index(a)) print(a.index(2, 2)) try: a.index(2, 2...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/tuple_index.py
Python
apache-2.0
419
# basic multiplication print((0,) * 5) # check negative, 0, positive; lhs and rhs multiplication for i in (-4, -2, 0, 2, 4): print(i * (1, 2)) print((1, 2) * i) # check that we don't modify existing tuple a = (1, 2, 3) c = a * 3 print(a, c) # inplace multiplication a = (1, 2) a *= 2 print(a) # unsupported t...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/tuple_mult.py
Python
apache-2.0
391
# tuple slicing x = (1, 2, 3 * 4) print(x[1:]) print(x[:-1]) print(x[2:3])
YifuLiu/AliOS-Things
components/py_engine/tests/basics/tuple_slice.py
Python
apache-2.0
77
# basic types # similar test for set type is done in set_type.py print(bool) print(int) print(tuple) print(list) print(dict) print(type(bool()) == bool) print(type(int()) == int) print(type(tuple()) == tuple) print(type(list()) == list) print(type(dict()) == dict) print(type(False) == bool) print(type(0) == int) pri...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/types1.py
Python
apache-2.0
460
# Types are hashable print(hash(type) != 0) print(hash(int) != 0) print(hash(list) != 0) class Foo: pass print(hash(Foo) != 0) print(int == int) print(int != list) d = {} d[int] = list d[list] = int print(len(d))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/types2.py
Python
apache-2.0
215
x = 1 print(+x) print(-x) print(~x) print(not None) print(not False) print(not True) print(not 0) print(not 1) print(not -1) print(not ()) print(not (1,)) print(not []) print(not [1,]) print(not {}) print(not {1:1}) # check user instance class A: pass print(not A()) # check user instances derived from builtins class...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/unary_op.py
Python
apache-2.0
557
# locals referenced before assignment def f1(): print(x) x = 1 def f2(): for i in range(0): print(i) print(i) def check(f): try: f() except NameError: print("NameError") check(f1) check(f2)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/unboundlocal.py
Python
apache-2.0
242
# unpack sequences a, = 1, ; print(a) a, b = 2, 3 ; print(a, b) a, b, c = 1, 2, 3; print(a, b, c) a, = range(1); print(a) a, b = range(2); print(a, b) a, b, c = range(3); print(a, b, c) (a) = range(1); print(a) (a,) = range(1); print(a) (a, b) = range(2); print(a, b) (a, b, c) = range(3); print(a, b, c) (a, (b, ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/unpack1.py
Python
apache-2.0
1,802
# basic while loop x = 0 while x < 2: y = 0 while y < 2: z = 0 while z < 2: z = z + 1 print(x, y, z) y = y + 1 x = x + 1
YifuLiu/AliOS-Things
components/py_engine/tests/basics/while1.py
Python
apache-2.0
182
# test while conditions which are optimised by the compiler while 0: print(0) else: print(1) while 1: print(2) break while 2: print(3) break while -1: print(4) break while False: print('a') else: print('b') while True: print('a') break while not False: print('a...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/while_cond.py
Python
apache-2.0
386
# test nested whiles within a try-except while 1: print(1) try: print(2) while 1: print(3) break except: print(4) print(5) break
YifuLiu/AliOS-Things
components/py_engine/tests/basics/while_nest_exc.py
Python
apache-2.0
198
class CtxMgr: def __enter__(self): print("__enter__") return self def __exit__(self, a, b, c): print("__exit__", repr(a), repr(b)) with CtxMgr() as a: print(isinstance(a, CtxMgr)) try: with CtxMgr() as a: raise ValueError except ValueError: print("ValueError") ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/with1.py
Python
apache-2.0
1,628
class CtxMgr: def __enter__(self): print("__enter__") return self def __exit__(self, a, b, c): print("__exit__", repr(a), repr(b)) for i in range(5): print(i) with CtxMgr(): if i == 3: break
YifuLiu/AliOS-Things
components/py_engine/tests/basics/with_break.py
Python
apache-2.0
254
class CtxMgr: def __enter__(self): print("__enter__") return self def __exit__(self, a, b, c): print("__exit__", repr(a), repr(b)) for i in range(5): print(i) with CtxMgr(): if i == 3: continue
YifuLiu/AliOS-Things
components/py_engine/tests/basics/with_continue.py
Python
apache-2.0
257
# test with when context manager raises in __enter__/__exit__ class CtxMgr: def __init__(self, id): self.id = id def __enter__(self): print("__enter__", self.id) if 10 <= self.id < 20: raise Exception('enter', self.id) return self def __exit__(self, a, b, c): ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/with_raise.py
Python
apache-2.0
823
class CtxMgr: def __init__(self, id): self.id = id def __enter__(self): print("__enter__", self.id) return self def __exit__(self, a, b, c): print("__exit__", self.id, repr(a), repr(b)) # simple case def foo(): with CtxMgr(1): return 4 print(foo()) # for loop ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/with_return.py
Python
apache-2.0
1,239
# cmdline: -O # test optimisation output print(__debug__) assert 0
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/cmd_optimise.py
Python
apache-2.0
67
# cmdline: -v -v -v # test printing of the parse-tree 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" f = 123456789012345678901234567890 g = 123 h = f"fstring: '{b}'"
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/cmd_parsetree.py
Python
apache-2.0
273
# cmdline: -v -v # test printing of all bytecodes # fmt: off def f(): # constants a = None + False + True a = 0 a = 1000 a = -1000 # constructing data a = 1 b = (1, 2) c = [1, 2] d = {1, 2} e = {} f = {1:2} g = 'a' h = b'a' # unary/binary ops i = 1 ...
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/cmd_showbc.py
Python
apache-2.0
2,126
# cmdline: -v -v # test verbose output print(1)
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/cmd_verbose.py
Python
apache-2.0
48
# tests for autocompletion impo sys not_exist.  not_exist  x = '123' 1, x.isdi () i = str i.lowe ('ABC') None. 
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_autocomplete.py
Python
apache-2.0
136
# basic REPL tests print(1)  2
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_basic.py
Python
apache-2.0
34
# check REPL allows to continue input 1 \ + 2 '"' "'" '\'' "\"" '\'(' "\"(" print("\"(") print('\'(') print("\'(") print('\"(') 'abc' "abc" '''abc def''' """ABC DEF""" print( 1 + 2) l = [1, 2] print(l) d = {1:'one', 2:'two'} print(d[2]) def f(x): print(x)  f(3) if1=1 if1 = 2 print(if1)
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_cont.py
Python
apache-2.0
288
# REPL tests of GNU-ish readline navigation # history buffer navigation 1 2 3   # input line motion t = 12 'boofar fbar'
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_emacs_keys.py
Python
apache-2.0
136
# cmdline: -i -c print("test") # -c option combined with -i option results in REPL
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_inspect.py
Python
apache-2.0
83
# cmdline: cmdline/repl_micropyinspect # setting MICROPYINSPECT environment variable before program exit triggers REPL
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_micropyinspect.py
Python
apache-2.0
119
# word movement # backward-word, start in word 234b1 # backward-word, don't start in word 234 b1 # backward-word on start of line. if cursor is moved, this will result in a SyntaxError 1 2 + 3b+ # forward-word, start in word 1+2 12+f+3 # forward-word, don't start in word 1+ 12 3f+ # forward-word on eo...
YifuLiu/AliOS-Things
components/py_engine/tests/cmdline/repl_words_move.py
Python
apache-2.0
709
""" categories: Modules,builtins description: Second argument to next() is not implemented cause: MicroPython is optimised for code space. workaround: Instead of ``val = next(it, deflt)`` use:: try: val = next(it) except StopIteration: val = deflt """ print(next(iter(range(0)), 42))
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/builtin_next_arg2.py
Python
apache-2.0
309
""" categories: Core,Classes description: Special method __del__ not implemented for user-defined classes cause: Unknown workaround: Unknown """ import gc class Foo: def __del__(self): print("__del__") f = Foo() del f gc.collect()
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_class_delnotimpl.py
Python
apache-2.0
248
""" categories: Core,Classes 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 inhe...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_class_mro.py
Python
apache-2.0
457
""" categories: Core,Classes 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.__...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_class_supermultiple.py
Python
apache-2.0
551
""" categories: Core,Classes description: Calling super() getter property in subclass will return a property object, not the value cause: Unknown workaround: Unknown """ class A: @property def p(self): return {"a": 10} class AA(A): @property def p(self): return super().p a = AA() p...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_class_superproperty.py
Python
apache-2.0
330
""" categories: Core description: f-strings don't support concatenation with adjacent literals if the adjacent literals contain braces cause: MicroPython is optimised for code space. workaround: Use the + operator between literal strings when either is an f-string """ x = 1 print("aa" f"{x}") print(f"{x}" "ab") print(...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_fstring_concat.py
Python
apache-2.0
356
""" categories: Core description: f-strings cannot support expressions that require parsing to resolve nested braces cause: MicroPython is optimised for code space. workaround: Only use simple expressions inside f-strings """ f'{"hello {} world"}' f"{repr({})}"
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_fstring_parser.py
Python
apache-2.0
263
""" categories: Core description: Raw f-strings are not supported cause: MicroPython is optimised for code space. workaround: Unknown """ rf"hello"
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_fstring_raw.py
Python
apache-2.0
149
""" categories: Core description: f-strings don't support the !r, !s, and !a conversions cause: MicroPython is optimised for code space. workaround: Use repr(), str(), and ascii() explictly. """ class X: def __repr__(self): return "repr" def __str__(self): return "str" print(f"{X()!r}") pri...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_fstring_repr.py
Python
apache-2.0
335
""" categories: Core,Functions description: Error messages for methods may display unexpected argument counts cause: MicroPython counts "self" as an argument. workaround: Interpret error messages with the information above in mind. """ try: [].append() except Exception as e: print(e)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_function_argcount.py
Python
apache-2.0
293
""" categories: Core,Functions description: Function objects do not have the ``__module__`` attribute cause: MicroPython is optimized for reduced code size and RAM usage. workaround: Use ``sys.modules[function.__globals__['__name__']]`` for non-builtin modules. """ def f(): pass print(f.__module__)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_function_moduleattr.py
Python
apache-2.0
308
""" categories: Core,Functions 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)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_function_userattr.py
Python
apache-2.0
263
""" categories: Core,Generator description: Context manager __exit__() not called in a generator which does not run to completion cause: Unknown workaround: Unknown """ class foo(object): def __enter__(self): print("Enter") def __exit__(self, *args): print("Exit") def bar(x): with foo()...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_generator_noexit.py
Python
apache-2.0
465
""" categories: Core,import description: __all__ is unsupported in __init__.py in MicroPython. cause: Not implemented. workaround: Manually import the sub-modules directly in __init__.py using ``from . import foo, bar``. """ from modules3 import * foo.hello()
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_import_all.py
Python
apache-2.0
261
""" categories: Core,import description: __path__ attribute of a package has a different type (single string instead of list of strings) in MicroPython cause: MicroPython does't support namespace packages split across filesystem. Beyond that, MicroPython's import system is highly optimized for minimal memory usage. wor...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_import_path.py
Python
apache-2.0
493
""" categories: Core,import description: Failed to load modules are still registered as loaded cause: To make module handling more efficient, it's not wrapped with exception handling. workaround: Test modules before production use; during development, use ``del sys.modules["name"]``, or just soft or hard reset the boar...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_import_prereg.py
Python
apache-2.0
511
""" categories: Core,import description: MicroPython does't support namespace packages split across filesystem. cause: MicroPython's import system is highly optimized for simplicity, minimal memory usage, and minimal filesystem search overhead. workaround: Don't install modules belonging to the same namespace package i...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_import_split_ns_pkgs.py
Python
apache-2.0
705
""" categories: Core,Runtime 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()) te...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_locals.py
Python
apache-2.0
325
""" categories: Core,Runtime description: Code running in eval() function doesn't have access to local variables 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. Effectively, ``eval(expr)`` in MicroPython is equivale...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/core_locals_eval.py
Python
apache-2.0
469
""" categories: Modules,array description: Comparison between different typecodes not supported cause: Code size workaround: Compare individual elements """ import array array.array("b", [1, 2]) == array.array("i", [1, 2])
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/module_array_comparison.py
Python
apache-2.0
224
""" categories: Modules,array description: Overflow checking is not implemented cause: MicroPython implements implicit truncation in order to reduce code size and execution time workaround: If CPython compatibility is needed then mask the value explicitly """ import array a = array.array("b", [257]) print(a)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/module_array_constructor.py
Python
apache-2.0
311
print("foo") xxx
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules/foo.py
Python
apache-2.0
17
__all__ = ["foo"]
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules3/__init__.py
Python
apache-2.0
18
def hello(): print("hello")
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules3/foo.py
Python
apache-2.0
32
""" categories: Modules,array description: Looking for integer not implemented cause: Unknown workaround: Unknown """ import array print(1 in array.array("B", b"12"))
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_array_containment.py
Python
apache-2.0
168
""" categories: Modules,array description: Array deletion not implemented cause: Unknown workaround: Unknown """ import array a = array.array("b", (1, 2, 3)) del a[1] print(a)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_array_deletion.py
Python
apache-2.0
177
""" categories: Modules,array description: Subscript with step != 1 is not yet implemented cause: Unknown workaround: Unknown """ import array a = array.array("b", (1, 2, 3)) print(a[3:2:2])
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_array_subscrstep.py
Python
apache-2.0
192
""" categories: Modules,deque description: Deque not implemented cause: Unknown workaround: Use regular lists. micropython-lib has implementation of collections.deque. """ import collections D = collections.deque() print(D)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_deque.py
Python
apache-2.0
225
""" categories: Modules,json description: JSON module does not throw exception when object is not serialisable 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") except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_json_nonserializable.py
Python
apache-2.0
319
""" categories: Modules,os description: ``environ`` attribute is not implemented 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"]) except AttributeError: ...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_os_environ.py
Python
apache-2.0
462
""" categories: Modules,os description: ``getenv`` returns actual value instead of cached value 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"))
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_os_getenv.py
Python
apache-2.0
284
""" categories: Modules,os description: ``getenv`` only allows one argument cause: Unknown workaround: Test that the return value is ``None`` """ import os try: print(os.getenv("NEW_VARIABLE", "DEFAULT")) except TypeError: print("should not get here") # this assumes NEW_VARIABLE is never an empty variable ...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_os_getenv_argcount.py
Python
apache-2.0
370
""" categories: Modules,random description: ``getrandbits`` method can only return a maximum of 32 bits at a time. cause: PRNG's internal state is only 32bits so it can only return a maximum of 32 bits of data at a time. workaround: If you need a number that has more than 32 bits then utilize the random module from mic...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_random_getrandbits.py
Python
apache-2.0
404
""" categories: Modules,random description: ``randint`` method can only return an integer that is at most the native word size. cause: PRNG is only able to generate 32 bits of state at a time. The result is then cast into a native sized int instead of a full int object. workaround: If you need integers larger than nati...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_random_randint.py
Python
apache-2.0
464
""" categories: Modules,struct description: Struct pack with too few args, not checked by uPy cause: Unknown workaround: Unknown """ import struct try: print(struct.pack("bb", 1)) print("Should not get here") except: print("struct.error")
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_struct_fewargs.py
Python
apache-2.0
252
""" categories: Modules,struct description: Struct pack with too many args, not checked by uPy cause: Unknown workaround: Unknown """ import struct try: print(struct.pack("bb", 1, 2, 3)) print("Should not get here") except: print("struct.error")
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_struct_manyargs.py
Python
apache-2.0
259
""" categories: Modules,struct description: Struct pack with whitespace in format, whitespace ignored by CPython, error on uPy cause: MicroPython is optimised for code size. workaround: Don't use spaces in format strings. """ import struct try: print(struct.pack("b b", 1, 2)) print("Should have worked") except...
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_struct_whitespace_in_format.py
Python
apache-2.0
348
""" categories: Modules,sys description: Overriding sys.stdin, sys.stdout and sys.stderr not possible cause: They are stored in read-only memory. workaround: Unknown """ import sys sys.stdin = None print(sys.stdin)
YifuLiu/AliOS-Things
components/py_engine/tests/cpydiff/modules_sys_stdassign.py
Python
apache-2.0
216