8000 tests/micropython: Split viper_misc test into two files. · micropython/micropython@41ed01f · GitHub
[go: up one dir, main page]

Skip to content

Commit 41ed01f

Browse files
committed
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 <damien@micropython.org>
1 parent d99ebb3 commit 41ed01f

File tree

4 files changed

+110
-105
lines changed

4 files changed

+110
-105
lines changed

tests/micropython/viper_misc.py

Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Miscellaneous viper tests.
2+
13
import micropython
24

35

@@ -52,8 +54,7 @@ def viper_4args(a: int, b: int, c: int, d: int) -> int:
5254
return a + b + c + d
5355

5456

55-
# viper call with 4 args not yet supported
56-
# print(viper_4args(1, 2, 3, 4))
57+
print(viper_4args(1, 2, 3, 4))
5758

5859

5960
# a local (should have automatic type int)
@@ -73,96 +74,3 @@ def viper_no_annotation(x, y):
7374

7475

7576
print(viper_no_annotation(4, 5))
76-
77-
78-
# a for loop
79-
@micropython.viper
80-
def viper_for(a: int, b: int) -> int:
81-
total = 0
82-
for x in range(a, b):
83-
total += x
84-
return total
85-
86-
87-
print(viper_for(10, 10000))
88-
89-
90-
# accessing a global
91-
@micropython.viper
92-
def viper_access_global():
93-
global gl
94-
gl = 1
95-
return gl
96-
97-
98-
print(viper_access_global(), gl)
99-
100-
101-
# calling print with object and int types
102-
@micropython.viper
103-
def viper_print(x, y: int):
104-
print(x, y + 1)
105-
106-
107-
viper_print(1, 2)
108-
109-
110-
# convert constants to objects in tuple
111-
@micropython.viper
112-
def viper_tuple_consts(x):
113-
return (x, 1, False, True)
114-
115-
116-
print(viper_tuple_consts(0))
117-
118-
119-
# making a tuple from an object and an int
120-
@micropython.viper
121-
def viper_tuple(x, y: int):
122-
return (x, y + 1)
123-
124-
125-
print(viper_tuple(1, 2))
126-
127-
128-
# making a list from an object and an int
129-
@micropython.viper
130-
def viper_list(x, y: int):
131-
return [x, y + 1]
132-
133-
134-
print(viper_list(1, 2))
135-
136-
137-
# making a set from an object and an int
138-
@micropython.viper
139-
def viper_set(x, y: int):
140-
return {x, y + 1}
141-
142-
143-
print(sorted(list(viper_set(1, 2))))
144-
145-
146-
# raising an exception
147-
@micropython.viper
148-
def viper_raise(x: int):
149-
raise OSError(x)
150-
151-
152-
try:
153-
viper_raise(1)
154-
except OSError as e:
155-
print(repr(e))
156-
157-
158-
# calling GC after defining the function
159-
@micropython.viper
160-
def viper_gc() -> int:
161-
return 1
162-
163-
164-
print(viper_gc())
165-
import gc
166-
167-
gc.collect()
168-
print(viper_gc())

tests/micropython/viper_misc.py.exp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
0
44
Ellipsis
55
6
6+
10
67
7
78
20
8-
49994955
9-
1 1
10-
1 3
11-
(0, 1, False, True)
12-
(1, 3)
13-
[1, 3]
14-
[1, 3]
15-
OSError(1,)
16-
1
17-
1

tests/micropython/viper_misc3.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Miscellaneous viper tests.
2+
3+
import micropython
4+
5+
6+
# a for loop
7+
@micropython.viper
8+
def viper_for(a: int, b: int) -> int:
9+
total = 0
10+
for x in range(a, b):
11+
total += x
12+
return total
13+
14+
15+
print(viper_for(10, 10000))
16+
17+
18+
# accessing a global
19+
@micropython.viper
20+
def viper_access_global():
21+
global gl
22+
gl = 1
23+
return gl
24+
25+
26+
print(viper_access_global(), gl)
27+
28+
29+
# calling print with object and int types
30+
@micropython.viper
31+
def viper_print(x, y: int):
32+
print(x, y + 1)
33+
34+
35+
viper_print(1, 2)
36+
37+
38+
# convert constants to objects in tuple
39+
@micropython.viper
40+
def viper_tuple_consts(x):
41+
return (x, 1, False, True)
42+
43+
44+
print(viper_tuple_consts(0))
45+
46+
47+
# making a tuple from an object and an int
48+
@micropython.viper
49+
def viper_tuple(x, y: int):
50+
return (x, y + 1)
51+
52+
53+
print(viper_tuple(1, 2))
54+
55+
56+
# making a list from an object and an int
57+
@micropython.viper
58+
def viper_list(x, y: int):
59+
return [x, y + 1]
60+
61+
62+
print(viper_list(1, 2))
63+
64+
65+
# making a set from an object and an int
66+
@micropython.viper
67+
def viper_set(x, y: int):
68+
return {x, y + 1}
69+
70+
71+
print(sorted(list(viper_set(1, 2))))
72+
73+
74+
# raising an exception
75+
@micropython.viper
76+
def viper_raise(x: int):
77+
raise OSError(x)
78+
79+
80+
try:
81+
viper_raise(1)
82+
except OSError as e:
83+
print(repr(e))
84+
85+
86+
# calling GC after defining the function
87+
@micropython.viper
88+
def viper_gc() -> int:
89+
return 1
90+
91+
92+
print(viper_gc())
93+
import gc
94+
95+
gc.collect()
96+
print(viper_gc())

tests/micropython/viper_misc3.py.exp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
49994955
2+
1 1
3+
1 3
4+
(0, 1, False, True)
5+
(1, 3)
6+
[1, 3]
7+
[1, 3]
8+
OSError(1,)
9+
1
10+
1

0 commit comments

Comments
 (0)
0