Skip to content

Commit 7081ea4

Browse files
committed
tests/micropython: Get heapalloc_traceback test running on baremetal.
When printing exceptions from files sent to a target by pyboard.py the filename in the exception is <stdin>, which differs to when running the script on the PC. So we strip out the filename to make the outputs the same on all targets (see also misc/print_exception.py test).
1 parent a5b3c7e commit 7081ea4

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

tests/micropython/heapalloc_traceback.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import micropython
44
import sys
5+
import uio
56

67
# preallocate exception instance with some room for a traceback
78
global_exc = StopIteration()
@@ -15,10 +16,21 @@ def test():
1516
global_exc.__traceback__ = None
1617
try:
1718
raise global_exc
18-
except StopIteration as e:
19-
sys.print_exception(e)
19+
except StopIteration:
20+
print('StopIteration')
2021

2122
# call test() with heap allocation disabled
2223
micropython.heap_lock()
2324
test()
2425
micropython.heap_unlock()
26+
27+
# print the exception that was raised
28+
buf = uio.StringIO()
29+
sys.print_exception(global_exc, buf)
30+
for l in buf.getvalue().split("\n"):
31+
# uPy on pyboard prints <stdin> as file, so remove filename.
32+
if l.startswith(" File "):
33+
l = l.split('"')
34+
print(l[0], l[2])
35+
else:
36+
print(l)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
StopIteration
12
Traceback (most recent call last):
2-
File "micropython/heapalloc_traceback.py", line 17, in test
3+
File , line 18, in test
34
StopIteration:
5+

0 commit comments

Comments
 (0)