@@ -425,6 +425,9 @@ def _basetest_sock_client_ops(self, httpd, sock):
425425 with self .assertRaises (ValueError ):
426426 self .loop .run_until_complete (
427427 self .loop .sock_recv (sock , 1024 ))
428+ with self .assertRaises (ValueError ):
429+ self .loop .run_until_complete (
430+ self .loop .sock_recv_into (sock , bytearray ()))
428431 with self .assertRaises (ValueError ):
429432 self .loop .run_until_complete (
430433 self .loop .sock_accept (sock ))
@@ -443,16 +446,37 @@ def _basetest_sock_client_ops(self, httpd, sock):
443446 sock .close ()
444447 self .assertTrue (data .startswith (b'HTTP/1.0 200 OK' ))
445448
449+ def _basetest_sock_recv_into (self , httpd , sock ):
450+ # same as _basetest_sock_client_ops, but using sock_recv_into
451+ sock .setblocking (False )
452+ self .loop .run_until_complete (
453+ self .loop .sock_connect (sock , httpd .address ))
454+ self .loop .run_until_complete (
455+ self .loop .sock_sendall (sock , b'GET / HTTP/1.0\r \n \r \n ' ))
456+ data = bytearray (1024 )
457+ with memoryview (data ) as buf :
458+ nbytes = self .loop .run_until_complete (
459+ self .loop .sock_recv_into (sock , buf [:1024 ]))
460+ # consume data
461+ self .loop .run_until_complete (
462+ self .loop .sock_recv_into (sock , buf [nbytes :]))
463+ sock .close ()
464+ self .assertTrue (data .startswith (b'HTTP/1.0 200 OK' ))
465+
446466 def test_sock_client_ops (self ):
447467 with test_utils .run_test_server () as httpd :
448468 sock = socket .socket ()
449469 self ._basetest_sock_client_ops (httpd , sock )
470+ sock = socket .socket ()
471+ self ._basetest_sock_recv_into (httpd , sock )
450472
451473 @unittest .skipUnless (hasattr (socket , 'AF_UNIX' ), 'No UNIX Sockets' )
452474 def test_unix_sock_client_ops (self ):
453475 with test_utils .run_test_unix_server () as httpd :
454476 sock = socket .socket (socket .AF_UNIX )
455477 self ._basetest_sock_client_ops (httpd , sock )
478+ sock = socket .socket (socket .AF_UNIX )
479+ self ._basetest_sock_recv_into (httpd , sock )
456480
457481 def test_sock_client_fail (self ):
458482 # Make sure that we will get an unused port
@@ -2612,6 +2636,8 @@ def test_not_implemented(self):
26122636 NotImplementedError , loop .remove_writer , 1 )
26132637 self .assertRaises (
26142638 NotImplementedError , loop .sock_recv , f , 10 )
2639+ self .assertRaises (
2640+ NotImplementedError , loop .sock_recv_into , f , 10 )
26152641 self .assertRaises (
26162642 NotImplementedError , loop .sock_sendall , f , 10 )
26172643 self .assertRaises (
0 commit comments