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 errors from bad operations (unary, binary, etc) # unsupported unary operators try: ~bytearray() except TypeError: print('TypeError') # unsupported binary operators try: bytearray() // 2 except TypeError: print('TypeError') # object with buffer protocol needed on rhs try: bytearray(1) + 1 e...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/op_error_bytearray.py
Python
apache-2.0
360
# test errors from bad operations (unary, binary, etc) def test_exc(code, exc): try: exec(code) print("no exception") except exc: print("right exception") except: print("wrong exception") # object with buffer protocol needed on rhs try: (1 << 70) in 1 except TypeError: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/op_error_intbig.py
Python
apache-2.0
343
# test errors from bad operations with literals # these raise a SyntaxWarning in CPython; see https://bugs.python.org/issue15248 # unsupported subscription try: 1[0] except TypeError: print("TypeError") try: ""[""] except TypeError: print("TypeError") # not callable try: 1() except TypeError: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/op_error_literal.py
Python
apache-2.0
339
# test errors from bad operations (unary, binary, etc) try: memoryview except: print("SKIP") raise SystemExit # unsupported binary operators try: m = memoryview(bytearray()) m += bytearray() except TypeError: print('TypeError')
YifuLiu/AliOS-Things
components/py_engine/tests/basics/op_error_memoryview.py
Python
apache-2.0
253
# see https://docs.python.org/3/reference/expressions.html#operator-precedence # '|' is the least binding numeric operator # '^' # OK: 1 | (2 ^ 3) = 1 | 1 = 1 # BAD: (1 | 2) ^ 3 = 3 ^ 3 = 0 print(1 | 2 ^ 3) # '&' # OK: 3 ^ (2 & 1) = 3 ^ 0 = 3 # BAD: (3 ^ 2) & 1 = 1 & 1 = 1 print(3 ^ 2 & 1) # '<<', '>>' # OK: 2 &...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/op_precedence.py
Python
apache-2.0
818
try: from collections import OrderedDict except ImportError: try: from ucollections import OrderedDict except ImportError: print("SKIP") raise SystemExit d = OrderedDict([(10, 20), ("b", 100), (1, 2)]) print(len(d)) print(list(d.keys())) print(list(d.values())) del d["b"] print(len(...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/ordereddict1.py
Python
apache-2.0
850
try: from collections import OrderedDict except ImportError: try: from ucollections import OrderedDict except ImportError: print("SKIP") raise SystemExit x = OrderedDict() y = OrderedDict() x['a'] = 1 x['b'] = 2 y['a'] = 1 y['b'] = 2 print(x) print(y) print(x == y) z = OrderedDict(...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/ordereddict_eq.py
Python
apache-2.0
541
# parser tests try: compile except NameError: print("SKIP") raise SystemExit # completely empty string # uPy and CPy differ for this case #try: # compile("", "stdin", "single") #except SyntaxError: # print("SyntaxError") try: compile("", "stdin", "eval") except SyntaxError: print("SyntaxErro...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/parser.py
Python
apache-2.0
586
# tests that differ when running under Python 3.4 vs 3.5/3.6/3.7 try: exec except NameError: print("SKIP") raise SystemExit # from basics/fun_kwvarargs.py # test evaluation order of arguments (in 3.4 it's backwards, 3.5 it's fixed) def f4(*vargs, **kwargs): print(vargs, kwargs) def print_ret(x): p...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/python34.py
Python
apache-2.0
1,287
# tests for things that only Python 3.6 supports # underscores in numeric literals print(100_000) print(0b1010_0101) print(0xff_ff) # underscore supported by int constructor print(int('1_2_3')) print(int('0o1_2_3', 8))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/python36.py
Python
apache-2.0
221
# test return statement def f(): return print(f()) def g(): return 1 print(g()) def f(x): return 1 if x else 2 print(f(0), f(1))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/return1.py
Python
apache-2.0
144
# test scoping rules # explicit global variable a = 1 def f(): global a global a, a # should be able to redefine as global a = 2 f() print(a) # explicit nonlocal variable def f(): a = 1 def g(): nonlocal a nonlocal a, a # should be able to redefine as nonlocal a = 2 g()...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/scope.py
Python
apache-2.0
729
# test implicit scoping rules # implicit nonlocal, with variable defined after closure def f(): def g(): return x # implicit nonlocal x = 3 # variable defined after function that closes over it return g print(f()()) # implicit nonlocal at inner level, with variable defined after closure def f(): ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/scope_implicit.py
Python
apache-2.0
725
# make sure type of first arg (self) to a builtin method is checked list.append try: list.append() except TypeError as e: print("TypeError") try: list.append(1) except TypeError as e: print("TypeError") try: list.append(1, 2) except TypeError as e: print("TypeError") l = [] list.append(l, 2...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/self_type_check.py
Python
apache-2.0
464
# Basics a, b = 1, 2 print(a, b) a, b = (1, 2) print(a, b) (a, b) = 1, 2 print(a, b) (a, b) = (1, 2) print(a, b) # Tuples/lists are optimized a, b = [1, 2] print(a, b) [a, b] = 100, 200 print(a, b) # optimised 3-way swap a = 1 b = 2 c = 3 a, b, c = b, c, a print(a, b, c) try: a, b, c = (1, 2) except ValueError: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/seq_unpack.py
Python
apache-2.0
622
s = {1, 2, 3, 4} print(s.add(5)) print(sorted(s)) s = set() s.add(0) s.add(False) print(s) s = set() s.add(False) s.add(0) print(s) s = set() s.add(1) s.add(True) print(s) s = set() s.add(True) s.add(1) print(s)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_add.py
Python
apache-2.0
216
# basic sets s = {1} print(s) s = {3, 4, 3, 1} print(sorted(s)) # expression in constructor s = {1 + len(s)} print(s) # bools mixed with integers s = {False, True, 0, 1, 2} print(len(s)) # Sets are not hashable try: {s: 1} except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_basic.py
Python
apache-2.0
273
# test set binary operations sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}] for s in sets: for t in sets: print(sorted(s), '|', sorted(t), '=', sorted(s | t)) print(sorted(s), '^', sorted(t), '=', sorted(s ^ t)) print(sorted(s), '&', sorted(t), '=', sorted(s & t)) ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_binop.py
Python
apache-2.0
1,807
s = {1, 2, 3, 4} print(s.clear()) print(list(s))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_clear.py
Python
apache-2.0
49
print({a for a in range(5)})
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_comprehension.py
Python
apache-2.0
29
for i in 1, 2: for o in {}, {1}, {2}: print("{} in {}: {}".format(i, o, i in o)) print("{} not in {}: {}".format(i, o, i not in o))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_containment.py
Python
apache-2.0
152
s = {1, 2, 3, 4} t = s.copy() s.add(5) t.add(7) for i in s, t: print(sorted(i))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_copy.py
Python
apache-2.0
84
l = [1, 2, 3, 4] s = set(l) outs = [s.difference(), s.difference({1}), s.difference({1}, [1, 2]), s.difference({1}, {1, 2}, {2, 3})] for out in outs: print(sorted(out)) s = set(l) print(s.difference_update()) print(sorted(s)) print(s.difference_update({1})) print(sorted(s)) print(s.differen...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_difference.py
Python
apache-2.0
391
s = {1, 2} print(s.discard(1)) print(list(s))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_discard.py
Python
apache-2.0
46
s = {1, 2, 3, 4} print(sorted(s)) print(sorted(s.intersection({1, 3}))) print(sorted(s.intersection([3, 4]))) print(s.intersection_update([1])) print(sorted(s))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_intersection.py
Python
apache-2.0
162
s = {1, 2, 3, 4} print(s.isdisjoint({1})) print(s.isdisjoint([2])) print(s.isdisjoint([])) print(s.isdisjoint({7,8,9,10})) print(s.isdisjoint([7,8,9,1]))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_isdisjoint.py
Python
apache-2.0
154
sets = [set(), {1}, {1, 2, 3}, {3, 4, 5}, {5, 6, 7}] args = sets + [[1], [1, 2], [1, 2 ,3]] for i in sets: for j in args: print(i.issubset(j)) print(i.issuperset(j))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_isfooset.py
Python
apache-2.0
186
s = {1, 2, 3, 4} l = list(s) l.sort() print(l)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_iter.py
Python
apache-2.0
48
i = iter(iter({1, 2, 3})) print(sorted(i))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_iter_of_iter.py
Python
apache-2.0
43
s = {1} print(s.pop()) try: print(s.pop(), "!!!") except KeyError: pass else: print("Failed to raise KeyError") # this tests an optimisation in mp_set_remove_first # N must not be equal to one of the values in hash_allocation_sizes N = 11 s = set(range(N)) while s: print(s.pop()) # last pop() should tr...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_pop.py
Python
apache-2.0
444
# basic test s = {1} print(s.remove(1)) print(list(s)) try: print(s.remove(1), "!!!") except KeyError as er: print('KeyError', er.args[0]) else: print("failed to raise KeyError") # test sets of varying size for n in range(20): print('testing set with {} items'.format(n)) for i in range(n): ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_remove.py
Python
apache-2.0
767
# set object with special methods s = {1, 2} print(s.__contains__(1)) print(s.__contains__(3))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_specialmeth.py
Python
apache-2.0
96
print(sorted({1,2}.symmetric_difference({2,3}))) print(sorted({1,2}.symmetric_difference([2,3]))) s = {1,2} print(s.symmetric_difference_update({2,3})) print(sorted(s))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_symmetric_difference.py
Python
apache-2.0
169
# set type # This doesn't really work as expected, because {None} # leads SyntaxError during parsing. try: set except NameError: print("SKIP") raise SystemExit print(set) print(type(set()) == set) print(type({None}) == set)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_type.py
Python
apache-2.0
240
print(sorted({1}.union({2})))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_union.py
Python
apache-2.0
30
# test set unary operations print(bool(set())) print(bool(set('abc'))) print(len(set())) print(len(set('abc'))) try: hash(set('abc')) except TypeError: print('TypeError')
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_unop.py
Python
apache-2.0
182
s = {1} s.update() print(s) s.update([2]) print(sorted(s)) s.update([1,3], [2,2,4]) print(sorted(s))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/set_update.py
Python
apache-2.0
101
# test builtin slice attributes access # print slice attributes class A: def __getitem__(self, idx): print(idx.start, idx.stop, idx.step) try: t = A()[1:2] except: print("SKIP") raise SystemExit A()[1:2:3] # test storing to attr (shouldn't be allowed) class B: def __getitem__(self, idx)...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/slice_attrs.py
Python
apache-2.0
435
# Test builtin slice indices resolution # A class that returns an item key class A: def __getitem__(self, idx): return idx # Make sure that we have slices and .indices() try: A()[2:5].indices(10) except: print("SKIP") raise SystemExit print(A()[:].indices(10)) print(A()[2:].indices(10)) print...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/slice_indices.py
Python
apache-2.0
611
# test slicing when arguments are bignums print(list(range(10))[(1<<66)>>65:]) print(list(range(10))[:(1<<66)>>65]) print(list(range(10))[::(1<<66)>>65])
YifuLiu/AliOS-Things
components/py_engine/tests/basics/slice_intbig.py
Python
apache-2.0
155
class A: def __bool__(self): print('__bool__') return True def __len__(self): print('__len__') return 1 class B: def __len__(self): print('__len__') return 0 print(bool(A())) print(len(A())) print(bool(B())) print(len(B()))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/slots_bool_len.py
Python
apache-2.0
286
class A: def __eq__(self, other): print("A __eq__ called") return True class B: def __ne__(self, other): print("B __ne__ called") return True class C: def __eq__(self, other): print("C __eq__ called") return False class D: def __ne__(self, other): ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/special_comparisons.py
Python
apache-2.0
561
class E: def __repr__(self): return "E" def __eq__(self, other): print('E eq', other) return 123 class F: def __repr__(self): return "F" def __ne__(self, other): print('F ne', other) return -456 print(E() != F()) print(F() != E()) tests = (None, 0, 1,...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/special_comparisons2.py
Python
apache-2.0
552
class Cud(): def __init__(self): print("__init__ called") def __repr__(self): print("__repr__ called") return "" def __lt__(self, other): print("__lt__ called") def __le__(self, other): print("__le__ called") def __eq__(self, other): print("__eq__...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/special_methods.py
Python
apache-2.0
2,366
class Cud(): def __init__(self): #print("__init__ called") pass def __repr__(self): print("__repr__ called") return "" def __lt__(self, other): print("__lt__ called") def __le__(self, other): print("__le__ called") def __eq__(self, other): ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/special_methods2.py
Python
apache-2.0
2,493
# test StopIteration interaction with generators try: enumerate, exec except: print("SKIP") raise SystemExit def get_stop_iter_arg(msg, code): try: exec(code) print("FAIL") except StopIteration as er: print(msg, er.args) class A: def __iter__(self): return se...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/stopiteration.py
Python
apache-2.0
1,315
# basic strings # literals print('abc') print(r'abc') print(u'abc') print(repr('\a\b\t\n\v\f\r')) print('\z') # unrecognised escape char # construction print(str()) print(str('abc')) # inplace addition x = 'abc' print(x) x += 'def' print(x) # binary ops print('123' + "456") print('123' * 5) try: '123' * '1' exc...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string1.py
Python
apache-2.0
796
try: str.center except: print("SKIP") raise SystemExit print("foo".center(0)) print("foo".center(1)) print("foo".center(3)) print("foo".center(4)) print("foo".center(5)) print("foo".center(6)) print("foo".center(20))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_center.py
Python
apache-2.0
230
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" == "10") print("1" > "1") print("1" > "2")...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_compare.py
Python
apache-2.0
1,156
try: str.count except AttributeError: print("SKIP") raise SystemExit print("".count("")) print("".count("a")) print("a".count("")) print("a".count("a")) print("a".count("b")) print("b".count("a")) print("aaa".count("")) print("aaa".count("a")) print("aaa".count("aa")) print("aaa".count("aaa")) print("aaa"...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_count.py
Python
apache-2.0
1,288
# this file has CR line endings to test lexer's conversion of them to LF # in triple quoted strings print(repr("""abc def"""))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_cr_conversion.py
Python
apache-2.0
127
# this file has CRLF line endings to test lexer's conversion of them to LF # in triple quoted strings print(repr("""abc def"""))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_crlf_conversion.py
Python
apache-2.0
133
print("foobar".endswith("bar")) print("foobar".endswith("baR")) print("foobar".endswith("bar1")) print("foobar".endswith("foobar")) print("foobar".endswith("")) print("foobar".endswith("foobarbaz")) #print("1foobar".startswith("foo", 1)) #print("1foo".startswith("foo", 1)) #print("1foo".startswith("1foo", 1)) #print("...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_endswith.py
Python
apache-2.0
455
# MicroPython doesn't support tuple argument try: "foobar".endswith(("bar", "sth")) except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_endswith_upy.py
Python
apache-2.0
130
a = "a\1b" print(len(a)) print(ord(a[1])) print(len("a\123b")) a = "a\12345b" print(len(a)) print(ord(a[1])) a = "a\xffb" print(len(a)) print(ord(a[1]))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_escape.py
Python
apache-2.0
154
print("hello world".find("ll")) print("hello world".find("ll", None)) print("hello world".find("ll", 1)) print("hello world".find("ll", 1, None)) print("hello world".find("ll", None, None)) print("hello world".find("ll", 1, -1)) print("hello world".find("ll", 1, 1)) print("hello world".find("ll", 1, 2)) print("hello wo...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_find.py
Python
apache-2.0
856
# basic functionality test for {} format string def test(fmt, *args): print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') test("}}{{") test("{}-{}", 1, [4, 5]) test("{0}-{1}", 1, [4, 5]) test("{1}-{0}", 1, [4, 5]) test("{:x}", 1) test("{!r}", 2) test("{:x}", 0x10) test("{!r}", "foo") test("{!s}", "foo") t...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_format.py
Python
apache-2.0
1,782
# comprehensive functionality test for {} format string int_tests = False # these take a while char_tests = True str_tests = True def test(fmt, *args): print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): fmt = '{' if ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_format2.py
Python
apache-2.0
2,025
# tests for errors in {} format string try: '{0:0}'.format('zzz') except (ValueError): print('ValueError') try: '{1:}'.format(1) except IndexError: print('IndexError') try: '}'.format('zzzz') except ValueError: print('ValueError') # end of format parsing conversion specifier try: '{!'.fo...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_format_error.py
Python
apache-2.0
1,415
try: '' % () except TypeError: print("SKIP") raise SystemExit print("%%" % ()) print("=%s=" % 1) print("=%s=%s=" % (1, 2)) print("=%s=" % (1,)) print("=%s=" % [1, 2]) print("=%s=" % "str") print("=%r=" % "str") try: print("=%s=%s=" % 1) except TypeError: print("TypeError") try: print("=%s=%s...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_format_modulo.py
Python
apache-2.0
1,887
# test string modulo formatting with int values try: '' % () except TypeError: print("SKIP") raise SystemExit # basic cases print("%d" % 10) print("%+d" % 10) print("% d" % 10) print("%d" % -10) print("%d" % True) print("%i" % -10) print("%i" % True) print("%u" % -10) print("%u" % True) print("%x" % 18) p...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_format_modulo_int.py
Python
apache-2.0
952
def f(): return 4 def g(_): return 5 def h(): return 6 print(f'no interpolation') print(f"no interpolation") print(f"""no interpolation""") x, y = 1, 2 print(f'{x}') print(f'{x:08x}') print(f'a {x} b {y} c') print(f'a {x:08x} b {y} c') print(f'a {"hello"} b') print(f'a {f() + g("foo") + h()} b') def foo...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_fstring.py
Python
apache-2.0
1,118
# test f-string debug feature {x=} def f(): return 4 def g(_): return 5 def h(): return 6 x, y = 1, 2 print(f"{x=}") print(f"{x=:08x}") print(f"a {x=} b {y} c") print(f"a {x=:08x} b {y} c") print(f'a {f() + g("foo") + h()=} b') print(f'a {f() + g("foo") + h()=:08x} b')
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_fstring_debug.py
Python
apache-2.0
291
print("hello world".index("ll")) print("hello world".index("ll", None)) print("hello world".index("ll", 1)) print("hello world".index("ll", 1, None)) print("hello world".index("ll", None, None)) print("hello world".index("ll", 1, -1)) try: print("hello world".index("ll", 1, 1)) except ValueError: print("Raised...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_index.py
Python
apache-2.0
1,712
print("".isspace()) print(" \t\n\r\v\f".isspace()) print("a".isspace()) print(" \t\n\r\v\fa".isspace()) print("".isalpha()) print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".isalpha()) print("0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".isalpha()) print("this ".isalpha()) print("".isdigit()) print(...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_istest.py
Python
apache-2.0
645
print(','.join(())) print(','.join(('a',))) print(','.join(('a', 'b'))) print(','.join([])) print(','.join(['a'])) print(','.join(['a', 'b'])) print(''.join('')) print(''.join('abc')) print(','.join('abc')) print(','.join('abc' for i in range(5))) print(b','.join([b'abc', b'123'])) try: ''.join(None) except Typ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_join.py
Python
apache-2.0
713
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string lo...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_large.py
Python
apache-2.0
856
# basic multiplication print('0' * 5) # check negative, 0, positive; lhs and rhs multiplication for i in (-4, -2, 0, 2, 4): print(i * '12') print('12' * i) # check that we don't modify existing object a = '123' c = a * 3 print(a, c)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_mult.py
Python
apache-2.0
243
try: str.partition except AttributeError: print("SKIP") raise SystemExit print("asdf".partition('g')) print("asdf".partition('a')) print("asdf".partition('s')) print("asdf".partition('f')) print("asdf".partition('d')) print("asdf".partition('asd')) print("asdf".partition('sdf')) print("asdf".partition('as'...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_partition.py
Python
apache-2.0
1,017
print("".replace("a", "b")) print("aaa".replace("b", "c")) print("aaa".replace("a", "b", 0)) print("aaa".replace("a", "b", -5)) print("asdfasdf".replace("a", "b")) print("aabbaabbaabbaa".replace("aa", "cc", 3)) print("a".replace("aa", "bb")) print("testingtesting".replace("ing", "")) print("testINGtesting".replace("ing...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_replace.py
Python
apache-2.0
591
# anything above 0xa0 is printed as Unicode by CPython # the abobe is CPython implementation detail, stick to ASCII for c in range(0x80): print("0x{:02x}: {}".format(c, repr(chr(c))))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_repr.py
Python
apache-2.0
188
print("hello world".rfind("ll")) print("hello world".rfind("ll", None)) print("hello world".rfind("ll", 1)) print("hello world".rfind("ll", 1, None)) print("hello world".rfind("ll", None, None)) print("hello world".rfind("ll", 1, -1)) print("hello world".rfind("ll", 1, 1)) print("hello world".rfind("ll", 1, 2)) print("...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_rfind.py
Python
apache-2.0
815
print("hello world".rindex("ll")) print("hello world".rindex("ll", None)) print("hello world".rindex("ll", 1)) print("hello world".rindex("ll", 1, None)) print("hello world".rindex("ll", None, None)) print("hello world".rindex("ll", 1, -1)) try: print("hello world".rindex("ll", 1, 1)) except ValueError: print(...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_rindex.py
Python
apache-2.0
1,735
try: str.partition except AttributeError: print("SKIP") raise SystemExit print("asdf".rpartition('g')) print("asdf".rpartition('a')) print("asdf".rpartition('s')) print("asdf".rpartition('f')) print("asdf".rpartition('d')) print("asdf".rpartition('asd')) print("asdf".rpartition('sdf')) print("asdf".rpartit...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_rpartition.py
Python
apache-2.0
820
# default separator (whitespace) print("a b".rsplit()) #print(" a b ".rsplit(None)) #print(" a b ".rsplit(None, 1)) #print(" a b ".rsplit(None, 2)) #print(" a b c ".rsplit(None, 1)) #print(" a b c ".rsplit(None, 0)) #print(" a b c ".rsplit(None, -1)) # empty separator should fail...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_rsplit.py
Python
apache-2.0
1,526
print("123"[0:1]) print("123"[0:2]) print("123"[:1]) print("123"[1:]) # Idiom for copying sequence print("123"[:]) print("123"[:-1]) # Weird cases print("123"[0:0]) print("123"[1:0]) print("123"[1:1]) print("123"[-1:-1]) print("123"[-3:]) print("123"[-3:3]) print("123"[0:]) print("123"[:0]) print("123"[:-3]) prin...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_slice.py
Python
apache-2.0
555
# default separator (whitespace) print("a b".split()) print(" a b ".split(None)) print(" a b ".split(None, 1)) print(" a b ".split(None, 2)) print(" a b c ".split(None, 1)) print(" a b c ".split(None, 0)) print(" a b c ".split(None, -1)) print("foo\n\t\x07\v\nbar".split()) print("...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_split.py
Python
apache-2.0
817
# test string.splitlines() method try: str.splitlines except: print("SKIP") raise SystemExit # test \n as newline print("foo\nbar".splitlines()) print("foo\nbar\n".splitlines()) print("foo and\nbar\n".splitlines()) print("foo\nbar\n\n".splitlines()) print("foo\n\nbar\n\n".splitlines()) print("\nfoo\nbar\n...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_splitlines.py
Python
apache-2.0
1,010
print("foobar".startswith("foo")) print("foobar".startswith("Foo")) print("foobar".startswith("foo1")) print("foobar".startswith("foobar")) print("foobar".startswith("")) print("1foobar".startswith("foo", 1)) print("1foo".startswith("foo", 1)) print("1foo".startswith("1foo", 1)) print("1fo".startswith("foo", 1)) print...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_startswith.py
Python
apache-2.0
424
# MicroPython doesn't support tuple argument try: "foobar".startswith(("foo", "sth")) except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_startswith_upy.py
Python
apache-2.0
132
print("".strip()) print(" \t\n\r\v\f".strip()) print(" T E S T".strip()) print("abcabc".strip("ce")) print("aaa".strip("b")) print("abc efg ".strip("g a")) print(' spacious '.lstrip()) print('www.example.com'.lstrip('cmowz.')) print(' spacious '.rstrip()) print('mississippi'.rstrip('ipz')) print(b'mississip...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_strip.py
Python
apache-2.0
988
print("".lower()) print(" t\tn\nr\rv\vf\f".upper()) print(" T E S T".lower()) print("*@a1b2cabc_[]/\\".upper())
YifuLiu/AliOS-Things
components/py_engine/tests/basics/string_upperlow.py
Python
apache-2.0
112
try: import ustruct as struct except: try: import struct except ImportError: print("SKIP") raise SystemExit print(struct.calcsize("<bI")) print(struct.unpack("<bI", b"\x80\0\0\x01\0")) print(struct.calcsize(">bI")) print(struct.unpack(">bI", b"\x80\0\0\x01\0")) # 32-bit little-endi...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/struct1.py
Python
apache-2.0
2,326
try: import ustruct as struct except: try: import struct except ImportError: print("SKIP") raise SystemExit # check maximum pack on 32-bit machine print(struct.pack("<I", 2**32 - 1)) print(struct.pack("<I", 0xffffffff)) # long long ints print(struct.pack("<Q", 1)) print(struct.pack...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/struct1_intbig.py
Python
apache-2.0
1,535
# test ustruct with a count specified before the type try: import ustruct as struct except: try: import struct except ImportError: print("SKIP") raise SystemExit print(struct.calcsize('0s')) print(struct.unpack('0s', b'')) print(struct.pack('0s', b'123')) print(struct.calcsize('2s...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/struct2.py
Python
apache-2.0
1,497
# test ustruct and endian specific things try: import ustruct as struct except: try: import struct except ImportError: print("SKIP") raise SystemExit # unpack/unpack_from with unaligned native type buf = b'0123456789' print(struct.unpack('h', memoryview(buf)[1:3])) print(struct.unp...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/struct_endian.py
Python
apache-2.0
617
# test MicroPython-specific features of struct try: import ustruct as struct except: try: import struct except ImportError: print("SKIP") raise SystemExit class A(): pass # pack and unpack objects o = A() s = struct.pack("<O", o) o2 = struct.unpack("<O", s) print(o is o2[0]) ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/struct_micropython.py
Python
apache-2.0
793
# Calling an inherited classmethod class Base: @classmethod def foo(cls): print(cls.__name__) try: Base.__name__ except AttributeError: print("SKIP") raise SystemExit class Sub(Base): pass Sub.foo() # overriding a member and accessing it via a classmethod class A(object): foo ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_classmethod.py
Python
apache-2.0
573
class mylist(list): pass a = mylist([1, 2, 5]) # Test setting instance attr a.attr = "something" # Test base type __str__ print(a) # Test getting instance attr print(a.attr) # Test base type ->subscr print(a[-1]) a[0] = -1 print(a) # Test another base type unary op print(len(a)) # Test binary op of base type, wit...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native1.py
Python
apache-2.0
728
class Base1: def __init__(self, *args): print("Base1.__init__", args) class Clist1(Base1, list): pass a = Clist1() print(len(a)) # Not compliant - list assignment should happen in list.__init__, which is not called # because there's Base1.__init__, but we assign in list.__new__ #a = Clist1([1, 2, 3]) ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native2_list.py
Python
apache-2.0
587
class Base1: def __init__(self, *args): print("Base1.__init__", args) class Ctuple1(Base1, tuple): pass a = Ctuple1() print(len(a)) a = Ctuple1([1, 2, 3]) print(len(a)) print("---") class Ctuple2(tuple, Base1): pass a = Ctuple2() print(len(a)) a = Ctuple2([1, 2, 3]) print(len(a)) a = tuple([1,...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native2_tuple.py
Python
apache-2.0
411
# test subclassing a native exception class MyExc(Exception): pass e = MyExc(100, "Some error") print(e) print(repr(e)) print(e.args) try: raise MyExc("Some error", 1) except MyExc as e: print("Caught exception:", repr(e)) try: raise MyExc("Some error2", 2) except Exception as e: print("Caught...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native3.py
Python
apache-2.0
948
# Test calling non-special method inherited from native type class mylist(list): pass l = mylist([1, 2, 3]) print(l) l.append(10) print(l)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native4.py
Python
apache-2.0
145
# Subclass from 2 bases explicitly subclasses from object class Base1(object): pass class Base2(object): pass class Sub(Base1, Base2): pass o = Sub()
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native5.py
Python
apache-2.0
166
# test when we subclass a type with the buffer protocol class my_bytes(bytes): pass b1 = my_bytes([0, 1]) b2 = my_bytes([2, 3]) b3 = bytes([4, 5]) # addition will use the buffer protocol on the RHS print(b1 + b2) print(b1 + b3) print(b3 + b1) # bytes construction will use the buffer protocol print(bytes(b1))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_buffer.py
Python
apache-2.0
318
# test calling a subclass of a native class that supports calling # For this test we need a native class that can be subclassed (has make_new) # and is callable (has call). The only one available is machine.Signal, which # in turns needs PinBase. try: try: import umachine as machine except ImportError...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_call.py
Python
apache-2.0
692
# Test calling non-special method inherited from native type class mytuple(tuple): pass t = mytuple((1, 2, 3)) print(t) print(t == (1, 2, 3)) print((1, 2, 3) == t) print(t < (1, 2, 3), t < (1, 2, 4)) print((1, 2, 3) <= t, (1, 2, 4) < t)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_cmp.py
Python
apache-2.0
244
# test containment operator on subclass of a native type class mylist(list): pass class mydict(dict): pass class mybytes(bytes): pass l = mylist([1, 2, 3]) print(0 in l) print(1 in l) d = mydict({1:1, 2:2}) print(0 in l) print(1 in l) b = mybytes(b'1234') print(0 in b) print(b'1' in b)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_containment.py
Python
apache-2.0
305
# test subclassing a native type and overriding __init__ # overriding list.__init__() class L(list): def __init__(self, a, b): super().__init__([a, b]) print(L(2, 3)) # inherits implicitly from object class A: def __init__(self): print("A.__init__") super().__init__() A() # inherits e...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_init.py
Python
apache-2.0
887
# test subclassing a native type which can be iterated over class mymap(map): pass m = mymap(lambda x: x + 10, range(4)) print(list(m))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/subclass_native_iter.py
Python
apache-2.0
142