[Python-checkins] r68369 - sandbox/trunk/io-c/test_io.py
antoine.pitrou
python-checkins at python.org
Wed Jan 7 00:58:38 CET 2009
Author: antoine.pitrou
Date: Wed Jan 7 00:58:38 2009
New Revision: 68369
Log:
Add tests for the destructor behaviour of TextIOWrapper
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 Wed Jan 7 00:58:38 2009
@@ -1257,6 +1257,40 @@
finally:
os.linesep = save_linesep
+ def testDestructor(self):
+ l = []
+ class MyBytesIO(io.BytesIO):
+ def close(self):
+ l.append(self.getvalue())
+ io.BytesIO.close(self)
+ b = MyBytesIO()
+ t = io.TextIOWrapper(b, encoding="ascii")
+ t.write("abc")
+ del t
+ self.assertEquals([b"abc"], l)
+
+ def testOverrideDestructor(self):
+ record = []
+ class MyTextIO(io.TextIOWrapper):
+ def __del__(self):
+ record.append(1)
+ try:
+ f = io.TextIOWrapper.__del__
+ except AttributeError:
+ pass
+ else:
+ f(self)
+ def close(self):
+ record.append(2)
+ io.TextIOWrapper.close(self)
+ def flush(self):
+ record.append(3)
+ io.TextIOWrapper.flush(self)
+ b = io.BytesIO()
+ t = MyTextIO(b, encoding="ascii")
+ del t
+ self.assertEqual(record, [1, 2, 3])
+
# Systematic tests of the text I/O API
def testBasicIO(self):
More information about the Python-checkins
mailing list