diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2015-09-29 15:36:00 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2015-09-29 15:36:00 (GMT) |
commit | d94c1b92ed6420044d38b59371fd934b9ca9a79f (patch) | |
tree | 71c82c277c8175ad27a8ef228c2a10b8e1283728 /Lib/test/test_asyncio | |
parent | 85976b14ddb941670ee831ed18b5bc69ca1380ac (diff) | |
download | cpython-d94c1b92ed6420044d38b59371fd934b9ca9a79f.zip cpython-d94c1b92ed6420044d38b59371fd934b9ca9a79f.tar.gz cpython-d94c1b92ed6420044d38b59371fd934b9ca9a79f.tar.bz2 |
Fix StreamReader.__repr__
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_streams.py | 42 |
1 files changed, 42 insertions, 0 deletions
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() |