summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-03-17 22:50:28 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-03-17 22:50:28 (GMT)
commit254807816c4c7058598e3ab90aec0aa9b7babad0 (patch)
tree661975688d6bb684fbd8de86e781eb327846d7e9 /Lib
parent5d2ad25252be3323a1f6a3e02a058280174cf661 (diff)
downloadcpython-254807816c4c7058598e3ab90aec0aa9b7babad0.zip
cpython-254807816c4c7058598e3ab90aec0aa9b7babad0.tar.gz
cpython-254807816c4c7058598e3ab90aec0aa9b7babad0.tar.bz2
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. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 6bff03e..1e1e453 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