Skip to content

Commit e8487ea

Browse files
pfalcondpgeorge
authored andcommitted
tests: Add test for print_exception() function.
1 parent 6c3fc74 commit e8487ea

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/misc/print_exception.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import io
2+
import sys
3+
if hasattr(sys, 'print_exception'):
4+
print_exception = sys.print_exception
5+
else:
6+
import traceback
7+
print_exception = lambda e, f: traceback.print_exception(None, e, None, file=f)
8+
9+
try:
10+
1/0
11+
except Exception as e:
12+
print('caught')
13+
buf = io.StringIO()
14+
print_exception(e, buf)
15+
s = buf.getvalue()
16+
for l in s.split("\n"):
17+
# uPy and CPy tracebacks differ in that CPy prints a source line for
18+
# each traceback entry. In this case, we know that offending line
19+
# has 4-space indent, so filter it out.
20+
if not l.startswith(" "):
21+
print(l)

0 commit comments

Comments
 (0)