Skip to content

Commit 3440201

Browse files
committed
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>
1 parent 9a8ee6a commit 3440201

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

tests/micropython/heapalloc_exc_compressed.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
# mp_obj_new_exception_msg (decompression can be deferred)
66

77
# NameError uses mp_obj_new_exception_msg_varg for NameError("name '%q' isn't defined")
8-
# set.pop uses mp_obj_new_exception_msg for KeyError("pop from an empty set")
8+
# `raise 0` uses mp_obj_new_exception_msg for TypeError("exceptions must derive from BaseException")
99

1010
# Tests that deferred decompression works both via print(e) and accessing the message directly via e.args.
1111

12-
a = set()
13-
1412
# First test the regular case (can use heap for allocating the decompression buffer).
1513
try:
1614
name()
1715
except NameError as e:
1816
print(type(e).__name__, e)
1917

2018
try:
21-
a.pop()
22-
except KeyError as e:
19+
raise 0
20+
except TypeError as e:
2321
print(type(e).__name__, e)
2422

2523
try:
@@ -28,8 +26,8 @@
2826
print(e.args[0])
2927

3028
try:
31-
a.pop()
32-
except KeyError as e:
29+
raise 0
30+
except TypeError as e:
3331
print(e.args[0])
3432

3533
# Then test that it still works when the heap is locked (i.e. in ISR context).
@@ -41,8 +39,8 @@
4139
print(type(e).__name__)
4240

4341
try:
44-
a.pop()
45-
except KeyError as e:
42+
raise 0
43+
except TypeError as e:
4644
print(type(e).__name__)
4745

4846
micropython.heap_unlock()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NameError name 'name' isn't defined
2-
KeyError pop from an empty set
2+
TypeError exceptions must derive from BaseException
33
name 'name' isn't defined
4-
pop from an empty set
4+
exceptions must derive from BaseException
55
NameError
6-
KeyError
6+
TypeError

tests/micropython/heapalloc_exc_compressed_emg_exc.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
except AttributeError:
1010
pass
1111

12-
a = set()
13-
1412

1513
def test():
1614
micropython.heap_lock()
@@ -21,8 +19,8 @@ def test():
2119
print(type(e).__name__, e)
2220

2321
try:
24-
a.pop()
25-
except KeyError as e:
22+
raise 0
23+
except TypeError as e:
2624
print(type(e).__name__, e)
2725

2826
try:
@@ -31,8 +29,8 @@ def test():
3129
print(e.args[0])
3230

3331
try:
34-
a.pop()
35-
except KeyError as e:
32+
raise 0
33+
except TypeError as e:
3634
print(e.args[0])
3735

3836
micropython.heap_unlock()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
NameError name 'name' isn't defined
2-
KeyError pop from an empty set
2+
TypeError exceptions must derive from BaseException
33
name 'name' isn't defined
4-
pop from an empty set
4+
exceptions must derive from BaseException

0 commit comments

Comments
 (0)