[Python-checkins] r68353 - sandbox/trunk/io-c/test_io.py
antoine.pitrou
python-checkins at python.org
Tue Jan 6 01:28:33 CET 2009
Author: antoine.pitrou
Date: Tue Jan 6 01:28:32 2009
New Revision: 68353
Log:
add destructor tests for Buffered*. Unfortunately one of them fails...
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 Tue Jan 6 01:28:32 2009
@@ -424,6 +424,32 @@
# this test. Else, write it.
pass
+ def testOverrideDestructor(self):
+ tp = self.tp
+ record = []
+ class MyBufferedIO(tp):
+ def __del__(self):
+ record.append(1)
+ try:
+ f = tp.__del__
+ except AttributeError:
+ pass
+ else:
+ f(self)
+ def close(self):
+ record.append(2)
+ tp.close(self)
+ def flush(self):
+ record.append(3)
+ tp.flush(self)
+ rawio = MockRawIO()
+ bufio = MyBufferedIO(rawio)
+ writable = bufio.writable()
+ del bufio
+ if writable:
+ self.assertEqual(record, [1, 2, 3])
+ else:
+ self.assertEqual(record, [1, 2])
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
tp = io.BufferedReader
@@ -674,6 +700,13 @@
bufio.flush()
self.assertEquals(b"abc", writer._write_stack[0])
+ def testDestructor(self):
+ writer = MockRawIO()
+ bufio = self.tp(writer, 8)
+ bufio.write(b"abc")
+ del bufio
+ self.assertEquals(b"abc", writer._write_stack[0])
+
def testTruncate(self):
# Truncate implicitly flushes the buffer.
with io.open(support.TESTFN, self.write_mode, buffering=0) as raw:
More information about the Python-checkins
mailing list