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 construction of bytearray from array with float type try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit print(bytearray(array("f", [1, 2.5])))
YifuLiu/AliOS-Things
components/py_engine/tests/float/bytearray_construct_endian.py
Python
apache-2.0
267
# test construction of bytes from array with float type try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit print(bytes(array("f", [1, 2.5])))
YifuLiu/AliOS-Things
components/py_engine/tests/float/bytes_construct_endian.py
Python
apache-2.0
259
# test the functions imported from cmath try: from cmath import * except ImportError: print("SKIP") raise SystemExit # make sure these constants exist in cmath print("%.5g" % e) print("%.5g" % pi) test_values_non_zero = [] base_values = (0.0, 0.5, 1.2345, 10.0) for r in base_values: for i in base_val...
YifuLiu/AliOS-Things
components/py_engine/tests/float/cmath_fun.py
Python
apache-2.0
1,792
# test the special functions imported from cmath try: from cmath import * log10 except (ImportError, NameError): print("SKIP") raise SystemExit test_values_non_zero = [] base_values = (0.0, 0.5, 1.2345, 10.0) for r in base_values: for i in base_values: if r != 0.0 or i != 0.0: ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/cmath_fun_special.py
Python
apache-2.0
835
# test basic complex number functionality # constructor print(complex(1)) print(complex(1.2)) print(complex(1.2j)) print(complex("1")) print(complex("1.2")) print(complex("1.2j")) print(complex(1, 2)) print(complex(1j, 2j)) # unary ops print(bool(1j)) print(+(1j)) print(-(1 + 2j)) # binary ops print(1j + False) prin...
YifuLiu/AliOS-Things
components/py_engine/tests/float/complex1.py
Python
apache-2.0
2,303
# test basic complex number functionality # convert bignum to complex on rhs ans = 1j + (1 << 70) print("%.5g %.5g" % (ans.real, ans.imag))
YifuLiu/AliOS-Things
components/py_engine/tests/float/complex1_intbig.py
Python
apache-2.0
141
# test complex interacting with special reverse methods class A: def __radd__(self, x): print("__radd__") return 2 print(1j + A())
YifuLiu/AliOS-Things
components/py_engine/tests/float/complex_reverse_op.py
Python
apache-2.0
155
# test complex interacting with special methods class A: def __add__(self, x): print("__add__") return 1 print(A() + 1j)
YifuLiu/AliOS-Things
components/py_engine/tests/float/complex_special_methods.py
Python
apache-2.0
145
# test basic float capabilities # literals print(0.12) print(1.0) print(1.2) print(0e0) print(0e0) print(0e-0) # float construction print(float(1.2)) print(float("1.2")) print(float("+1")) print(float("1e1")) print(float("1e+1")) print(float("1e-1")) print(float("inf")) print(float("-inf")) print(float("INF")) print(...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float1.py
Python
apache-2.0
2,195
# check cases converting float to int, requiring double precision float try: import ustruct as struct import usys as sys except: import struct import sys maxsize_bits = 0 maxsize = sys.maxsize while maxsize: maxsize >>= 1 maxsize_bits += 1 # work out configuration values is_64bit = maxsize_bi...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float2int_doubleprec_intbig.py
Python
apache-2.0
2,920
# check cases converting float to int, relying only on single precision float try: import ustruct as struct import usys as sys except: import struct import sys maxsize_bits = 0 maxsize = sys.maxsize while maxsize: maxsize >>= 1 maxsize_bits += 1 # work out configuration values is_64bit = maxs...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float2int_fp30_intbig.py
Python
apache-2.0
2,800
# check cases converting float to int, relying only on single precision float try: import ustruct as struct import usys as sys except: import struct import sys maxsize_bits = 0 maxsize = sys.maxsize while maxsize: maxsize >>= 1 maxsize_bits += 1 # work out configuration values is_64bit = maxs...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float2int_intbig.py
Python
apache-2.0
2,815
try: from uarray import array except ImportError: try: from array import array except ImportError: print("SKIP") raise SystemExit def test(a): print(a) a.append(1.2) print(len(a), "%.3f" % a[0]) a.append(1) a.append(False) print(len(a), "%.3f %.3f" % (a[1], ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_array.py
Python
apache-2.0
478
# Extended float comparisons class Foo: pass foo = Foo() print(foo == 1.0) print(1.0 == foo) print(1.0 == Foo) print(1.0 == []) print(1.0 == {}) try: print(foo < 1.0) except TypeError: print("TypeError") try: print(1.0 < foo) except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_compare.py
Python
apache-2.0
290
# test floating point floor divide and modulus # it has some tricky corner cases def test(x, y): div, mod = divmod(x, y) print("%.8f %.8f %.8f %.8f" % (x // y, x % y, div, mod)) print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-15) test(1.23456, 0.7) test(-1.23456, 0.7) test(1.23456, -0.7) ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_divmod.py
Python
apache-2.0
524
# test floating point floor divide and modulus # it has some tricky corner cases # pyboard has 32-bit floating point and gives different (but still # correct) answers for certain combinations of divmod arguments. def test(x, y): div, mod = divmod(x, y) print(div == x // y, mod == x % y, abs(div * y + mod - x...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_divmod_relaxed.py
Python
apache-2.0
707
# test float formatting # general rounding for val in (116, 1111, 1234, 5010, 11111): print("%.0f" % val) print("%.1f" % val) print("%.3f" % val) # make sure rounding is done at the correct precision for prec in range(8): print(("%%.%df" % prec) % 6e-5) # check certain cases that had a digit value of...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_format.py
Python
apache-2.0
607
# test parsing of floats inf = float("inf") # it shouldn't matter where the decimal point is if the exponent balances the value print(float("1234") - float("0.1234e4")) print(float("1.015625") - float("1015625e-6")) # very large integer part with a very negative exponent should cancel out print("%.4e" % float("9" * ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_parse.py
Python
apache-2.0
1,228
# test parsing of floats, requiring double-precision # very large integer part with a very negative exponent should cancel out print(float("9" * 400 + "e-100")) print(float("9" * 400 + "e-200")) print(float("9" * 400 + "e-400")) # many fractional digits print(float("." + "9" * 400)) print(float("." + "9" * 400 + "e10...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_parse_doubleprec.py
Python
apache-2.0
755
# test struct package with floats try: try: import ustruct as struct except: import struct except ImportError: print("SKIP") raise SystemExit i = 1.0 + 1 / 2 # TODO: it looks like '=' format modifier is not yet supported # for fmt in ('f', 'd', '>f', '>d', '<f', '<d', '=f', '=d'): for f...
YifuLiu/AliOS-Things
components/py_engine/tests/float/float_struct.py
Python
apache-2.0
498
# Test behaviour of inf and nan in basic float operations inf = float("inf") nan = float("nan") values = (-2, -1, 0, 1, 2, inf, nan) for x in values: for y in values: print(x, y) print(" + - *", x + y, x - y, x * y) try: print(" /", x / y) except ZeroDivisionError: ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/inf_nan_arith.py
Python
apache-2.0
587
# test bignum operation with float/complex i = 1 << 65 # convert bignum to float on rhs print("%.5g" % (2.0 * i)) # negative bignum as float print("%.5g" % float(-i)) # this should convert to float print("%.5g" % (i / 5)) # these should delegate to float print("%.5g" % (i * 1.2)) print("%.5g" % (i / 1.2)) # this ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/int_big_float.py
Python
apache-2.0
553
try: 1 / 0 except ZeroDivisionError: print("ZeroDivisionError") try: 0 ** -1 except ZeroDivisionError: print("ZeroDivisionError")
YifuLiu/AliOS-Things
components/py_engine/tests/float/int_divzero.py
Python
apache-2.0
147
# negative power should produce float x = 2 print(x ** -2) x = 3 x **= -2 print("%.5f" % x)
YifuLiu/AliOS-Things
components/py_engine/tests/float/int_power.py
Python
apache-2.0
94
# since black code formatter does not allow leading decimal point with nothing # before it, we need to test it explicitly # fmt: off print(.1) # fmt: on
YifuLiu/AliOS-Things
components/py_engine/tests/float/lexer.py
Python
apache-2.0
154
x = [1, 2] print(x[1]) try: print(x[1.0]) except TypeError: print("TypeError")
YifuLiu/AliOS-Things
components/py_engine/tests/float/list_index.py
Python
apache-2.0
89
# Tests domain errors in math functions try: import math except ImportError: print("SKIP") raise SystemExit inf = float("inf") nan = float("nan") # single argument functions for name, f, args in ( ("fabs", math.fabs, ()), ("ceil", math.ceil, ()), ("floor", math.floor, ()), ("trunc", math....
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_domain.py
Python
apache-2.0
1,490
# Tests domain errors in special math functions try: import math math.erf except (ImportError, AttributeError): print("SKIP") raise SystemExit inf = float("inf") nan = float("nan") # single argument functions for name, f, args in ( ("expm1", math.exp, ()), ("log2", math.log2, (-1, 0)), (...
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_domain_special.py
Python
apache-2.0
935
try: import math math.factorial except (ImportError, AttributeError): print("SKIP") raise SystemExit for fun in (math.factorial,): for x in range(-1, 30): try: print("%d" % fun(x)) except ValueError as e: print("ValueError")
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_factorial_intbig.py
Python
apache-2.0
288
# Tests the functions imported from math try: from math import * except ImportError: print("SKIP") raise SystemExit test_values = [-100.0, -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.0] test_values_small = [ -10.0, -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 10.0, ] # so we don'...
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_fun.py
Python
apache-2.0
2,517
# Test the bool functions from math try: from math import isfinite, isnan, isinf except ImportError: print("SKIP") raise SystemExit test_values = [1, 0, -1, 1.0, 0.0, -1.0, float("NaN"), float("Inf"), -float("NaN"), -float("Inf")] functions = [isfinite, isnan, isinf] for val in test_values: for f in...
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_fun_bool.py
Python
apache-2.0
354
# test the math functions that return ints try: import math except ImportError: print("SKIP") raise SystemExit for fun in (math.ceil, math.floor, math.trunc): for x in (-1.6, -0.2, 0, 0.6, 1.4, float("inf"), float("nan")): try: print(fun(x)) except (ValueError, OverflowErro...
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_fun_int.py
Python
apache-2.0
356
# test the math functions that return ints, with very large results try: import math except ImportError: print("SKIP") raise SystemExit for fun in (math.ceil, math.floor, math.trunc): for x in (-1e25, 1e25): print("%.3g" % fun(x))
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_fun_intbig.py
Python
apache-2.0
257
# test the special functions imported from math try: from math import * erf except (ImportError, NameError): print("SKIP") raise SystemExit test_values = [ -8.0, -2.5, -1, -0.5, 0.0, 0.5, 2.5, 8.0, ] pos_test_values = [ 0.001, 0.1, 0.5, 1.0, 1.5, ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_fun_special.py
Python
apache-2.0
1,094
# test math.isclose (appeared in Python 3.5) try: from math import isclose except ImportError: print("SKIP") raise SystemExit def test(a, b, **kwargs): print(isclose(a, b, **kwargs)) def test_combinations(a, b, **kwargs): test(a, a, **kwargs) test(a, b, **kwargs) test(b, a, **kwargs) ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/math_isclose.py
Python
apache-2.0
1,105
# tests for things that only Python 3.6 supports, needing floats # underscores in numeric literals print(1_000.1_8) print("%.2g" % 1e1_2) # underscore supported by int/float constructors print(float("1_2_3")) print(float("1_2_3.4")) print("%.2g" % float("1e1_3"))
YifuLiu/AliOS-Things
components/py_engine/tests/float/python36.py
Python
apache-2.0
266
def test(fmt, *args): print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<") test("{:10.4}", 123.456) test("{:10.4e}", 123.456) test("{:10.4e}", -123.456) test("{:10.4f}", 123.456) test("{:10.4f}", -123.456) test("{:10.4g}", 123.456) test("{:10.4g}", -123.456) test("{:10.4n}", 123.456) test("{:e}", 100) test(...
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format.py
Python
apache-2.0
1,042
# Change the following to True to get a much more comprehensive set of tests # to run, albeit, which take considerably longer. full_tests = False def test(fmt, *args): print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<") def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format2.py
Python
apache-2.0
4,610
def test(fmt, *args): print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<") test("{:10.4}", 123.456) test("{:10.4e}", 123.456) test("{:10.4e}", -123.456) # test("{:10.4f}", 123.456) # test("{:10.4f}", -123.456) test("{:10.4g}", 123.456) test("{:10.4g}", -123.456) test("{:10.4n}", 123.456) test("{:e}", 100) t...
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format_fp30.py
Python
apache-2.0
1,010
print("%s" % 1.0) print("%r" % 1.0) print("%d" % 1.0) print("%i" % 1.0) print("%u" % 1.0) # these 3 have different behaviour in Python 3.x versions # uPy raises a TypeError, following Python 3.5 (earlier versions don't) # print("%x" % 18.0) # print("%o" % 18.0) # print("%X" % 18.0) print("%e" % 1.23456) print("%E" %...
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format_modulo.py
Python
apache-2.0
1,363
# test formatting floats with large precision, that it doesn't overflow the buffer def test(num, num_str): if num == float("inf") or num == 0.0 and num_str != "0.0": # skip numbers that overflow or underflow the FP precision return for kind in ("e", "f", "g"): # check precision either ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format_modulo2.py
Python
apache-2.0
836
# test formatting floats with large precision, that it doesn't overflow the buffer def test(num, num_str): if num == float("inf") or num == 0.0 and num_str != "0.0": # skip numbers that overflow or underflow the FP precision return for kind in ("e", "f", "g"): # check precision either ...
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format_modulo2_intbig.py
Python
apache-2.0
804
# uPy and CPython outputs differ for the following print("%.1g" % -9.9) # round up 'g' with '-' sign print("%.2g" % 99.9) # round up
YifuLiu/AliOS-Things
components/py_engine/tests/float/string_format_modulo3.py
Python
apache-2.0
135
# Test true-ish value handling if not 0.0: print("float 0") if not 0 + 0j: print("complex 0")
YifuLiu/AliOS-Things
components/py_engine/tests/float/true_value.py
Python
apache-2.0
104
# float types print(float) print(complex) print(type(float()) == float) print(type(complex()) == complex) print(type(0.0) == float) print(type(1j) == complex) # hashing float types d = dict() d[float] = complex d[complex] = float print(len(d))
YifuLiu/AliOS-Things
components/py_engine/tests/float/types.py
Python
apache-2.0
249
# test calling builtin import function # basic test __import__("builtins") # first arg should be a string try: __import__(1) except TypeError: print("TypeError") # module name should not be empty try: __import__("") except ValueError: print("ValueError") # level argument should be non-negative try: ...
YifuLiu/AliOS-Things
components/py_engine/tests/import/builtin_import.py
Python
apache-2.0
407
import gen_context2 GLOBAL = "GLOBAL" def gen(): print(GLOBAL) yield 1 gen_context2.call(gen())
YifuLiu/AliOS-Things
components/py_engine/tests/import/gen_context.py
Python
apache-2.0
109
def call(g): next(g)
YifuLiu/AliOS-Things
components/py_engine/tests/import/gen_context2.py
Python
apache-2.0
25
import import1b print(import1b.var)
YifuLiu/AliOS-Things
components/py_engine/tests/import/import1a.py
Python
apache-2.0
37
var = 123 def throw(): raise ValueError
YifuLiu/AliOS-Things
components/py_engine/tests/import/import1b.py
Python
apache-2.0
46
from import1b import var print(var) from import1b import var as var2 print(var2)
YifuLiu/AliOS-Things
components/py_engine/tests/import/import2a.py
Python
apache-2.0
84
from import1b import * print(var)
YifuLiu/AliOS-Things
components/py_engine/tests/import/import3a.py
Python
apache-2.0
35
import import1b print(import1b.__file__)
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_file.py
Python
apache-2.0
42
from import_long_dyn2 import *
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_long_dyn.py
Python
apache-2.0
31
globals()["long_long_very_long_long_name"] = 1
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_long_dyn2.py
Python
apache-2.0
47
# test overriding __import__ combined with importing from the filesystem def custom_import(name, globals, locals, fromlist, level): print("import", name, fromlist, level) class M: var = 456 return M orig_import = __import__ try: __import__("builtins").__import__ = custom_import except Attr...
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_override.py
Python
apache-2.0
480
import pkg.mod print(pkg.__name__) print(pkg.mod.__name__) print(pkg.mod.foo()) # Import 2nd time, must be same module objects pkg_ = __import__("pkg.mod") print(pkg_ is not pkg.mod) print(pkg_ is pkg) print(pkg_.mod is pkg.mod) # import using "as" import pkg.mod as mm print(mm is pkg.mod) print(mm.foo())
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg1.py
Python
apache-2.0
311
from pkg.mod import foo try: pkg except NameError: print("NameError") try: pkg.mod except NameError: print("NameError") print(foo()) # Import few times, must be same module objects mod_1 = __import__("pkg.mod", None, None, ("foo",)) mod_2 = __import__("pkg.mod", None, None, ("foo",)) print(mod_1 is mo...
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg2.py
Python
apache-2.0
379
from pkg import mod print(mod.foo()) import pkg.mod print(mod is pkg.mod)
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg3.py
Python
apache-2.0
77
# Testing that "recursive" imports (pkg2/__init__.py imports from pkg2) work import pkg2
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg4.py
Python
apache-2.0
89
# This tests relative imports as used in pkg3 import pkg3 import pkg3.mod1 import pkg3.subpkg1.mod1 pkg3.subpkg1.mod1.foo()
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg5.py
Python
apache-2.0
125
# This tests relative imports as used in pkg6 import pkg6
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg6.py
Python
apache-2.0
58
# This tests ... relative imports as used in pkg7 and imports beyond package root import pkg7.subpkg1.subpkg2.mod3
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg7.py
Python
apache-2.0
115
# import with no __init__.py files import pkg8.mod
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_pkg8.py
Python
apache-2.0
51
# test errors with import * # 'import *' is not allowed in function scope try: exec("def foo(): from x import *") except SyntaxError as er: print("function", "SyntaxError") # 'import *' is not allowed in class scope try: exec("class C: from x import *") except SyntaxError as er: print("class", "Syntax...
YifuLiu/AliOS-Things
components/py_engine/tests/import/import_star_error.py
Python
apache-2.0
328
# test __getattr__ on module # ensure that does_not_exist doesn't exist to start with this = __import__(__name__) try: this.does_not_exist assert False except AttributeError: pass # define __getattr__ def __getattr__(attr): if attr == "does_not_exist": return False raise AttributeError #...
YifuLiu/AliOS-Things
components/py_engine/tests/import/module_getattr.py
Python
apache-2.0
540
def foo(): return 42
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg/mod.py
Python
apache-2.0
25
from pkg2 import mod1
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg2/__init__.py
Python
apache-2.0
22
from pkg2 import mod2
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg2/mod1.py
Python
apache-2.0
22
print("in mod2")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg2/mod2.py
Python
apache-2.0
17
print("pkg __name__:", __name__)
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg3/__init__.py
Python
apache-2.0
33
print("mod1 __name__:", __name__) from . import mod2
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg3/mod1.py
Python
apache-2.0
53
print("mod2 __name__:", __name__) print("in mod2") def foo(): print("mod2.foo()")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg3/mod2.py
Python
apache-2.0
88
print("subpkg1 __name__:", __name__)
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg3/subpkg1/__init__.py
Python
apache-2.0
37
print("subpkg1.mod1 __name__:", __name__) from ..mod2 import foo
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg3/subpkg1/mod1.py
Python
apache-2.0
65
from .x import * print("init")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg6/__init__.py
Python
apache-2.0
32
from .y import * print("x")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg6/x/__init__.py
Python
apache-2.0
29
print("y")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg6/x/y.py
Python
apache-2.0
11
print("pkg __name__:", __name__)
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg7/__init__.py
Python
apache-2.0
33
print("mod1") foo = "mod1.foo"
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg7/mod1.py
Python
apache-2.0
31
print("mod2") bar = "mod2.bar"
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg7/mod2.py
Python
apache-2.0
31
print("pkg __name__:", __name__)
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg7/subpkg1/__init__.py
Python
apache-2.0
33
print("pkg __name__:", __name__)
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg7/subpkg1/subpkg2/__init__.py
Python
apache-2.0
33
from ... import mod1 from ...mod2 import bar print(mod1.foo) print(bar) # attempted relative import beyond top-level package try: from .... import mod1 except ImportError: print("ImportError")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg7/subpkg1/subpkg2/mod3.py
Python
apache-2.0
203
print("foo")
YifuLiu/AliOS-Things
components/py_engine/tests/import/pkg8/mod.py
Python
apache-2.0
13
try: from . import foo except: print("Invalid relative import caught")
YifuLiu/AliOS-Things
components/py_engine/tests/import/rel_import_inv.py
Python
apache-2.0
79
# Regression test for #290 - throwing exception in another module led to # its namespace stick and namespace of current module not coming back. import import1b def func1(): print("func1") def func2(): try: import1b.throw() except ValueError: pass func1() func2()
YifuLiu/AliOS-Things
components/py_engine/tests/import/try_module.py
Python
apache-2.0
301
# test passing arguments @micropython.asm_thumb def arg0(): mov(r0, 1) print(arg0()) @micropython.asm_thumb def arg1(r0): add(r0, r0, 1) print(arg1(1)) @micropython.asm_thumb def arg2(r0, r1): add(r0, r0, r1) print(arg2(1, 2)) @micropython.asm_thumb def arg3(r0, r1, r2): add(r0, r0, r1) ...
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmargs.py
Python
apache-2.0
498
# test bcc instructions # at the moment only tests beq, narrow and wide versions @micropython.asm_thumb def f(r0): mov(r1, r0) mov(r0, 10) cmp(r1, 1) beq(end) mov(r0, 20) cmp(r1, 2) beq_n(end) mov(r0, 30) cmp(r1, 3) beq_w(end) mov(r0, 0) label(end) print(f(0)) pr...
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmbcc.py
Python
apache-2.0
354
@micropython.asm_thumb def clz(r0): clz(r0, r0) print(clz(0xF0)) print(clz(0x8000)) @micropython.asm_thumb def rbit(r0): rbit(r0, r0) print(hex(rbit(0xF0))) print(hex(rbit(0x8000)))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmbitops.py
Python
apache-2.0
196
# test bl and bx instructions @micropython.asm_thumb def f(r0): # jump over the internal functions b(entry) label(func1) add(r0, 2) bx(lr) label(func2) sub(r0, 1) bx(lr) label(entry) bl(func1) bl(func2) print(f(0)) print(f(1))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmblbx.py
Python
apache-2.0
278
# test constants in assembler @micropython.asm_thumb def c1(): movwt(r0, 0xFFFFFFFF) movwt(r1, 0xF0000000) sub(r0, r0, r1) print(hex(c1()))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmconst.py
Python
apache-2.0
156
@micropython.asm_thumb def sdiv(r0, r1): sdiv(r0, r0, r1) @micropython.asm_thumb def udiv(r0, r1): udiv(r0, r0, r1) print(sdiv(1234, 3)) print(sdiv(-1234, 3)) print(sdiv(1234, -3)) print(sdiv(-1234, -3)) print(udiv(1234, 3)) print(udiv(0xFFFFFFFF, 0x7FFFFFFF)) print(udiv(0xFFFFFFFF, 0xFFFFFFFF))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmdiv.py
Python
apache-2.0
310
@micropython.asm_thumb # r0 = r0+r1-r2 def add_sub(r0, r1, r2): vmov(s0, r0) vcvt_f32_s32(s0, s0) vmov(s1, r1) vcvt_f32_s32(s1, s1) vmov(s2, r2) vcvt_f32_s32(s2, s2) vadd(s0, s0, s1) vsub(s0, s0, s2) vcvt_s32_f32(s31, s0) vmov(r0, s31) print(add_sub(100, 20, 30))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmfpaddsub.py
Python
apache-2.0
307
@micropython.asm_thumb # test vcmp, vmrs def f(r0, r1): vmov(s0, r0) vcvt_f32_s32(s0, s0) vmov(s1, r1) vcvt_f32_s32(s1, s1) vcmp(s1, s0) vmrs(r0, FPSCR) mov(r1, 28) lsr(r0, r1) print(f(0, 1)) print(f(1, 1)) print(f(1, 0))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmfpcmp.py
Python
apache-2.0
257
import uarray as array @micropython.asm_thumb # test vldr, vstr def arrayadd(r0): vldr(s0, [r0, 0]) vldr(s1, [r0, 4]) vadd(s2, s0, s1) vstr(s2, [r0, 8]) z = array.array("f", [2, 4, 10]) arrayadd(z) print(z[2])
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmfpldrstr.py
Python
apache-2.0
231
@micropython.asm_thumb # r0 = (int)(r0*r1/r2) def muldiv(r0, r1, r2): vmov(s0, r0) vcvt_f32_s32(s0, s0) vmov(s1, r1) vcvt_f32_s32(s1, s1) vmov(s2, r2) vcvt_f32_s32(s2, s2) vmul(s7, s0, s1) vdiv(s8, s7, s2) vcvt_s32_f32(s31, s8) vmov(r0, s31) print(muldiv(100, 10, 50))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmfpmuldiv.py
Python
apache-2.0
312
# test vsqrt, vneg @micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1) def sqrt_test(r0, r1): vmov(s1, r0) vcvt_f32_s32(s1, s1) vsqrt(s1, s1) vmov(s2, r1) vcvt_f32_s32(s2, s2) vmul(s0, s1, s2) vneg(s7, s0) vcvt_s32_f32(s31, s7) vmov(r0, s31) print(sqrt_test(256, 10))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmfpsqrt.py
Python
apache-2.0
305
# test it instruction @micropython.asm_thumb def f(r0, r1): cmp(r0, r1) it(eq) mov(r0, 100) print(f(0, 0), f(1, 2)) @micropython.asm_thumb def g(r0, r1): cmp(r0, r1) ite(eq) mov(r0, 100) mov(r0, 200) print(g(0, 0), g(0, 1))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmit.py
Python
apache-2.0
260
@micropython.asm_thumb def f(r0, r1, r2): push({r0}) push({r1, r2}) pop({r0}) pop({r1, r2}) print(f(0, 1, 2))
YifuLiu/AliOS-Things
components/py_engine/tests/inlineasm/asmpushpop.py
Python
apache-2.0
128