Skip to content

Commit 095f90f

Browse files
committed
tests/micropython: Add test for native generators.
1 parent 6647d03 commit 095f90f

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tests/micropython/native_gen.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# test for native generators
2+
3+
# simple generator with yield and return
4+
@micropython.native
5+
def gen1(x):
6+
yield x
7+
yield x + 1
8+
return x + 2
9+
g = gen1(3)
10+
print(next(g))
11+
print(next(g))
12+
try:
13+
next(g)
14+
except StopIteration as e:
15+
print(e.args[0])
16+
17+
# using yield from
18+
@micropython.native
19+
def gen2(x):
20+
yield from range(x)
21+
print(list(gen2(3)))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
4
3+
5
4+
[0, 1, 2]

0 commit comments

Comments
 (0)