Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
117158fc
Commit
117158fc
authored
Dec 23, 2015
by
Damien George
Browse files
tests: Add tests for stream IO errors.
parent
1c9210bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
tests/io/file1.py
View file @
117158fc
...
...
@@ -12,3 +12,35 @@ f = open("io/data/file1",mode="r")
print
(
f
.
readlines
())
f
=
open
(
"io/data/file1"
,
mode
=
"rb"
)
print
(
f
.
readlines
())
# write() error
f
=
open
(
'io/data/file1'
,
'r'
)
try
:
f
.
write
(
'x'
)
except
OSError
:
print
(
'OSError'
)
f
.
close
()
# read(n) error on binary file
f
=
open
(
'io/data/file1'
,
'ab'
)
try
:
f
.
read
(
1
)
except
OSError
:
print
(
'OSError'
)
f
.
close
()
# read(n) error on text file
f
=
open
(
'io/data/file1'
,
'at'
)
try
:
f
.
read
(
1
)
except
OSError
:
print
(
'OSError'
)
f
.
close
()
# readall() error (call read() for compat with CPy)
f
=
open
(
'io/data/file1'
,
'ab'
)
try
:
f
.
read
()
except
OSError
:
print
(
'OSError'
)
f
.
close
()
tests/io/file_readinto.py
View file @
117158fc
...
...
@@ -5,3 +5,10 @@ print(b)
f
=
open
(
"io/data/file2"
,
"rb"
)
print
(
f
.
readinto
(
b
))
print
(
b
)
# readinto() on writable file
f
=
open
(
'io/data/file1'
,
'ab'
)
try
:
f
.
readinto
(
bytearray
(
4
))
except
OSError
:
print
(
'OSError'
)
tests/io/file_readline.py
View file @
117158fc
...
...
@@ -4,3 +4,11 @@ print(f.readline(3))
print
(
f
.
readline
(
4
))
print
(
f
.
readline
(
5
))
print
(
f
.
readline
())
# readline() on writable file
f
=
open
(
'io/data/file1'
,
'ab'
)
try
:
f
.
readline
()
except
OSError
:
print
(
'OSError'
)
f
.
close
()
tests/io/file_seek.py
View file @
117158fc
...
...
@@ -23,3 +23,12 @@ print(f.seek(6))
print
(
f
.
read
(
5
))
print
(
f
.
tell
())
f
.
close
()
# seek closed file
f
=
open
(
'io/data/file1'
,
'r'
)
f
.
close
()
try
:
f
.
seek
(
1
)
except
(
OSError
,
ValueError
):
# CPy raises ValueError, uPy raises OSError
print
(
'OSError or ValueError'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment