aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_events.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-10-19 21:46:40 +0200
committerYury Selivanov <yury@magic.io>2017-10-19 15:46:40 -0400
commit525f40d231aba2c004619fc7a5207171ed65b0cb (patch)
tree60cda8363e0c027aa17a6bb4288d9436aa228829 /Lib/test/test_asyncio/test_events.py
parentea2ef5d0ca869d4550820ed53bdf56013dbb9546 (diff)
downloadcpython-525f40d231aba2c004619fc7a5207171ed65b0cb.tar.gz
cpython-525f40d231aba2c004619fc7a5207171ed65b0cb.zip
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/test_events.py')
-rw-r--r--Lib/test/test_asyncio/test_events.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 736f703c2fb..0ea9c086747 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)