diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_fileio.py | 16 | ||||
-rw-r--r-- | Lib/test/test_io.py | 13 |
2 files changed, 22 insertions, 7 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 35b30a6..0f8310c 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -190,9 +190,9 @@ class AutoFileTests: self.assertTrue(f.closed) def testMethods(self): - methods = ['fileno', 'isatty', 'read', - 'tell', 'truncate', 'seekable', - 'readable', 'writable'] + methods = ['fileno', 'isatty', 'seekable', 'readable', 'writable', + 'read', 'readall', 'readline', 'readlines', + 'tell', 'truncate', 'flush'] self.f.close() self.assertTrue(self.f.closed) @@ -201,9 +201,15 @@ class AutoFileTests: method = getattr(self.f, methodname) # should raise on closed file self.assertRaises(ValueError, method) - self.assertRaises(ValueError, self.f.readinto, bytearray()) - self.assertRaises(ValueError, self.f.seek, 0, os.SEEK_CUR) + + self.assertRaises(TypeError, self.f.readinto) + self.assertRaises(ValueError, self.f.readinto, bytearray(1)) + self.assertRaises(TypeError, self.f.seek) + self.assertRaises(ValueError, self.f.seek, 0) + self.assertRaises(TypeError, self.f.write) self.assertRaises(ValueError, self.f.write, b'') + self.assertRaises(TypeError, self.f.writelines) + self.assertRaises(ValueError, self.f.writelines, b'') def testOpendir(self): # Issue 3703: opening a directory should fill the errno diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 02f7427..5b7cfc9 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2163,6 +2163,17 @@ class TextIOWrapperTest(unittest.TestCase): self.assertRaises(TypeError, t.__init__, b, newline=42) self.assertRaises(ValueError, t.__init__, b, newline='xyzzy') + def test_uninitialized(self): + t = self.TextIOWrapper.__new__(self.TextIOWrapper) + del t + t = self.TextIOWrapper.__new__(self.TextIOWrapper) + self.assertRaises(Exception, repr, t) + self.assertRaisesRegex((ValueError, AttributeError), + 'uninitialized|has no attribute', + t.read, 0) + t.__init__(self.MockRawIO()) + self.assertEqual(t.read(0), '') + def test_non_text_encoding_codecs_are_rejected(self): # Ensure the constructor complains if passed a codec that isn't # marked as a text encoding @@ -3024,8 +3035,6 @@ class CTextIOWrapperTest(TextIOWrapperTest): r = self.BytesIO(b"\xc3\xa9\n\n") b = self.BufferedReader(r, 1000) t = self.TextIOWrapper(b) - self.assertRaises(TypeError, t.__init__, b, newline=42) - self.assertRaises(ValueError, t.read) self.assertRaises(ValueError, t.__init__, b, newline='xyzzy') self.assertRaises(ValueError, t.read) |