diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-05-14 22:01:31 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-05-14 22:01:31 (GMT) |
commit | 81971eafbef55f635413ed530beb4a6651c68549 (patch) | |
tree | b4c62f8c86b55e4ba3370e7cdc34e5231c39d58e /Lib | |
parent | 37d1c18bda0e1596c465c75f8fe928400899399a (diff) | |
download | cpython-81971eafbef55f635413ed530beb4a6651c68549.zip cpython-81971eafbef55f635413ed530beb4a6651c68549.tar.gz cpython-81971eafbef55f635413ed530beb4a6651c68549.tar.bz2 |
correctly handle invalid operations on streams (like writing on a non-writable one)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 98dc711..08e0f13 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -290,6 +290,19 @@ class IOTest(unittest.TestCase): self.assertEqual(f.seek(-1, 2), self.LARGE) self.assertEqual(f.read(2), b"x") + def test_invalid_operations(self): + # Try writing on a file opened in read mode and vice-versa. + for mode in ("w", "wb"): + with open(support.TESTFN, mode) as fp: + self.assertRaises(IOError, fp.read) + self.assertRaises(IOError, fp.readline) + with open(support.TESTFN, "rb") as fp: + self.assertRaises(IOError, fp.write, b"blah") + self.assertRaises(IOError, fp.writelines, [b"blah\n"]) + with open(support.TESTFN, "r") as fp: + self.assertRaises(IOError, fp.write, "blah") + self.assertRaises(IOError, fp.writelines, ["blah\n"]) + def test_raw_file_io(self): with self.open(support.TESTFN, "wb", buffering=0) as f: self.assertEqual(f.readable(), False) |