diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-10-19 19:46:40 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2017-10-19 19:46:40 (GMT) |
commit | 525f40d231aba2c004619fc7a5207171ed65b0cb (patch) | |
tree | 60cda8363e0c027aa17a6bb4288d9436aa228829 /Lib/test/test_asyncio | |
parent | ea2ef5d0ca869d4550820ed53bdf56013dbb9546 (diff) | |
download | cpython-525f40d231aba2c004619fc7a5207171ed65b0cb.zip cpython-525f40d231aba2c004619fc7a5207171ed65b0cb.tar.gz cpython-525f40d231aba2c004619fc7a5207171ed65b0cb.tar.bz2 |
bpo-31819: Add AbstractEventLoop.sock_recv_into() (#4051)
* bpo-31819: Add AbstractEventLoop.sock_recv_into()
* Add NEWS
* Add doc
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 26 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_proactor_events.py | 5 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index 736f703..0ea9c08 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -427,6 +427,9 @@ class EventLoopTestsMixin: self.loop.sock_recv(sock, 1024)) with self.assertRaises(ValueError): self.loop.run_until_complete( + self.loop.sock_recv_into(sock, bytearray())) + with self.assertRaises(ValueError): + self.loop.run_until_complete( self.loop.sock_accept(sock)) # test in non-blocking mode @@ -443,16 +446,37 @@ class EventLoopTestsMixin: sock.close() self.assertTrue(data.startswith(b'HTTP/1.0 200 OK')) + def _basetest_sock_recv_into(self, httpd, sock): + # same as _basetest_sock_client_ops, but using sock_recv_into + sock.setblocking(False) + self.loop.run_until_complete( + self.loop.sock_connect(sock, httpd.address)) + self.loop.run_until_complete( + self.loop.sock_sendall(sock, b'GET / HTTP/1.0\r\n\r\n')) + data = bytearray(1024) + with memoryview(data) as buf: + nbytes = self.loop.run_until_complete( + self.loop.sock_recv_into(sock, buf[:1024])) + # consume data + self.loop.run_until_complete( + self.loop.sock_recv_into(sock, buf[nbytes:])) + sock.close() + self.assertTrue(data.startswith(b'HTTP/1.0 200 OK')) + def test_sock_client_ops(self): with test_utils.run_test_server() as httpd: sock = socket.socket() self._basetest_sock_client_ops(httpd, sock) + sock = socket.socket() + self._basetest_sock_recv_into(httpd, sock) @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets') def test_unix_sock_client_ops(self): with test_utils.run_test_unix_server() as httpd: sock = socket.socket(socket.AF_UNIX) self._basetest_sock_client_ops(httpd, sock) + sock = socket.socket(socket.AF_UNIX) + self._basetest_sock_recv_into(httpd, sock) def test_sock_client_fail(self): # Make sure that we will get an unused port @@ -2613,6 +2637,8 @@ class AbstractEventLoopTests(unittest.TestCase): self.assertRaises( NotImplementedError, loop.sock_recv, f, 10) self.assertRaises( + NotImplementedError, loop.sock_recv_into, f, 10) + self.assertRaises( NotImplementedError, loop.sock_sendall, f, 10) self.assertRaises( NotImplementedError, loop.sock_connect, f, f) diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index d76da66..7a8b523 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -489,6 +489,11 @@ class BaseProactorEventLoopTests(test_utils.TestCase): self.loop.sock_recv(self.sock, 1024) self.proactor.recv.assert_called_with(self.sock, 1024) + def test_sock_recv_into(self): + buf = bytearray(10) + self.loop.sock_recv_into(self.sock, buf) + self.proactor.recv_into.assert_called_with(self.sock, buf) + def test_sock_sendall(self): self.loop.sock_sendall(self.sock, b'data') self.proactor.send.assert_called_with(self.sock, b'data') |