circuitpython/tests/micropython/heapalloc_fail_memoryview.py
Damien George eb1f81b209 tests/micropython: Add some tests for failed heap allocation.
This adds tests for some locations in the code where a memory allocation
should raise an exception.
2019-04-18 14:34:12 +10:00

26 lines
507 B
Python

# test handling of failed heap allocation with memoryview
import micropython
class GetSlice:
def __getitem__(self, idx):
return idx
sl = GetSlice()[:]
# create memoryview
micropython.heap_lock()
try:
memoryview(b'')
except MemoryError:
print('MemoryError: memoryview create')
micropython.heap_unlock()
# memoryview get with slice
m = memoryview(b'')
micropython.heap_lock()
try:
m[sl]
except MemoryError:
print('MemoryError: memoryview subscr get')
micropython.heap_unlock()