summaryrefslogtreecommitdiff
path: root/tests/micropython/heapalloc_iter.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/micropython/heapalloc_iter.py')
-rw-r--r--tests/micropython/heapalloc_iter.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py
index 5a44a558b..18f5322ee 100644
--- a/tests/micropython/heapalloc_iter.py
+++ b/tests/micropython/heapalloc_iter.py
@@ -16,7 +16,8 @@ except ImportError:
try:
from micropython import heap_lock, heap_unlock
except (ImportError, AttributeError):
- heap_lock = heap_unlock = lambda:0
+ heap_lock = heap_unlock = lambda: 0
+
def do_iter(l):
heap_lock()
@@ -24,16 +25,18 @@ def do_iter(l):
print(i)
heap_unlock()
+
def gen_func():
yield 1
yield 2
+
# pre-create collections to iterate over
-ba = bytearray(b'123')
-ar = array.array('H', (123, 456))
+ba = bytearray(b"123")
+ar = array.array("H", (123, 456))
t = (1, 2, 3)
l = [1, 2]
-d = {1:2}
+d = {1: 2}
s = set((1,))
fs = frozenset((1,))
g1 = (100 + x for x in range(2))
@@ -41,7 +44,7 @@ g2 = gen_func()
# test containment (both success and failure) with the heap locked
heap_lock()
-print(49 in b'123', 255 in b'123')
+print(49 in b"123", 255 in b"123")
print(1 in t, -1 in t)
print(1 in l, -1 in l)
print(1 in d, -1 in d)
@@ -49,7 +52,7 @@ print(1 in s, -1 in s)
heap_unlock()
# test unpacking with the heap locked
-unp0 = unp1 = unp2 = None # preallocate slots for globals
+unp0 = unp1 = unp2 = None # preallocate slots for globals
heap_lock()
unp0, unp1, unp2 = t
print(unp0, unp1, unp2)
@@ -65,7 +68,7 @@ print(sum(t))
heap_unlock()
# test iterating over collections with the heap locked
-do_iter(b'123')
+do_iter(b"123")
do_iter(ba)
do_iter(ar)
do_iter(t)