circuitpython/tests/micropython/heapalloc_super.py
Paul Sokolovsky 016f830536 tests/heapalloc, heapalloc_super: Skip in strict stackless mode.
These tests involves testing allocation-free function calling, and in strict
stackless mode, it's not possible to make a function call with heap locked
(because function activation record aka frame is allocated on the heap).
2017-12-11 12:04:59 +02:00

27 lines
551 B
Python

# test super() operations which don't require allocation
import micropython
# Check for stackless build, which can't call functions without
# allocating a frame on heap.
try:
def stackless(): pass
micropython.heap_lock(); stackless(); micropython.heap_unlock()
except RuntimeError:
print("SKIP")
raise SystemExit
class A:
def foo(self):
print('A foo')
return 42
class B(A):
def foo(self):
print('B foo')
print(super().foo())
b = B()
micropython.heap_lock()
b.foo()
micropython.heap_unlock()