diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2020-01-29 14:27:33 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-05 15:02:06 +1000 |
commit | 85858e72dfdc3e941c2e620e94de05ad663138b1 (patch) | |
tree | d801c11e07380213b7e2abbb3066e2a90636369c /tests/micropython/heapalloc_exc_compressed_emg_exc.py | |
parent | 92c83bd16b55daf81157100243ded6d7d0e56538 (diff) |
py/objexcept: Allow compression of exception message text.
The decompression of error-strings is only done if the string is accessed
via printing or via er.args. Tests are added for this feature to ensure
the decompression works.
Diffstat (limited to 'tests/micropython/heapalloc_exc_compressed_emg_exc.py')
-rw-r--r-- | tests/micropython/heapalloc_exc_compressed_emg_exc.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/micropython/heapalloc_exc_compressed_emg_exc.py b/tests/micropython/heapalloc_exc_compressed_emg_exc.py new file mode 100644 index 000000000..86ade0786 --- /dev/null +++ b/tests/micropython/heapalloc_exc_compressed_emg_exc.py @@ -0,0 +1,41 @@ +import micropython + +# Does the full test from heapalloc_exc_compressed.py but while the heap is +# locked (this can only work when the emergency exception buf is enabled). + +# Some ports need to allocate heap for the emgergency exception buffer. +try: + micropython.alloc_emergency_exception_buf(256) +except AttributeError: + pass + +a = set() + + +def test(): + micropython.heap_lock() + + try: + name() + except NameError as e: + print(type(e).__name__, e) + + try: + a.pop() + except KeyError as e: + print(type(e).__name__, e) + + try: + name() + except NameError as e: + print(e.args[0]) + + try: + a.pop() + except KeyError as e: + print(e.args[0]) + + micropython.heap_unlock() + + +test() |