From: Antoine Pitrou Date: Wed, 17 Mar 2010 22:50:28 +0000 (+0000) Subject: NOTE: just porting tests here. X-Git-Tag: v3.2a1~1437 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=254807816c4c7058598e3ab90aec0aa9b7babad0;p=python NOTE: just porting tests here. Merged revisions 79039 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79039 | antoine.pitrou | 2010-03-17 23:45:39 +0100 (mer., 17 mars 2010) | 5 lines Issue #8104: socket.recv_into() and socket.recvfrom_into() now support writing into objects supporting the new buffer API, for example bytearrays or memoryviews. ........ --- diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 6bff03e2ba..1e1e4536c1 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1312,28 +1312,64 @@ class BufferIOTest(SocketConnectedTest): def __init__(self, methodName='runTest'): SocketConnectedTest.__init__(self, methodName=methodName) - def testRecvInto(self): + def testRecvIntoArray(self): buf = bytearray(1024) nbytes = self.cli_conn.recv_into(buf) self.assertEqual(nbytes, len(MSG)) msg = buf[:len(MSG)] self.assertEqual(msg, MSG) - def _testRecvInto(self): + def _testRecvIntoArray(self): buf = bytes(MSG) self.serv_conn.send(buf) - def testRecvFromInto(self): + def testRecvIntoBytearray(self): + buf = bytearray(1024) + nbytes = self.cli_conn.recv_into(buf) + self.assertEqual(nbytes, len(MSG)) + msg = buf[:len(MSG)] + self.assertEqual(msg, MSG) + + _testRecvIntoBytearray = _testRecvIntoArray + + def testRecvIntoMemoryview(self): + buf = bytearray(1024) + nbytes = self.cli_conn.recv_into(memoryview(buf)) + self.assertEqual(nbytes, len(MSG)) + msg = buf[:len(MSG)] + self.assertEqual(msg, MSG) + + _testRecvIntoMemoryview = _testRecvIntoArray + + def testRecvFromIntoArray(self): buf = bytearray(1024) nbytes, addr = self.cli_conn.recvfrom_into(buf) self.assertEqual(nbytes, len(MSG)) msg = buf[:len(MSG)] self.assertEqual(msg, MSG) - def _testRecvFromInto(self): + def _testRecvFromIntoArray(self): buf = bytes(MSG) self.serv_conn.send(buf) + def testRecvFromIntoBytearray(self): + buf = bytearray(1024) + nbytes, addr = self.cli_conn.recvfrom_into(buf) + self.assertEqual(nbytes, len(MSG)) + msg = buf[:len(MSG)] + self.assertEqual(msg, MSG) + + _testRecvFromIntoBytearray = _testRecvFromIntoArray + + def testRecvFromIntoMemoryview(self): + buf = bytearray(1024) + nbytes, addr = self.cli_conn.recvfrom_into(memoryview(buf)) + self.assertEqual(nbytes, len(MSG)) + msg = buf[:len(MSG)] + self.assertEqual(msg, MSG) + + _testRecvFromIntoMemoryview = _testRecvFromIntoArray + TIPC_STYPE = 2000 TIPC_LOWER = 200