[Python-checkins] cpython (2.7): Backported tests from issue #20175.

serhiy.storchaka python-checkins at python.org
Thu Apr 16 10:58:57 CEST 2015


https://hg.python.org/cpython/rev/867c509c8c5e
changeset:   95688:867c509c8c5e
branch:      2.7
parent:      95675:5576c8240963
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Apr 16 11:56:35 2015 +0300
summary:
  Backported tests from issue #20175.

files:
  Lib/test/test_fileio.py |  15 ++++++++++++---
  Lib/test/test_io.py     |  11 +++++++++++
  2 files changed, 23 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -125,9 +125,9 @@
         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']
         if sys.platform.startswith('atheos'):
             methods.remove('truncate')
 
@@ -139,6 +139,15 @@
             # 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
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1990,6 +1990,17 @@
         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.assertRaisesRegexp((ValueError, AttributeError),
+                                'uninitialized|has no attribute',
+                                t.read, 0)
+        t.__init__(self.MockRawIO())
+        self.assertEqual(t.read(0), u'')
+
     def test_detach(self):
         r = self.BytesIO()
         b = self.BufferedWriter(r)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list