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 <damien@micropython.org>
This commit is contained in:
Damien George 2022-03-07 16:47:33 +11:00
parent 9a8ee6a5df
commit 3440201e2e
4 changed files with 16 additions and 20 deletions

View File

@ -5,12 +5,10 @@ import micropython
# mp_obj_new_exception_msg (decompression can be deferred) # mp_obj_new_exception_msg (decompression can be deferred)
# NameError uses mp_obj_new_exception_msg_varg for NameError("name '%q' isn't defined") # 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. # 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). # First test the regular case (can use heap for allocating the decompression buffer).
try: try:
name() name()
@ -18,8 +16,8 @@ except NameError as e:
print(type(e).__name__, e) print(type(e).__name__, e)
try: try:
a.pop() raise 0
except KeyError as e: except TypeError as e:
print(type(e).__name__, e) print(type(e).__name__, e)
try: try:
@ -28,8 +26,8 @@ except NameError as e:
print(e.args[0]) print(e.args[0])
try: try:
a.pop() raise 0
except KeyError as e: except TypeError as e:
print(e.args[0]) print(e.args[0])
# Then test that it still works when the heap is locked (i.e. in ISR context). # 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__) print(type(e).__name__)
try: try:
a.pop() raise 0
except KeyError as e: except TypeError as e:
print(type(e).__name__) print(type(e).__name__)
micropython.heap_unlock() micropython.heap_unlock()

View File

@ -1,6 +1,6 @@
NameError name 'name' isn't defined NameError name 'name' isn't defined
KeyError pop from an empty set TypeError exceptions must derive from BaseException
name 'name' isn't defined name 'name' isn't defined
pop from an empty set exceptions must derive from BaseException
NameError NameError
KeyError TypeError

View File

@ -9,8 +9,6 @@ try:
except AttributeError: except AttributeError:
pass pass
a = set()
def test(): def test():
micropython.heap_lock() micropython.heap_lock()
@ -21,8 +19,8 @@ def test():
print(type(e).__name__, e) print(type(e).__name__, e)
try: try:
a.pop() raise 0
except KeyError as e: except TypeError as e:
print(type(e).__name__, e) print(type(e).__name__, e)
try: try:
@ -31,8 +29,8 @@ def test():
print(e.args[0]) print(e.args[0])
try: try:
a.pop() raise 0
except KeyError as e: except TypeError as e:
print(e.args[0]) print(e.args[0])
micropython.heap_unlock() micropython.heap_unlock()

View File

@ -1,4 +1,4 @@
NameError name 'name' isn't defined NameError name 'name' isn't defined
KeyError pop from an empty set TypeError exceptions must derive from BaseException
name 'name' isn't defined name 'name' isn't defined
pop from an empty set exceptions must derive from BaseException