Skip to content

Commit b92a8ad

Browse files
committed
tests: Add tests using "file" argument in print and sys.print_exception.
1 parent 582b190 commit b92a8ad

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

tests/io/builtin_print_file.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# test builtin print function, using file= argument
2+
3+
import sys
4+
5+
try:
6+
sys.stdout
7+
except AttributeError:
8+
print('SKIP')
9+
raise SystemExit
10+
11+
print(file=sys.stdout)
12+
print('test', file=sys.stdout)
13+
14+
try:
15+
print(file=1)
16+
except (AttributeError, OSError): # CPython and uPy differ in error message
17+
print('Error')

tests/misc/print_exception.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,12 @@ def f():
5656
f()
5757
except Exception as e:
5858
print_exc(e)
59+
60+
# Test non-stream object passed as output object, only valid for uPy
61+
if hasattr(sys, 'print_exception'):
62+
try:
63+
sys.print_exception(Exception, 1)
64+
had_exception = False
65+
except OSError:
66+
had_exception = True
67+
assert had_exception

0 commit comments

Comments
 (0)