PythonExtra/tests/micropython/emg_exc.py
stijn 40ad8f1666 all: Rename "sys" module to "usys".
This is consistent with the other 'micro' modules and allows implementing
additional features in Python via e.g. micropython-lib's sys.

Note this is a breaking change (not backwards compatible) for ports which
do not enable weak links, as "import sys" must now be replaced with
"import usys".
2020-09-04 00:10:24 +10:00

38 lines
682 B
Python

# test that emergency exceptions work
import micropython
import usys
try:
import uio
except ImportError:
print("SKIP")
raise SystemExit
# some ports need to allocate heap for the emg exc
try:
micropython.alloc_emergency_exception_buf(256)
except AttributeError:
pass
def f():
micropython.heap_lock()
try:
raise ValueError(1)
except ValueError as er:
exc = er
micropython.heap_unlock()
# print the exception
buf = uio.StringIO()
usys.print_exception(exc, buf)
for l in buf.getvalue().split("\n"):
if l.startswith(" File "):
print(l.split('"')[2])
else:
print(l)
f()