summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-20 17:55:16 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-12-20 17:55:16 (GMT)
commit4c05969fc41d83e7da9ee3a2e15285a60b68ce23 (patch)
treec8a4ea23a1f982f788d8b1619d218b009091f3c9 /Lib/test/test_io.py
parent7643c92cdd0e8a3cfd83be9edae3964097b63f0e (diff)
parent68623614f095c8589ff17c004b9a05c537afc01f (diff)
downloadcpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.zip
cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.gz
cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.bz2
merge 3.3 (#16597)
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index c99ba34..28d3e0f 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -603,6 +603,7 @@ class IOTest(unittest.TestCase):
raise IOError()
f.flush = bad_flush
self.assertRaises(IOError, f.close) # exception not swallowed
+ self.assertTrue(f.closed)
def test_multi_close(self):
f = self.open(support.TESTFN, "wb", buffering=0)
@@ -780,6 +781,22 @@ class CommonBufferedTests:
raw.flush = bad_flush
b = self.tp(raw)
self.assertRaises(IOError, b.close) # exception not swallowed
+ self.assertTrue(b.closed)
+
+ def test_close_error_on_close(self):
+ raw = self.MockRawIO()
+ def bad_flush():
+ raise IOError('flush')
+ def bad_close():
+ raise IOError('close')
+ raw.close = bad_close
+ b = self.tp(raw)
+ b.flush = bad_flush
+ with self.assertRaises(IOError) as err: # exception not swallowed
+ b.close()
+ self.assertEqual(err.exception.args, ('close',))
+ self.assertEqual(err.exception.__context__.args, ('flush',))
+ self.assertFalse(b.closed)
def test_multi_close(self):
raw = self.MockRawIO()
@@ -1304,6 +1321,16 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
with self.assertRaises(TypeError):
self.tp(self.MockRawIO(), 8, 12)
+ def test_write_error_on_close(self):
+ raw = self.MockRawIO()
+ def bad_write(b):
+ raise IOError()
+ raw.write = bad_write
+ b = self.tp(raw)
+ b.write(b'spam')
+ self.assertRaises(IOError, b.close) # exception not swallowed
+ self.assertTrue(b.closed)
+
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
tp = io.BufferedWriter
@@ -2473,6 +2500,7 @@ class TextIOWrapperTest(unittest.TestCase):
raise IOError()
txt.flush = bad_flush
self.assertRaises(IOError, txt.close) # exception not swallowed
+ self.assertTrue(txt.closed)
def test_multi_close(self):
txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")