Skip to content

Commit de8c043

Browse files
committed
tests/micropython: Add test for yield-from while heap is locked.
1 parent aacd618 commit de8c043

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Check that yield-from can work without heap allocation
2+
3+
import micropython
4+
5+
# Yielding from a function generator
6+
def sub_gen(a):
7+
for i in range(a):
8+
yield i
9+
def gen(g):
10+
yield from g
11+
g = gen(sub_gen(4))
12+
micropython.heap_lock()
13+
print(next(g))
14+
print(next(g))
15+
micropython.heap_unlock()
16+
17+
# Yielding from a user iterator
18+
class G:
19+
def __init__(self):
20+
self.value = 0
21+
def __iter__(self):
22+
return self
23+
def __next__(self):
24+
v = self.value
25+
self.value += 1
26+
return v
27+
g = gen(G())
28+
micropython.heap_lock()
29+
print(next(g))
30+
print(next(g))
31+
micropython.heap_unlock()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0
2+
1
3+
0
4+
1

0 commit comments

Comments
 (0)