3dc324d3f1
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
26 lines
671 B
Python
26 lines
671 B
Python
# Test that we can raise and catch (preallocated) exception
|
|
# without memory allocation.
|
|
import micropython
|
|
|
|
e = ValueError("error")
|
|
|
|
|
|
def func():
|
|
micropython.heap_lock()
|
|
try:
|
|
# This works as is because traceback is not allocated
|
|
# if not possible (heap is locked, no memory). If heap
|
|
# is not locked, this would allocate a traceback entry.
|
|
# To avoid that, traceback should be warmed up (by raising
|
|
# it once after creation) and then cleared before each
|
|
# raise with:
|
|
# e.__traceback__ = None
|
|
raise e
|
|
except Exception as e2:
|
|
print(e2)
|
|
micropython.heap_unlock()
|
|
|
|
|
|
func()
|
|
print("ok")
|