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)
# 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()

View File

@ -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

View File

@ -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()

View File

@ -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