summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2015-09-29 15:36:44 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2015-09-29 15:36:44 (GMT)
commite4be3c25974e70708147183b187d30dc96ddd552 (patch)
tree827f0d4bc105803cafcd4a1b18db24e1a357333b /Lib
parentad4003c7fb9072c2697480ee84440408f7a49cd9 (diff)
parentd94c1b92ed6420044d38b59371fd934b9ca9a79f (diff)
downloadcpython-e4be3c25974e70708147183b187d30dc96ddd552.zip
cpython-e4be3c25974e70708147183b187d30dc96ddd552.tar.gz
cpython-e4be3c25974e70708147183b187d30dc96ddd552.tar.bz2
Merge 3.4 -> 3.5
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/streams.py2
-rw-r--r--Lib/test/test_asyncio/test_streams.py42
2 files changed, 43 insertions, 1 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index 6484c43..bb9fb31 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -324,7 +324,7 @@ class StreamReader:
def __repr__(self):
info = ['StreamReader']
if self._buffer:
- info.append('%d bytes' % len(info))
+ info.append('%d bytes' % len(self._buffer))
if self._eof:
info.append('eof')
if self._limit != _DEFAULT_LIMIT:
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index ef6f603..d4a7582 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -632,6 +632,48 @@ os.close(fd)
protocol = asyncio.StreamReaderProtocol(reader)
self.assertIs(protocol._loop, self.loop)
+ def test___repr__(self):
+ stream = asyncio.StreamReader(loop=self.loop)
+ self.assertEqual("<StreamReader>", repr(stream))
+
+ def test___repr__nondefault_limit(self):
+ stream = asyncio.StreamReader(loop=self.loop, limit=123)
+ self.assertEqual("<StreamReader l=123>", repr(stream))
+
+ def test___repr__eof(self):
+ stream = asyncio.StreamReader(loop=self.loop)
+ stream.feed_eof()
+ self.assertEqual("<StreamReader eof>", repr(stream))
+
+ def test___repr__data(self):
+ stream = asyncio.StreamReader(loop=self.loop)
+ stream.feed_data(b'data')
+ self.assertEqual("<StreamReader 4 bytes>", repr(stream))
+
+ def test___repr__exception(self):
+ stream = asyncio.StreamReader(loop=self.loop)
+ exc = RuntimeError()
+ stream.set_exception(exc)
+ self.assertEqual("<StreamReader e=RuntimeError()>", repr(stream))
+
+ def test___repr__waiter(self):
+ stream = asyncio.StreamReader(loop=self.loop)
+ stream._waiter = asyncio.Future(loop=self.loop)
+ self.assertRegex(
+ repr(stream),
+ "<StreamReader w=<Future pending[\S ]*>>")
+ stream._waiter.set_result(None)
+ self.loop.run_until_complete(stream._waiter)
+ stream._waiter = None
+ self.assertEqual("<StreamReader>", repr(stream))
+
+ def test___repr__transport(self):
+ stream = asyncio.StreamReader(loop=self.loop)
+ stream._transport = mock.Mock()
+ stream._transport.__repr__ = mock.Mock()
+ stream._transport.__repr__.return_value = "<Transport>"
+ self.assertEqual("<StreamReader t=<Transport>>", repr(stream))
+
if __name__ == '__main__':
unittest.main()