From 3440201e2e6861be77aecb1d5069a6cfe4ccc328 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 7 Mar 2022 16:47:33 +1100 Subject: [PATCH] tests/micropython: Switch from set.pop to raise-0 to test exc strings. To not rely on sets, which are an optional feature. Signed-off-by: Damien George --- tests/micropython/heapalloc_exc_compressed.py | 16 +++++++--------- .../micropython/heapalloc_exc_compressed.py.exp | 6 +++--- .../heapalloc_exc_compressed_emg_exc.py | 10 ++++------ .../heapalloc_exc_compressed_emg_exc.py.exp | 4 ++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/tests/micropython/heapalloc_exc_compressed.py b/tests/micropython/heapalloc_exc_compressed.py index 79e423ca0f..aa071d641c 100644 --- a/tests/micropython/heapalloc_exc_compressed.py +++ b/tests/micropython/heapalloc_exc_compressed.py @@ -5,12 +5,10 @@ import micropython # mp_obj_new_exception_msg (decompression can be deferred) # NameError uses mp_obj_new_exception_msg_varg for NameError("name '%q' isn't defined") -# set.pop uses mp_obj_new_exception_msg for KeyError("pop from an empty set") +# `raise 0` uses mp_obj_new_exception_msg for TypeError("exceptions must derive from BaseException") # Tests that deferred decompression works both via print(e) and accessing the message directly via e.args. -a = set() - # First test the regular case (can use heap for allocating the decompression buffer). try: name() @@ -18,8 +16,8 @@ except NameError as e: print(type(e).__name__, e) try: - a.pop() -except KeyError as e: + raise 0 +except TypeError as e: print(type(e).__name__, e) try: @@ -28,8 +26,8 @@ except NameError as e: print(e.args[0]) try: - a.pop() -except KeyError as e: + raise 0 +except TypeError as e: print(e.args[0]) # Then test that it still works when the heap is locked (i.e. in ISR context). @@ -41,8 +39,8 @@ except NameError as e: print(type(e).__name__) try: - a.pop() -except KeyError as e: + raise 0 +except TypeError as e: print(type(e).__name__) micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_exc_compressed.py.exp b/tests/micropython/heapalloc_exc_compressed.py.exp index 32d1642f86..c3e6e5dd9f 100644 --- a/tests/micropython/heapalloc_exc_compressed.py.exp +++ b/tests/micropython/heapalloc_exc_compressed.py.exp @@ -1,6 +1,6 @@ NameError name 'name' isn't defined -KeyError pop from an empty set +TypeError exceptions must derive from BaseException name 'name' isn't defined -pop from an empty set +exceptions must derive from BaseException NameError -KeyError +TypeError diff --git a/tests/micropython/heapalloc_exc_compressed_emg_exc.py b/tests/micropython/heapalloc_exc_compressed_emg_exc.py index 86ade07862..48ce9dd69e 100644 --- a/tests/micropython/heapalloc_exc_compressed_emg_exc.py +++ b/tests/micropython/heapalloc_exc_compressed_emg_exc.py @@ -9,8 +9,6 @@ try: except AttributeError: pass -a = set() - def test(): micropython.heap_lock() @@ -21,8 +19,8 @@ def test(): print(type(e).__name__, e) try: - a.pop() - except KeyError as e: + raise 0 + except TypeError as e: print(type(e).__name__, e) try: @@ -31,8 +29,8 @@ def test(): print(e.args[0]) try: - a.pop() - except KeyError as e: + raise 0 + except TypeError as e: print(e.args[0]) micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_exc_compressed_emg_exc.py.exp b/tests/micropython/heapalloc_exc_compressed_emg_exc.py.exp index 7c368712a2..1fc8109339 100644 --- a/tests/micropython/heapalloc_exc_compressed_emg_exc.py.exp +++ b/tests/micropython/heapalloc_exc_compressed_emg_exc.py.exp @@ -1,4 +1,4 @@ NameError name 'name' isn't defined -KeyError pop from an empty set +TypeError exceptions must derive from BaseException name 'name' isn't defined -pop from an empty set +exceptions must derive from BaseException