summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-23 19:04:03 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-23 19:04:03 (GMT)
commit716c444edcac0f32c6d82d530db2e6495e3d2be9 (patch)
treef63a8b6c4839ed622022eb5f1a8fab988b1847bc /Lib/test/test_io.py
parent744af4406406d8c96a5a368efbf6f377a7d79095 (diff)
downloadcpython-716c444edcac0f32c6d82d530db2e6495e3d2be9.zip
cpython-716c444edcac0f32c6d82d530db2e6495e3d2be9.tar.gz
cpython-716c444edcac0f32c6d82d530db2e6495e3d2be9.tar.bz2
Issue #5761: Add the name of the underlying file to the repr() of various IO objects.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 08e0f13..1337b7c 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -618,6 +618,16 @@ class CommonBufferedTests:
self.assert_(s.startswith("Exception IOError: "), s)
self.assert_(s.endswith(" ignored"), s)
+ def test_repr(self):
+ raw = self.MockRawIO()
+ b = self.tp(raw)
+ clsname = "%s.%s" % (self.tp.__module__, self.tp.__name__)
+ self.assertEqual(repr(b), "<%s>" % clsname)
+ raw.name = "dummy"
+ self.assertEqual(repr(b), "<%s name='dummy'>" % clsname)
+ raw.name = b"dummy"
+ self.assertEqual(repr(b), "<%s name=b'dummy'>" % clsname)
+
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
read_mode = "rb"
@@ -1528,7 +1538,15 @@ class TextIOWrapperTest(unittest.TestCase):
raw = self.BytesIO("hello".encode("utf-8"))
b = self.BufferedReader(raw)
t = self.TextIOWrapper(b, encoding="utf-8")
- self.assertEqual(repr(t), "<TextIOWrapper encoding=utf-8>")
+ modname = self.TextIOWrapper.__module__
+ self.assertEqual(repr(t),
+ "<%s.TextIOWrapper encoding='utf-8'>" % modname)
+ raw.name = "dummy"
+ self.assertEqual(repr(t),
+ "<%s.TextIOWrapper name='dummy' encoding='utf-8'>" % modname)
+ raw.name = b"dummy"
+ self.assertEqual(repr(t),
+ "<%s.TextIOWrapper name=b'dummy' encoding='utf-8'>" % modname)
def test_line_buffering(self):
r = self.BytesIO()