]> granicus.if.org Git - python/commitdiff
Backported tests from issue #20175.
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 16 Apr 2015 08:54:14 +0000 (11:54 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 16 Apr 2015 08:54:14 +0000 (11:54 +0300)
Lib/test/test_fileio.py
Lib/test/test_io.py

index c37482ed701b6a6ac17eb5d0c616cc66aad06f20..fe5da695a596cc8a67436a7fa30a95829e564863 100644 (file)
@@ -126,9 +126,9 @@ class AutoFileTests(unittest.TestCase):
         self.assertTrue(f.closed)
 
     def testMethods(self):
-        methods = ['fileno', 'isatty', 'read', 'readinto',
-                   'seek', 'tell', 'truncate', 'write', 'seekable',
-                   'readable', 'writable']
+        methods = ['fileno', 'isatty', 'seekable', 'readable', 'writable',
+                   'read', 'readall', 'readline', 'readlines',
+                   'tell', 'truncate', 'flush']
 
         self.f.close()
         self.assertTrue(self.f.closed)
@@ -138,6 +138,15 @@ class AutoFileTests(unittest.TestCase):
             # should raise on closed file
             self.assertRaises(ValueError, method)
 
+        self.assertRaises(ValueError, self.f.readinto) # XXX should be TypeError?
+        self.assertRaises(ValueError, self.f.readinto, bytearray(1))
+        self.assertRaises(ValueError, self.f.seek)
+        self.assertRaises(ValueError, self.f.seek, 0)
+        self.assertRaises(ValueError, 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
         # Windows always returns "[Errno 13]: Permission denied
index ea109acaa0c5c3d95b97c617912733f74ebb23c4..2fb1b1e24a1ec911c6d8c29f4e28e314fd1a049d 100644 (file)
@@ -2087,6 +2087,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