tests: Add tests for stream IO errors.
This commit is contained in:
parent
1c9210bc2b
commit
117158fcd5
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue