Skip to content

Commit e405525

Browse files
committed
add test case
1 parent 6e70bfe commit e405525

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Lib/test/test_io/test_bufferedio.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ def test_args_error(self):
962962
with self.assertRaisesRegex(TypeError, "BufferedWriter"):
963963
self.tp(self.BytesIO(), 1024, 1024, 1024)
964964

965-
def test_closed_errors(self):
965+
def test_non_boolean_closed_attr(self):
966966
# gh-140650: check TypeError is raised
967967
class MockRawIOWithoutClosed(self.MockRawIO):
968968
closed = NotImplemented
@@ -972,6 +972,17 @@ class MockRawIOWithoutClosed(self.MockRawIO):
972972
self.assertRaises(TypeError, bufio.flush)
973973
self.assertRaises(TypeError, bufio.close)
974974

975+
def test_closed_attr_raises(self):
976+
class MockRawIOClosedRaises(self.MockRawIO):
977+
@property
978+
def closed(self):
979+
raise ValueError("test")
980+
981+
bufio = self.tp(MockRawIOClosedRaises())
982+
self.assertRaisesRegex(ValueError, "test", bufio.write, b"")
983+
self.assertRaisesRegex(ValueError, "test", bufio.flush)
984+
self.assertRaisesRegex(ValueError, "test", bufio.close)
985+
975986

976987
class PyBufferedWriterTest(BufferedWriterTest, PyTestCase):
977988
tp = pyio.BufferedWriter
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
Fix an issue where closing :class:`io.BufferedWriter` could crash
2-
if the closed attribute raised an exception.
1+
Fix an issue where closing :class:`io.BufferedWriter` could crash if
2+
the closed attribute raised an exception on access or could not be
3+
converted to a boolean.

0 commit comments

Comments
 (0)