mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
allow more operations to work on detached streams (closes #23093)
Patch by Martin Panter.
This commit is contained in:
parent
fe3dc376fa
commit
10e76b67c9
5 changed files with 61 additions and 42 deletions
|
@ -701,6 +701,8 @@ class CommonBufferedTests:
|
|||
self.assertIs(buf.detach(), raw)
|
||||
self.assertRaises(ValueError, buf.detach)
|
||||
|
||||
repr(buf) # Should still work
|
||||
|
||||
def test_fileno(self):
|
||||
rawio = self.MockRawIO()
|
||||
bufio = self.tp(rawio)
|
||||
|
@ -2026,6 +2028,12 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
self.assertEqual(r.getvalue(), b"howdy")
|
||||
self.assertRaises(ValueError, t.detach)
|
||||
|
||||
# Operations independent of the detached stream should still work
|
||||
repr(t)
|
||||
self.assertEqual(t.encoding, "ascii")
|
||||
self.assertEqual(t.errors, "strict")
|
||||
self.assertFalse(t.line_buffering)
|
||||
|
||||
def test_repr(self):
|
||||
raw = self.BytesIO("hello".encode("utf-8"))
|
||||
b = self.BufferedReader(raw)
|
||||
|
@ -2043,6 +2051,9 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
self.assertEqual(repr(t),
|
||||
"<%s.TextIOWrapper name=b'dummy' mode='r' encoding='utf-8'>" % modname)
|
||||
|
||||
t.buffer.detach()
|
||||
repr(t) # Should not raise an exception
|
||||
|
||||
def test_line_buffering(self):
|
||||
r = self.BytesIO()
|
||||
b = self.BufferedWriter(r, 1000)
|
||||
|
@ -2813,6 +2824,9 @@ class CTextIOWrapperTest(TextIOWrapperTest):
|
|||
self.assertRaises(ValueError, t.__init__, b, newline='xyzzy')
|
||||
self.assertRaises(ValueError, t.read)
|
||||
|
||||
t = self.TextIOWrapper.__new__(self.TextIOWrapper)
|
||||
self.assertRaises(Exception, repr, t)
|
||||
|
||||
def test_garbage_collection(self):
|
||||
# C TextIOWrapper objects are collected, and collecting them flushes
|
||||
# all data to disk.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue