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 builtin hash function print({1 << 66:1}) # hash big int print({-(1 << 66):2}) # hash negative big int # __hash__ returning a large number should be truncated class F: def __hash__(self): return 1 << 70 | 1 print(hash(F()) != 0) # this had a particular error with internal integer arithmetic of hash...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_hash_intbig.py
Python
apache-2.0
419
# test builtin help function try: help except NameError: print("SKIP") raise SystemExit help() # no args help(help) # help for a function help(int) # help for a class help(1) # help for an instance import micropython help(micropython) # help for a module help('modules') # list available modules print('do...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_help.py
Python
apache-2.0
364
# test builtin hex function print(hex(1)) print(hex(-1)) print(hex(15)) print(hex(-15)) print(hex(12345)) print(hex(0x12345))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_hex.py
Python
apache-2.0
128
# test builtin hex function print(hex(12345678901234567890)) print(hex(0x12345678901234567890))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_hex_intbig.py
Python
apache-2.0
97
print(id(1) == id(2)) print(id(None) == id(None)) # This can't be true per Python semantics, just CPython implementation detail #print(id([]) == id([])) l = [1, 2] print(id(l) == id(l)) f = lambda:None print(id(f) == id(f))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_id.py
Python
apache-2.0
226
# test builtin issubclass class A: pass print(issubclass(A, A)) print(issubclass(A, (A,))) try: issubclass(A, 1) except TypeError: print('TypeError') try: issubclass('a', 1) except TypeError: print('TypeError')
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_issubclass.py
Python
apache-2.0
235
# builtin len print(len(())) print(len((1,))) print(len((1, 2))) print(len([])) x = [1, 2, 3] print(len(x)) f = len print(f({})) print(f({1:2, 3:4}))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_len1.py
Python
apache-2.0
153
# test builtin locals() x = 123 print(locals()['x']) class A: y = 1 def f(self): pass print('x' in locals()) print(locals()['y']) print('f' in locals())
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_locals.py
Python
apache-2.0
184
print(list(map(lambda x: x & 1, range(-3, 4)))) print(list(map(abs, range(-3, 4)))) print(list(map(tuple, [[i] for i in range(-3, 4)]))) print(list(map(pow, range(4), range(4))))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_map.py
Python
apache-2.0
179
# test builtin min and max functions try: min max except: print("SKIP") raise SystemExit print(min(0,1)) print(min(1,0)) print(min(0,-1)) print(min(-1,0)) print(max(0,1)) print(max(1,0)) print(max(0,-1)) print(max(-1,0)) print(min([1,2,4,0,-1,2])) print(max([1,2,4,0,-1,2])) # test with key function ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_minmax.py
Python
apache-2.0
1,051
# test next(iter, default) try: next(iter([]), 42) except TypeError: # 2-argument version not supported print('SKIP') raise SystemExit print(next(iter([]), 42)) print(next(iter(range(0)), 42)) print(next((x for x in [0] if x == 1), 43)) def gen(): yield 1 yield 2 g = gen() print(next(g, 42)) pr...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_next_arg2.py
Python
apache-2.0
584
# test builtin oct function print(oct(1)) print(oct(-1)) print(oct(15)) print(oct(-15)) print(oct(12345)) print(oct(0o12345))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_oct.py
Python
apache-2.0
128
# test builtin oct function print(oct(12345678901234567890)) print(oct(0o12345670123456701234))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_oct_intbig.py
Python
apache-2.0
97
# test builtin ord (whether or not we support unicode) print(ord('a')) try: ord('') except TypeError: print("TypeError") # bytes also work in ord print(ord(b'a')) print(ord(b'\x00')) print(ord(b'\x01')) print(ord(b'\x7f')) print(ord(b'\x80')) print(ord(b'\xff')) try: ord(b'') except TypeError: prin...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_ord.py
Python
apache-2.0
421
# test overriding builtins import builtins # override generic builtin try: builtins.abs = lambda x: x + 1 except AttributeError: print("SKIP") raise SystemExit print(abs(1)) # __build_class__ is handled in a special way orig_build_class = __build_class__ builtins.__build_class__ = lambda x, y: ('class',...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_override.py
Python
apache-2.0
761
# test builtin pow() with integral values # 2 arg version print(pow(0, 1)) print(pow(1, 0)) print(pow(-2, 3)) print(pow(3, 8))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_pow.py
Python
apache-2.0
128
# test builtin pow() with integral values # 3 arg version try: print(pow(3, 4, 7)) except NotImplementedError: print("SKIP") raise SystemExit # test some edge cases print(pow(1, 1, 1)) print(pow(0, 1, 1)) print(pow(1, 0, 1)) print(pow(1, 0, 2)) # 3 arg pow is defined to only work on integers try: pri...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_pow3.py
Python
apache-2.0
553
# test builtin pow() with integral values # 3 arg version try: print(pow(3, 4, 7)) except NotImplementedError: print("SKIP") raise SystemExit print(pow(555557, 1000002, 1000003)) # Tests for 3 arg pow with large values # This value happens to be prime x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_pow3_intbig.py
Python
apache-2.0
1,008
# test builtin print function print() print(None) print('') print(1) print(1, 2) print(sep='') print(sep='x') print(end='') print(end='x\n') print(1, sep='') print(1, end='') print(1, sep='', end='') print(1, 2, sep='') print(1, 2, end='') print(1, 2, sep='', end='') print([{1:2}])
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_print.py
Python
apache-2.0
286
# test builtin property try: property except: print("SKIP") raise SystemExit # create a property object explicitly property() property(1, 2, 3) # use its accessor methods p = property() p.getter(1) p.setter(2) p.deleter(3) # basic use as a decorator class A: def __init__(self, x): self._x = x...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_property.py
Python
apache-2.0
1,903
# test builtin property combined with inheritance try: property except: print("SKIP") raise SystemExit # test property in a base class works for derived classes class A: @property def x(self): print('A x') return 123 class B(A): pass class C(B): pass class D: pass class ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_property_inherit.py
Python
apache-2.0
1,039
# test builtin range type # print print(range(4)) # bool print(bool(range(0))) print(bool(range(10))) # len print(len(range(0))) print(len(range(4))) print(len(range(1, 4))) print(len(range(1, 4, 2))) print(len(range(1, 4, -1))) print(len(range(4, 1, -1))) print(len(range(4, 1, -2))) # subscr print(range(4)[0]) pri...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_range.py
Python
apache-2.0
1,129
# test attributes of builtin range type try: range(0).start except AttributeError: print("SKIP") raise SystemExit # attrs print(range(1, 2, 3).start) print(range(1, 2, 3).stop) print(range(1, 2, 3).step) # bad attr (can't store) try: range(4).start = 0 except AttributeError: print('AttributeError...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_range_attrs.py
Python
apache-2.0
323
# test binary operations on range objects; (in)equality only # this "feature test" actually tests the implementation but is the best we can do if range(1) != range(1): print("SKIP") raise SystemExit # basic (in)equality print(range(1) == range(1)) print(range(1) != range(1)) print(range(1) != range(2)) # emp...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_range_binop.py
Python
apache-2.0
803
# test the builtin reverse() function try: reversed except: print("SKIP") raise SystemExit # list print(list(reversed([]))) print(list(reversed([1]))) print(list(reversed([1, 2, 3]))) # tuple print(list(reversed(()))) print(list(reversed((1, 2, 3)))) # string for c in reversed('ab'): print(c) # byte...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_reversed.py
Python
apache-2.0
723
# test round() with integral values tests = [ False, True, 0, 1, -1, 10 ] for t in tests: print(round(t))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_round.py
Python
apache-2.0
119
# test round() with integer values and second arg # rounding integers is an optional feature so test for it try: round(1, -1) except NotImplementedError: print('SKIP') raise SystemExit tests = [ (1, False), (1, True), (124, -1), (125, -1), (126, -1), (5, -1), (15, -1), (25, -1), (12345, 0)...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_round_int.py
Python
apache-2.0
427
# test round() with large integer values and second arg # rounding integers is an optional feature so test for it try: round(1, -1) except NotImplementedError: print('SKIP') raise SystemExit i = 2**70 tests = [ (i, 0), (i, -1), (i, -10), (i, 1), (-i, 0), (-i, -1), (-i, -10), (-i, 1), ] for t in t...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_round_intbig.py
Python
apache-2.0
347
class A: var = 132 def __init__(self): self.var2 = 34 a = A() setattr(a, "var", 123) setattr(a, "var2", 56) print(a.var) print(a.var2) try: setattr(a, b'var3', 1) except TypeError: print('TypeError') # try setattr on a built-in function try: setattr(int, 'to_bytes', 1) except (Attribut...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_setattr.py
Python
apache-2.0
436
# test builtin slice # print slice class A: def __getitem__(self, idx): print(idx) return idx s = A()[1:2:3] # check type print(type(s) is slice)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_slice.py
Python
apache-2.0
168
# test builtin sorted try: sorted set except: print("SKIP") raise SystemExit print(sorted(set(range(100)))) print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) # need to use keyword argument try: sorted([], None) except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_sorted.py
Python
apache-2.0
286
# test builtin "sum" tests = ( (), [], [0], [1], [0, 1, 2], range(10), ) for test in tests: print(sum(test)) print(sum(test, -2))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_sum.py
Python
apache-2.0
164
# test builtin type print(type(int)) try: type() except TypeError: print('TypeError') try: type(1, 2) except TypeError: print('TypeError') # second arg should be a tuple try: type('abc', None, None) except TypeError: print('TypeError') # third arg should be a dict try: type('abc', (), N...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_type.py
Python
apache-2.0
492
try: zip set except NameError: print("SKIP") raise SystemExit print(list(zip())) print(list(zip([1], set([2, 3]))))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/builtin_zip.py
Python
apache-2.0
133
print(bytearray(4)) a = bytearray([1, 2, 200]) print(type(a)) print(a[0], a[2]) print(a[-1]) print(a) a[2] = 255 print(a[-1]) a.append(10) print(len(a)) s = 0 for i in a: s += i print(s) print(a[1:]) print(a[:-1]) print(a[2:3]) print(str(bytearray(b"123"), "utf-8")) # Comparisons print(bytearray([1]) == bytearr...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray1.py
Python
apache-2.0
990
# test bytearray + bytearray b = bytearray(2) b[0] = 1 b[1] = 2 print(b + bytearray(2)) # inplace add b += bytearray(3) print(b) # extend b.extend(bytearray(4)) print(b) # this inplace add tests the code when the buffer doesn't need to be increased b = bytearray() b += b''
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_add.py
Python
apache-2.0
278
# test bytearray.append method a = bytearray(4) print(a) # append should append a single byte a.append(2) print(a) # a should not be modified if append fails try: a.append(None) except TypeError: print('TypeError') print(a)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_append.py
Python
apache-2.0
235
# test construction of bytearray from different objects print(bytearray(b'123')) print(bytearray('1234', 'utf-8')) print(bytearray('12345', 'utf-8', 'strict')) print(bytearray((1, 2))) print(bytearray([1, 2]))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_construct.py
Python
apache-2.0
211
# test construction of bytearray from different objects try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit # arrays print(bytearray(array('b', [1, 2]))) print(bytearray(array('h', [0x101, 0x202])))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_construct_array.py
Python
apache-2.0
314
# test construction of bytearray from different objects try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit # arrays print(bytearray(array('h', [1, 2]))) print(bytearray(array('I', [1, 2])))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_construct_endian.py
Python
apache-2.0
306
try: print(bytearray(b'').decode()) print(bytearray(b'abc').decode()) except AttributeError: print("SKIP") raise SystemExit
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_decode.py
Python
apache-2.0
140
print(bytearray(2**65 - (2**65 - 1)))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_intbig.py
Python
apache-2.0
38
try: bytearray()[:] = bytearray() except TypeError: print("SKIP") raise SystemExit # test slices; only 2 argument version supported by MicroPython at the moment x = bytearray(range(10)) # Assignment l = bytearray(x) l[1:3] = bytearray([10, 20]) print(l) l = bytearray(x) l[1:3] = bytearray([10]) print(l) l...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytearray_slice_assign.py
Python
apache-2.0
1,231
# literals print(b'123') print(br'123') print(rb'123') print(b'\u1234') # construction print(bytes()) print(bytes(b'abc')) # make sure empty bytes is converted correctly print(str(bytes(), 'utf-8')) a = b"123" print(a) print(str(a)) print(repr(a)) print(a[0], a[2]) print(a[-1]) print(str(a, "utf-8")) print(str(a, "u...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes.py
Python
apache-2.0
1,172
# test bytes + other print(b"123" + b"456") print(b"123" + b"") # RHS is empty, can be optimised print(b"" + b"123") # LHS is empty, can be optimised
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_add.py
Python
apache-2.0
152
# test bytes + other try: import uarray as array except ImportError: try: import array except ImportError: print("SKIP") raise SystemExit # should be byteorder-neutral print(b"123" + array.array('h', [0x1515])) print(b"\x01\x02" + array.array('b', [1, 2]))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_add_array.py
Python
apache-2.0
295
# test bytes + bytearray print(b"123" + bytearray(2)) print(b"" + bytearray(1)) # LHS is empty but can't be optimised
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_add_bytearray.py
Python
apache-2.0
120
# test bytes + other try: import uarray as array except ImportError: try: import array except ImportError: print("SKIP") raise SystemExit print(b"123" + array.array('i', [1]))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_add_endian.py
Python
apache-2.0
213
print(b"" == b"") print(b"" > b"") print(b"" < b"") print(b"" == b"1") print(b"1" == b"") print("==") print(b"" > b"1") print(b"1" > b"") print(b"" < b"1") print(b"1" < b"") print(b"" >= b"1") print(b"1" >= b"") print(b"" <= b"1") print(b"1" <= b"") print(b"1" == b"1") print(b"1" != b"1") print(b"1" == b"2") print(b"1...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_compare.py
Python
apache-2.0
920
print(b"1" == 1)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_compare2.py
Python
apache-2.0
17
# Based on MicroPython config option, comparison of str and bytes # or vice versa may issue a runtime warning. On CPython, if run as # "python3 -b", only comparison of str to bytes issues a warning, # not the other way around (while exactly comparison of bytes to # str would be the most common error, as in sock.recv(3)...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_compare3.py
Python
apache-2.0
497
try: import uarray as array except ImportError: try: import array except ImportError: print("SKIP") raise SystemExit print(array.array('b', [1, 2]) in b'\x01\x02\x03') # CPython gives False here #print(b"\x01\x02\x03" == array.array("B", [1, 2, 3]))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_compare_array.py
Python
apache-2.0
287
print(b"123" == bytearray(b"123")) print(b'123' < bytearray(b"124")) print(b'123' > bytearray(b"122")) print(bytearray(b"23") in b"1234")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_compare_bytearray.py
Python
apache-2.0
138
# test construction of bytes from different objects # tuple, list print(bytes((1, 2))) print(bytes([1, 2])) # constructor value out of range try: bytes([-1]) except ValueError: print('ValueError') # constructor value out of range try: bytes([256]) except ValueError: print('ValueError') # error in co...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_construct.py
Python
apache-2.0
405
# test construction of bytes from different objects try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit # arrays print(bytes(array('b', [1, 2]))) print(bytes(array('h', [0x101, 0x202])))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_construct_array.py
Python
apache-2.0
302
# test construction of bytes from bytearray print(bytes(bytearray(4)))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_construct_bytearray.py
Python
apache-2.0
72
# test construction of bytes from different objects try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit # arrays print(bytes(array('h', [1, 2]))) print(bytes(array('I', [1, 2])))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_construct_endian.py
Python
apache-2.0
295
# test construction of bytes from different objects # long ints print(ord(bytes([14953042807679334000 & 0xff])))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_construct_intbig.py
Python
apache-2.0
114
try: bytes.count except AttributeError: print("SKIP") raise SystemExit print(b"".count(b"")) print(b"".count(b"a")) print(b"a".count(b"")) print(b"a".count(b"a")) print(b"a".count(b"b")) print(b"b".count(b"a")) print(b"aaa".count(b"")) print(b"aaa".count(b"a")) print(b"aaa".count(b"aa")) print(b"aaa".coun...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_count.py
Python
apache-2.0
1,302
print(b"hello world".find(b"ll")) print(b"hello world".find(b"ll", None)) print(b"hello world".find(b"ll", 1)) print(b"hello world".find(b"ll", 1, None)) print(b"hello world".find(b"ll", None, None)) print(b"hello world".find(b"ll", 1, -1)) print(b"hello world".find(b"ll", 1, 1)) print(b"hello world".find(b"ll", 1, 2))...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_find.py
Python
apache-2.0
890
# This test requires CPython3.5 try: b'' % () except TypeError: print("SKIP") raise SystemExit print(b"%%" % ()) print(b"=%d=" % 1) print(b"=%d=%d=" % (1, 2)) print(b"=%s=" % b"str") print(b"=%r=" % b"str")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_format_modulo.py
Python
apache-2.0
222
# construct a bytes object from a generator def gen(): for i in range(4): yield i print(bytes(gen()))
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_gen.py
Python
apache-2.0
114
b1 = b"long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long bytes long ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_large.py
Python
apache-2.0
816
# basic multiplication print(b'0' * 5) # check negative, 0, positive; lhs and rhs multiplication for i in (-4, -2, 0, 2, 4): print(i * b'12') print(b'12' * i) # check that we don't modify existing object a = b'123' c = a * 3 print(a, c)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_mult.py
Python
apache-2.0
247
try: str.partition except AttributeError: print("SKIP") raise SystemExit print(b"asdf".partition(b'g')) print(b"asdf".partition(b'a')) print(b"asdf".partition(b's')) print(b"asdf".partition(b'f')) print(b"asdf".partition(b'd')) print(b"asdf".partition(b'asd')) print(b"asdf".partition(b'sdf')) print(b"asdf"...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_partition.py
Python
apache-2.0
836
print(b"".replace(b"a", b"b")) print(b"aaa".replace(b"a", b"b", 0)) print(b"aaa".replace(b"a", b"b", -5)) print(b"asdfasdf".replace(b"a", b"b")) print(b"aabbaabbaabbaa".replace(b"aa", b"cc", 3)) print(b"a".replace(b"aa", b"bb")) print(b"testingtesting".replace(b"ing", b"")) print(b"testINGtesting".replace(b"ing", b"ING...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_replace.py
Python
apache-2.0
452
# default separator (whitespace) print(b"a b".split()) print(b" a b ".split(None)) print(b" a b ".split(None, 1)) print(b" a b ".split(None, 2)) print(b" a b c ".split(None, 1)) print(b" a b c ".split(None, 0)) print(b" a b c ".split(None, -1)) # empty separator should fail try: ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_split.py
Python
apache-2.0
752
print(b"".strip()) print(b" \t\n\r\v\f".strip()) print(b" T E S T".strip()) print(b"abcabc".strip(b"ce")) print(b"aaa".strip(b"b")) print(b"abc efg ".strip(b"g a")) print(b' spacious '.lstrip()) print(b'www.example.com'.lstrip(b'cmowz.')) print(b' spacious '.rstrip()) print(b'mississippi'.rstrip(b'ipz')) # ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_strip.py
Python
apache-2.0
425
# test [...] of bytes print(b'123'[0]) print(b'123'[1]) print(b'123'[-1]) try: b'123'[1] = 4 except TypeError: print('TypeError') try: del b'123'[1] except TypeError: print('TypeError')
YifuLiu/AliOS-Things
components/py_engine/tests/basics/bytes_subscr.py
Python
apache-2.0
205
# basic class def go(): class C: def f(): print(1) def g(self): print(2) def set(self, value): self.value = value def print(self): print(self.value) C.f() C() C().g() o = C() o.set(3) o.print() C.set(o...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class1.py
Python
apache-2.0
346
# class with __init__ class C1: def __init__(self): self.x = 1 c1 = C1() print(type(c1) == C1) print(c1.x) class C2: def __init__(self, x): self.x = x c2 = C2(4) print(type(c2) == C2) print(c2.x) # __init__ should return None class C3: def __init__(self): return 10 try: C3()...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class2.py
Python
apache-2.0
362
# inheritance class A: def a(): print('A.a() called') class B(A): pass print(type(A)) print(type(B)) print(issubclass(A, A)) print(issubclass(A, B)) print(issubclass(B, A)) print(issubclass(B, B)) print(isinstance(A(), A)) print(isinstance(A(), B)) print(isinstance(B(), A)) print(isinstance(B(), B)...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class3.py
Python
apache-2.0
335
# test for type.__bases__ implementation if not hasattr(object, '__bases__'): print("SKIP") raise SystemExit class A: pass class B(object): pass class C(B): pass class D(C, A): pass # Check the attribute exists print(hasattr(A, '__bases__')) print(hasattr(B, '__bases__')) print(hasattr(C, ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_bases.py
Python
apache-2.0
886
# test for correct binding of self when accessing attr of an instance class A: def __init__(self, arg): self.val = arg def __str__(self): return 'A.__str__ ' + str(self.val) def __call__(self, arg): return 'A.__call__', arg def foo(self, arg): return 'A.foo', self.val, a...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_bind_self.py
Python
apache-2.0
1,356
class foo(object): def __init__(self, value): self.x = value def __eq__(self, other): print('eq') return self.x == other.x def __lt__(self, other): print('lt') return self.x < other.x def __gt__(self, other): print('gt') return self.x > other.x ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_binop.py
Python
apache-2.0
687
class C1: def __call__(self, val): print('call', val) return 'item' class C2: def __getattr__(self, k): pass c1 = C1() print(c1(1)) c2 = C2() try: print(c2(1)) except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_call.py
Python
apache-2.0
241
# A contains everything class A: def __contains__(self, key): return True a = A() print(True in a) print(1 in a) print(() in a) # B contains given things class B: def __init__(self, items): self.items = items def __contains__(self, key): return key in self.items b = B([]) print(1 ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_contains.py
Python
apache-2.0
382
# test __delattr__ and __setattr__ # feature test for __setattr__/__delattr__ try: class Test(): def __delattr__(self, attr): pass del Test().noexist except AttributeError: print('SKIP') raise SystemExit # this class just prints the calls to see if they were executed class A(): def __getat...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_delattr_setattr.py
Python
apache-2.0
2,354
class Descriptor: def __get__(self, obj, cls): print('get') print(type(obj) is Main) print(cls is Main) return 'result' def __set__(self, obj, val): print('set') print(type(obj) is Main) print(val) def __delete__(self, obj): print('delete') ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_descriptor.py
Python
apache-2.0
619
# test __dict__ attribute of a class if not hasattr(int, "__dict__"): print("SKIP") raise SystemExit # dict of a built-in type print("from_bytes" in int.__dict__) # dict of a user class class Foo: a = 1 b = "bar" d = Foo.__dict__ print(d["a"], d["b"]) # dict of a class that has no locals_dict (...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_dict.py
Python
apache-2.0
389
class A(): pass
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_emptybases.py
Python
apache-2.0
20
# test that __getattr__ and instance members don't override builtins class C: def __init__(self): self.__add__ = lambda: print('member __add__') def __add__(self, x): print('__add__') def __getattr__(self, attr): print('__getattr__', attr) return None c = C() c.add # should ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_getattr.py
Python
apache-2.0
433
class A: def __init__(self, x): print('A init', x) self.x = x def f(self): print(self.x, self.y) class B(A): def __init__(self, x, y): A.__init__(self, x) print('B init', x, y) self.y = y def g(self): print(self.x, self.y) A(1) b = B(1, 2) b.f(...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_inherit1.py
Python
apache-2.0
328
# test multiple inheritance of user classes class A: def __init__(self, x): print('A init', x) self.x = x def f(self): print(self.x) def f2(self): print(self.x) class B: def __init__(self, x): print('B init', x) self.x = x def f(self): pri...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_inherit_mul.py
Python
apache-2.0
632
# Case 1: Immutable object (e.g. number-like) # __iadd__ should not be defined, will be emulated using __add__ class A: def __init__(self, v): self.v = v def __add__(self, o): return A(self.v + o.v) def __repr__(self): return "A({})".format(self.v) a = A(5) b = a a += A(3) print...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_inplace_op.py
Python
apache-2.0
871
# Test inplace special methods enabled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS class A: def __imul__(self, other): print("__imul__") return self def __imatmul__(self, other): print("__imatmul__") return self def __ifloordiv__(self, other): print("__ifloordiv__")...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_inplace_op2.py
Python
apache-2.0
1,293
# test that we can override a class method with an instance method class A: def foo(self): return 1 a = A() print(a.foo()) a.foo = lambda:2 print(a.foo())
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_instance_override.py
Python
apache-2.0
169
# test class with __getitem__, __setitem__, __delitem__ methods class C: def __getitem__(self, item): print('get', item) return 'item' def __setitem__(self, item, value): print('set', item, value) def __delitem__(self, item): print('del', item) c = C() print(c[1]) c[1] = ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_item.py
Python
apache-2.0
435
# converting user instance to buffer class C: pass c = C() try: d = bytes(c) except TypeError: print('TypeError')
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_misc.py
Python
apache-2.0
127
try: # If we don't expose object.__new__ (small ports), there's # nothing to test. object.__new__ except AttributeError: print("SKIP") raise SystemExit class A: def __new__(cls): print("A.__new__") return super(cls, A).__new__(cls) def __init__(self): print("A.__ini...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_new.py
Python
apache-2.0
1,254
# Test that returning of NotImplemented from binary op methods leads to # TypeError. try: NotImplemented except NameError: print("SKIP") raise SystemExit class C: def __init__(self, value): self.value = value def __str__(self): return "C({})".format(self.value) def __add__(sel...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_notimpl.py
Python
apache-2.0
971
# test class with __add__ and __sub__ methods class C: def __init__(self, value): self.value = value def __add__(self, rhs): print(self.value, '+', rhs) def __sub__(self, rhs): print(self.value, '-', rhs) c = C(0) c + 1 c - 2
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_number.py
Python
apache-2.0
266
# test using an OrderedDict as the locals to construct a class try: from ucollections import OrderedDict except ImportError: try: from collections import OrderedDict except ImportError: print("SKIP") raise SystemExit if not hasattr(int, "__dict__"): print("SKIP") raise Syst...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_ordereddict.py
Python
apache-2.0
448
class A: def __init__(self, v): self.v = v def __add__(self, o): if isinstance(o, A): return A(self.v + o.v) return A(self.v + o) def __radd__(self, o): return A(self.v + o) def __repr__(self): return "A({})".format(self.v) print(A(3) + 1) print(2...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_reverse_op.py
Python
apache-2.0
329
# test static and class methods class C: @staticmethod def f(rhs): print('f', rhs) @classmethod def g(self, rhs): print('g', rhs) # builtin wrapped in staticmethod @staticmethod def __sub__(rhs): print('sub', rhs) # builtin wrapped in classmethod @classmetho...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_staticclassmethod.py
Python
apache-2.0
772
# store to class vs instance class C: pass c = C() c.x = 1 print(c.x) C.x = 2 C.y = 3 print(c.x, c.y) print(C.x, C.y) print(C().x, C().y) c = C() print(c.x) c.x = 4 print(c.x)
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_store.py
Python
apache-2.0
182
# Inspired by urlparse.py from CPython 3.3 stdlib # There was a bug in MicroPython that under some conditions class stored # in instance attribute later was returned "bound" as if it was a method, # which caused class constructor to receive extra argument. try: from collections import namedtuple except ImportError:...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_store_class.py
Python
apache-2.0
1,488
class C1: def __init__(self, value): self.value = value def __str__(self): return "str<C1 {}>".format(self.value) class C2: def __init__(self, value): self.value = value def __repr__(self): return "repr<C2 {}>".format(self.value) class C3: def __init__(self, value...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_str.py
Python
apache-2.0
794
class Base: def __init__(self): self.a = 1 def meth(self): print("in Base meth", self.a) class Sub(Base): def meth(self): print("in Sub meth") return super().meth() a = Sub() a.meth() # printing super class A: def p(self): print(str(super())[:18]) A().p() ...
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_super.py
Python
apache-2.0
1,017
# test using the name "super" as a local variable class A: def foo(self): super = [1, 2] super.pop() print(super) A().foo()
YifuLiu/AliOS-Things
components/py_engine/tests/basics/class_super_aslocal.py
Python
apache-2.0
154