summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-05-03 16:58:19 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-05-03 16:58:19 (GMT)
commitfaf9007d86a6ffa4a1f611fa1c3dd449f02cef56 (patch)
treefc6355eb95c041841ecd9bb6f5de931a7744e530 /Lib/test/test_io.py
parent2be7ec38d117dbbfa8719ed532b6125aa15c162e (diff)
downloadcpython-faf9007d86a6ffa4a1f611fa1c3dd449f02cef56.zip
cpython-faf9007d86a6ffa4a1f611fa1c3dd449f02cef56.tar.gz
cpython-faf9007d86a6ffa4a1f611fa1c3dd449f02cef56.tar.bz2
Merged revisions 80722 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r80722 | antoine.pitrou | 2010-05-03 18:48:20 +0200 (lun., 03 mai 2010) | 11 lines Merged revisions 80720 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r80720 | antoine.pitrou | 2010-05-03 18:25:33 +0200 (lun., 03 mai 2010) | 5 lines Issue #7865: The close() method of :mod:`io` objects should not swallow exceptions raised by the implicit flush(). Also ensure that calling close() several times is supported. Patch by Pascal Chambon. ........ ................
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 71362f0..f6175c8 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -535,6 +535,20 @@ class IOTest(unittest.TestCase):
with self.open(zero, "r") as f:
self.assertRaises(OverflowError, f.read)
+ def test_flush_error_on_close(self):
+ f = self.open(support.TESTFN, "wb", buffering=0)
+ def bad_flush():
+ raise IOError()
+ f.flush = bad_flush
+ self.assertRaises(IOError, f.close) # exception not swallowed
+
+ def test_multi_close(self):
+ f = self.open(support.TESTFN, "wb", buffering=0)
+ f.close()
+ f.close()
+ f.close()
+ self.assertRaises(ValueError, f.flush)
+
class CIOTest(IOTest):
pass
@@ -634,6 +648,22 @@ class CommonBufferedTests:
raw.name = b"dummy"
self.assertEqual(repr(b), "<%s name=b'dummy'>" % clsname)
+ def test_flush_error_on_close(self):
+ raw = self.MockRawIO()
+ def bad_flush():
+ raise IOError()
+ raw.flush = bad_flush
+ b = self.tp(raw)
+ self.assertRaises(IOError, b.close) # exception not swallowed
+
+ def test_multi_close(self):
+ raw = self.MockRawIO()
+ b = self.tp(raw)
+ b.close()
+ b.close()
+ b.close()
+ self.assertRaises(ValueError, b.flush)
+
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
read_mode = "rb"
@@ -2114,6 +2144,20 @@ class TextIOWrapperTest(unittest.TestCase):
for n in range(20):
self.assertEquals(content.count("Thread%03d\n" % n), 1)
+ def test_flush_error_on_close(self):
+ txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
+ def bad_flush():
+ raise IOError()
+ txt.flush = bad_flush
+ self.assertRaises(IOError, txt.close) # exception not swallowed
+
+ def test_multi_close(self):
+ txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
+ txt.close()
+ txt.close()
+ txt.close()
+ self.assertRaises(ValueError, txt.flush)
+
class CTextIOWrapperTest(TextIOWrapperTest):
def test_initialization(self):