summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-12-22 02:51:50 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-12-22 02:51:50 (GMT)
commit53ae6145a0b8f3380f819bf1c60b5dfc676f05ec (patch)
treeb14f0b0cc4f3e49a5ab6e8a9444f068f12c08b30 /Lib/test/test_io.py
parent4e9dbfba217301b20f0891746ba81556858f6495 (diff)
downloadcpython-53ae6145a0b8f3380f819bf1c60b5dfc676f05ec.zip
cpython-53ae6145a0b8f3380f819bf1c60b5dfc676f05ec.tar.gz
cpython-53ae6145a0b8f3380f819bf1c60b5dfc676f05ec.tar.bz2
allow more operations to work on detached streams (closes #23093)
Patch by Martin Panter.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 2a3b4a3..ba3701a 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -654,6 +654,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)
@@ -1922,6 +1924,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)
@@ -1936,6 +1944,9 @@ class TextIOWrapperTest(unittest.TestCase):
self.assertEqual(repr(t),
"<%s.TextIOWrapper name='dummy' 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)
@@ -2537,6 +2548,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.