tests: Add tests for stream IO errors.

readthedocs
Damien George 2015-12-23 22:37:02 +00:00
parent 1c9210bc2b
commit 117158fcd5
4 changed files with 56 additions and 0 deletions

View File

@ -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()

View File

@ -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')

View File

@ -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()

View File

@ -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')