From 41ed01f1394ea608bf9d055120d671e2765cd9b7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 9 Feb 2023 15:32:15 +1100 Subject: [PATCH] tests/micropython: Split viper_misc test into two files. So it can run on targets with low memory, eg esp8266. Also enable the viper_4args() sub-test, which is now supported. Signed-off-by: Damien George --- tests/micropython/viper_misc.py | 98 +--------------------------- tests/micropython/viper_misc.py.exp | 11 +--- tests/micropython/viper_misc3.py | 96 +++++++++++++++++++++++++++ tests/micropython/viper_misc3.py.exp | 10 +++ 4 files changed, 110 insertions(+), 105 deletions(-) create mode 100644 tests/micropython/viper_misc3.py create mode 100644 tests/micropython/viper_misc3.py.exp diff --git a/tests/micropython/viper_misc.py b/tests/micropython/viper_misc.py index f9267f65ca..2659032df6 100644 --- a/tests/micropython/viper_misc.py +++ b/tests/micropython/viper_misc.py @@ -1,3 +1,5 @@ +# Miscellaneous viper tests. + import micropython @@ -52,8 +54,7 @@ def viper_4args(a: int, b: int, c: int, d: int) -> int: return a + b + c + d -# viper call with 4 args not yet supported -# print(viper_4args(1, 2, 3, 4)) +print(viper_4args(1, 2, 3, 4)) # a local (should have automatic type int) @@ -73,96 +74,3 @@ 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: - total = 0 - for x in range(a, b): - total += x - return total - - -print(viper_for(10, 10000)) - - -# accessing a global -@micropython.viper -def viper_access_global(): - global gl - gl = 1 - return gl - - -print(viper_access_global(), gl) - - -# calling print with object and int types -@micropython.viper -def viper_print(x, y: int): - print(x, y + 1) - - -viper_print(1, 2) - - -# convert constants to objects in tuple -@micropython.viper -def viper_tuple_consts(x): - return (x, 1, False, True) - - -print(viper_tuple_consts(0)) - - -# making a tuple from an object and an int -@micropython.viper -def viper_tuple(x, y: int): - return (x, y + 1) - - -print(viper_tuple(1, 2)) - - -# making a list from an object and an int -@micropython.viper -def viper_list(x, y: int): - return [x, y + 1] - - -print(viper_list(1, 2)) - - -# making a set from an object and an int -@micropython.viper -def viper_set(x, y: int): - return {x, y + 1} - - -print(sorted(list(viper_set(1, 2)))) - - -# raising an exception -@micropython.viper -def viper_raise(x: int): - raise OSError(x) - - -try: - viper_raise(1) -except OSError as e: - print(repr(e)) - - -# calling GC after defining the function -@micropython.viper -def viper_gc() -> int: - return 1 - - -print(viper_gc()) -import gc - -gc.collect() -print(viper_gc()) diff --git a/tests/micropython/viper_misc.py.exp b/tests/micropython/viper_misc.py.exp index e4462771b4..922ceb9fef 100644 --- a/tests/micropython/viper_misc.py.exp +++ b/tests/micropython/viper_misc.py.exp @@ -3,15 +3,6 @@ 0 Ellipsis 6 +10 7 20 -49994955 -1 1 -1 3 -(0, 1, False, True) -(1, 3) -[1, 3] -[1, 3] -OSError(1,) -1 -1 diff --git a/tests/micropython/viper_misc3.py b/tests/micropython/viper_misc3.py new file mode 100644 index 0000000000..7b211e5dd8 --- /dev/null +++ b/tests/micropython/viper_misc3.py @@ -0,0 +1,96 @@ +# Miscellaneous viper tests. + +import micropython + + +# a for loop +@micropython.viper +def viper_for(a: int, b: int) -> int: + total = 0 + for x in range(a, b): + total += x + return total + + +print(viper_for(10, 10000)) + + +# accessing a global +@micropython.viper +def viper_access_global(): + global gl + gl = 1 + return gl + + +print(viper_access_global(), gl) + + +# calling print with object and int types +@micropython.viper +def viper_print(x, y: int): + print(x, y + 1) + + +viper_print(1, 2) + + +# convert constants to objects in tuple +@micropython.viper +def viper_tuple_consts(x): + return (x, 1, False, True) + + +print(viper_tuple_consts(0)) + + +# making a tuple from an object and an int +@micropython.viper +def viper_tuple(x, y: int): + return (x, y + 1) + + +print(viper_tuple(1, 2)) + + +# making a list from an object and an int +@micropython.viper +def viper_list(x, y: int): + return [x, y + 1] + + +print(viper_list(1, 2)) + + +# making a set from an object and an int +@micropython.viper +def viper_set(x, y: int): + return {x, y + 1} + + +print(sorted(list(viper_set(1, 2)))) + + +# raising an exception +@micropython.viper +def viper_raise(x: int): + raise OSError(x) + + +try: + viper_raise(1) +except OSError as e: + print(repr(e)) + + +# calling GC after defining the function +@micropython.viper +def viper_gc() -> int: + return 1 + + +print(viper_gc()) +import gc + +gc.collect() +print(viper_gc()) diff --git a/tests/micropython/viper_misc3.py.exp b/tests/micropython/viper_misc3.py.exp new file mode 100644 index 0000000000..b12807b2f3 --- /dev/null +++ b/tests/micropython/viper_misc3.py.exp @@ -0,0 +1,10 @@ +49994955 +1 1 +1 3 +(0, 1, False, True) +(1, 3) +[1, 3] +[1, 3] +OSError(1,) +1 +1