summaryrefslogtreecommitdiff
path: root/tests/micropython/heapalloc_fail_memoryview.py
blob: 3ba9015ff113eb8534cce394e3b7a8fc9d344bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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()