[Python-checkins] r68350 - sandbox/trunk/io-c/test_io.py

antoine.pitrou python-checkins at python.org
Mon Jan 5 22:44:30 CET 2009


Author: antoine.pitrou
Date: Mon Jan  5 22:44:30 2009
New Revision: 68350

Log:
Enhance and fix tests (again)



Modified:
   sandbox/trunk/io-c/test_io.py

Modified: sandbox/trunk/io-c/test_io.py
==============================================================================
--- sandbox/trunk/io-c/test_io.py	(original)
+++ sandbox/trunk/io-c/test_io.py	Mon Jan  5 22:44:30 2009
@@ -290,15 +290,20 @@
         class MyFileIO(io.FileIO):
             def __del__(self):
                 record.append(1)
-                io.FileIO.__del__(self)
+                try:
+                    f = io.FileIO.__del__
+                except AttributeError:
+                    pass
+                else:
+                    f(self)
             def close(self):
                 record.append(2)
                 io.FileIO.close(self)
             def flush(self):
                 record.append(3)
                 io.FileIO.flush(self)
-        f = MyFileIO(support.TESTFN, "w")
-        f.write("xxx")
+        f = MyFileIO(support.TESTFN, "wb")
+        f.write(b"xxx")
         del f
         self.assertEqual(record, [1, 2, 3])
 
@@ -780,6 +785,36 @@
         self.assertEquals(b"fl", rw.read(11))
         self.assertRaises(TypeError, rw.seek, 0.0)
     
+    def testFlushAndRead(self):
+        raw = io.BytesIO(b"abcdefghi")
+        bufio = self.tp(raw)
+
+        self.assertEquals(b"ab", bufio.read(2))
+        bufio.write(b"12")
+        self.assertEquals(b"ef", bufio.read(2))
+        self.assertEquals(6, bufio.tell())
+        bufio.flush()
+        self.assertEquals(6, bufio.tell())
+        self.assertEquals(b"ghi", bufio.read())
+        raw.seek(0, 0)
+        raw.write(b"XYZ")
+        # flush() resets the read buffer
+        bufio.flush()
+        bufio.seek(0, 0)
+        self.assertEquals(b"XYZ", bufio.read(3))
+
+    def testFlushAndWrite(self):
+        raw = io.BytesIO(b"abcdefghi")
+        bufio = self.tp(raw)
+
+        bufio.write(b"123")
+        bufio.flush()
+        bufio.write(b"45")
+        bufio.flush()
+        bufio.seek(0, 0)
+        self.assertEquals(b"12345fghi", raw.getvalue())
+        self.assertEquals(b"12345fghi", bufio.read())
+
     def testThreads(self):
         BufferedReaderTest.testThreads(self)
         BufferedWriterTest.testThreads(self)


More information about the Python-checkins mailing list