summaryrefslogtreecommitdiff
path: root/tests/micropython
diff options
context:
space:
mode:
Diffstat (limited to 'tests/micropython')
-rw-r--r--tests/micropython/const2.py4
-rw-r--r--tests/micropython/heapalloc_yield_from.py2
-rw-r--r--tests/micropython/native_closure.py3
-rw-r--r--tests/micropython/native_gen.py2
-rw-r--r--tests/micropython/native_misc.py4
-rw-r--r--tests/micropython/native_try.py3
-rw-r--r--tests/micropython/native_try_deep.py1
-rw-r--r--tests/micropython/native_with.py1
-rw-r--r--tests/micropython/viper_args.py1
-rw-r--r--tests/micropython/viper_cond.py3
-rw-r--r--tests/micropython/viper_misc.py17
-rw-r--r--tests/micropython/viper_misc2.py1
-rw-r--r--tests/micropython/viper_misc_intbig.py1
-rw-r--r--tests/micropython/viper_try.py3
-rw-r--r--tests/micropython/viper_types.py3
-rw-r--r--tests/micropython/viper_with.py1
16 files changed, 50 insertions, 0 deletions
diff --git a/tests/micropython/const2.py b/tests/micropython/const2.py
index ed4720122..d8b68c25f 100644
--- a/tests/micropython/const2.py
+++ b/tests/micropython/const2.py
@@ -11,6 +11,7 @@ import micropython as X
print(globals()["X"])
+
# function name that matches a constant
def X():
print("function X", X)
@@ -18,6 +19,7 @@ def X():
globals()["X"]()
+
# arguments that match a constant
def f(X, *Y, **Z):
pass
@@ -25,6 +27,7 @@ def f(X, *Y, **Z):
f(1)
+
# class name that matches a constant
class X:
def f(self):
@@ -33,6 +36,7 @@ class X:
globals()["X"]().f()
+
# constant within a class
class A:
C1 = const(4)
diff --git a/tests/micropython/heapalloc_yield_from.py b/tests/micropython/heapalloc_yield_from.py
index 58788b1db..950717189 100644
--- a/tests/micropython/heapalloc_yield_from.py
+++ b/tests/micropython/heapalloc_yield_from.py
@@ -2,6 +2,7 @@
import micropython
+
# Yielding from a function generator
def sub_gen(a):
for i in range(a):
@@ -18,6 +19,7 @@ print(next(g))
print(next(g))
micropython.heap_unlock()
+
# Yielding from a user iterator
class G:
def __init__(self):
diff --git a/tests/micropython/native_closure.py b/tests/micropython/native_closure.py
index 07014e90d..8182cfea7 100644
--- a/tests/micropython/native_closure.py
+++ b/tests/micropython/native_closure.py
@@ -1,5 +1,6 @@
# test native emitter can handle closures correctly
+
# basic closure
@micropython.native
def f():
@@ -15,6 +16,7 @@ def f():
print(f()())
+
# closing over an argument
@micropython.native
def f(x):
@@ -28,6 +30,7 @@ def f(x):
print(f(2)())
+
# closing over an argument and a normal local
@micropython.native
def f(x):
diff --git a/tests/micropython/native_gen.py b/tests/micropython/native_gen.py
index 62c324634..7e1ee25bc 100644
--- a/tests/micropython/native_gen.py
+++ b/tests/micropython/native_gen.py
@@ -1,5 +1,6 @@
# test for native generators
+
# simple generator with yield and return
@micropython.native
def gen1(x):
@@ -16,6 +17,7 @@ try:
except StopIteration as e:
print(e.args[0])
+
# using yield from
@micropython.native
def gen2(x):
diff --git a/tests/micropython/native_misc.py b/tests/micropython/native_misc.py
index f5ef807fe..f40fcb240 100644
--- a/tests/micropython/native_misc.py
+++ b/tests/micropython/native_misc.py
@@ -1,5 +1,6 @@
# tests for natively compiled functions
+
# basic test
@micropython.native
def native_test(x):
@@ -14,6 +15,7 @@ import gc
gc.collect()
native_test(3)
+
# native with 2 args
@micropython.native
def f(a, b):
@@ -22,6 +24,7 @@ def f(a, b):
f(1, 2)
+
# native with 3 args
@micropython.native
def f(a, b, c):
@@ -30,6 +33,7 @@ def f(a, b, c):
f(1, 2, 3)
+
# check not operator
@micropython.native
def f(a):
diff --git a/tests/micropython/native_try.py b/tests/micropython/native_try.py
index 492b59085..6a2152b28 100644
--- a/tests/micropython/native_try.py
+++ b/tests/micropython/native_try.py
@@ -1,5 +1,6 @@
# test native try handling
+
# basic try-finally
@micropython.native
def f():
@@ -14,6 +15,7 @@ try:
except NameError:
print("NameError")
+
# nested try-except with try-finally
@micropython.native
def f():
@@ -28,6 +30,7 @@ def f():
f()
+
# check that locals written to in try blocks keep their values
@micropython.native
def f():
diff --git a/tests/micropython/native_try_deep.py b/tests/micropython/native_try_deep.py
index 3d31248df..26b9243e0 100644
--- a/tests/micropython/native_try_deep.py
+++ b/tests/micropython/native_try_deep.py
@@ -1,5 +1,6 @@
# test native try handling
+
# deeply nested try (9 deep)
@micropython.native
def f():
diff --git a/tests/micropython/native_with.py b/tests/micropython/native_with.py
index 4e20b2385..9c0b98af9 100644
--- a/tests/micropython/native_with.py
+++ b/tests/micropython/native_with.py
@@ -21,6 +21,7 @@ def f():
f()
+
# nested with and try-except
@micropython.native
def f():
diff --git a/tests/micropython/viper_args.py b/tests/micropython/viper_args.py
index 8e3225331..27c73fa79 100644
--- a/tests/micropython/viper_args.py
+++ b/tests/micropython/viper_args.py
@@ -56,6 +56,7 @@ def f6(x1: int, x2: int, x3: int, x4: int, x5: int, x6: int):
f6(1, 2, 3, 4, 5, 6)
+
# test compiling *x, **x, * args (currently unsupported at runtime)
@micropython.viper
def f(*x, **y):
diff --git a/tests/micropython/viper_cond.py b/tests/micropython/viper_cond.py
index d5ebf837b..752261ff5 100644
--- a/tests/micropython/viper_cond.py
+++ b/tests/micropython/viper_cond.py
@@ -10,6 +10,7 @@ def f():
f()
+
# using True as a conditional
@micropython.viper
def f():
@@ -20,6 +21,7 @@ def f():
f()
+
# using an int as a conditional
@micropython.viper
def g():
@@ -30,6 +32,7 @@ def g():
g()
+
# using an int as a conditional that has the lower 16-bits clear
@micropython.viper
def h():
diff --git a/tests/micropython/viper_misc.py b/tests/micropython/viper_misc.py
index 41389c751..f9267f65c 100644
--- a/tests/micropython/viper_misc.py
+++ b/tests/micropython/viper_misc.py
@@ -1,5 +1,6 @@
import micropython
+
# viper function taking and returning ints
@micropython.viper
def viper_int(x: int, y: int) -> int:
@@ -8,6 +9,7 @@ def viper_int(x: int, y: int) -> int:
print(viper_int(1, 2))
+
# viper function taking and returning objects
@micropython.viper
def viper_object(x: object, y: object) -> object:
@@ -16,6 +18,7 @@ def viper_object(x: object, y: object) -> object:
print(viper_object(1, 2))
+
# return None as non-object (should return 0)
@micropython.viper
def viper_ret_none() -> int:
@@ -24,6 +27,7 @@ def viper_ret_none() -> int:
print(viper_ret_none())
+
# return Ellipsis as object
@micropython.viper
def viper_ret_ellipsis() -> object:
@@ -32,6 +36,7 @@ def viper_ret_ellipsis() -> object:
print(viper_ret_ellipsis())
+
# 3 args
@micropython.viper
def viper_3args(a: int, b: int, c: int) -> int:
@@ -40,6 +45,7 @@ def viper_3args(a: int, b: int, c: int) -> int:
print(viper_3args(1, 2, 3))
+
# 4 args
@micropython.viper
def viper_4args(a: int, b: int, c: int, d: int) -> int:
@@ -49,6 +55,7 @@ def viper_4args(a: int, b: int, c: int, d: int) -> int:
# viper call with 4 args not yet supported
# print(viper_4args(1, 2, 3, 4))
+
# a local (should have automatic type int)
@micropython.viper
def viper_local(x: int) -> int:
@@ -58,6 +65,7 @@ def viper_local(x: int) -> int:
print(viper_local(3))
+
# without type annotation, types should default to object
@micropython.viper
def viper_no_annotation(x, y):
@@ -66,6 +74,7 @@ def viper_no_annotation(x, y):
print(viper_no_annotation(4, 5))
+
# a for loop
@micropython.viper
def viper_for(a: int, b: int) -> int:
@@ -77,6 +86,7 @@ def viper_for(a: int, b: int) -> int:
print(viper_for(10, 10000))
+
# accessing a global
@micropython.viper
def viper_access_global():
@@ -87,6 +97,7 @@ def viper_access_global():
print(viper_access_global(), gl)
+
# calling print with object and int types
@micropython.viper
def viper_print(x, y: int):
@@ -95,6 +106,7 @@ def viper_print(x, y: int):
viper_print(1, 2)
+
# convert constants to objects in tuple
@micropython.viper
def viper_tuple_consts(x):
@@ -103,6 +115,7 @@ def viper_tuple_consts(x):
print(viper_tuple_consts(0))
+
# making a tuple from an object and an int
@micropython.viper
def viper_tuple(x, y: int):
@@ -111,6 +124,7 @@ def viper_tuple(x, y: int):
print(viper_tuple(1, 2))
+
# making a list from an object and an int
@micropython.viper
def viper_list(x, y: int):
@@ -119,6 +133,7 @@ def viper_list(x, y: int):
print(viper_list(1, 2))
+
# making a set from an object and an int
@micropython.viper
def viper_set(x, y: int):
@@ -127,6 +142,7 @@ def viper_set(x, y: int):
print(sorted(list(viper_set(1, 2))))
+
# raising an exception
@micropython.viper
def viper_raise(x: int):
@@ -138,6 +154,7 @@ try:
except OSError as e:
print(repr(e))
+
# calling GC after defining the function
@micropython.viper
def viper_gc() -> int:
diff --git a/tests/micropython/viper_misc2.py b/tests/micropython/viper_misc2.py
index 8f0be487d..cc77134bd 100644
--- a/tests/micropython/viper_misc2.py
+++ b/tests/micropython/viper_misc2.py
@@ -1,5 +1,6 @@
# Miscellaneous viper tests
+
# Test correct use of registers in load and store
@micropython.viper
def expand(dest: ptr8, source: ptr8, length: int):
diff --git a/tests/micropython/viper_misc_intbig.py b/tests/micropython/viper_misc_intbig.py
index eda873ca6..ac09f5785 100644
--- a/tests/micropython/viper_misc_intbig.py
+++ b/tests/micropython/viper_misc_intbig.py
@@ -1,5 +1,6 @@
import micropython
+
# unsigned ints
@micropython.viper
def viper_uint() -> uint:
diff --git a/tests/micropython/viper_try.py b/tests/micropython/viper_try.py
index 61335af22..f5822a668 100644
--- a/tests/micropython/viper_try.py
+++ b/tests/micropython/viper_try.py
@@ -1,5 +1,6 @@
# test try handling within a viper function
+
# basic try-finally
@micropython.viper
def f():
@@ -14,6 +15,7 @@ try:
except NameError:
print("NameError")
+
# nested try-except with try-finally
@micropython.viper
def f():
@@ -28,6 +30,7 @@ def f():
f()
+
# check that locals written to in try blocks keep their values
@micropython.viper
def f():
diff --git a/tests/micropython/viper_types.py b/tests/micropython/viper_types.py
index 3af148171..3e0a4f664 100644
--- a/tests/micropython/viper_types.py
+++ b/tests/micropython/viper_types.py
@@ -2,6 +2,7 @@
import micropython
+
# converting incoming arg to bool
@micropython.viper
def f1(x: bool):
@@ -13,6 +14,7 @@ f1(1)
f1([])
f1([1])
+
# taking and returning a bool
@micropython.viper
def f2(x: bool) -> bool:
@@ -22,6 +24,7 @@ def f2(x: bool) -> bool:
print(f2([]))
print(f2([1]))
+
# converting to bool within function
@micropython.viper
def f3(x) -> bool:
diff --git a/tests/micropython/viper_with.py b/tests/micropython/viper_with.py
index d640c8ae0..40fbf6fb3 100644
--- a/tests/micropython/viper_with.py
+++ b/tests/micropython/viper_with.py
@@ -21,6 +21,7 @@ def f():
f()
+
# nested with and try-except
@micropython.viper
def f():