diff options
| author | Martin Blais <blais@furius.ca> | 2006-05-26 12:03:27 (GMT) | 
|---|---|---|
| committer | Martin Blais <blais@furius.ca> | 2006-05-26 12:03:27 (GMT) | 
| commit | 2856e5f3909f8366487ad85ca6c234040317e1e5 (patch) | |
| tree | 7f2cbe99313c107ea133d08706171dd85683fe19 /Lib/test/test_socket.py | |
| parent | 1b94940165b4e2b789855b24ea0297ebed691c46 (diff) | |
| download | cpython-2856e5f3909f8366487ad85ca6c234040317e1e5.zip cpython-2856e5f3909f8366487ad85ca6c234040317e1e5.tar.gz cpython-2856e5f3909f8366487ad85ca6c234040317e1e5.tar.bz2  | |
Support for buffer protocol for socket and struct.
* Added socket.recv_buf() and socket.recvfrom_buf() methods, that use the buffer
  protocol (send and sendto already did).
* Added struct.pack_to(), that is the corresponding buffer compatible method to
  unpack_from().
* Fixed minor typos in arraymodule.
Diffstat (limited to 'Lib/test/test_socket.py')
| -rw-r--r-- | Lib/test/test_socket.py | 33 | 
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 6943080..2246fb6 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -9,6 +9,7 @@ import time  import thread, threading  import Queue  import sys +import array  from weakref import proxy  PORT = 50007 @@ -852,8 +853,38 @@ class TestLinuxAbstractNamespace(unittest.TestCase):          self.assertRaises(socket.error, s.bind, address) +class BufferIOTest(SocketConnectedTest): +    """ +    Test the buffer versions of socket.recv() and socket.send(). +    """ +    def __init__(self, methodName='runTest'): +        SocketConnectedTest.__init__(self, methodName=methodName) + +    def testRecvBuf(self): +        buf = array.array('c', ' '*1024) +        nbytes = self.cli_conn.recv_buf(buf) +        self.assertEqual(nbytes, len(MSG)) +        msg = buf.tostring()[:len(MSG)] +        self.assertEqual(msg, MSG) + +    def _testRecvBuf(self): +        buf = buffer(MSG) +        self.serv_conn.send(buf) + +    def testRecvFromBuf(self): +        buf = array.array('c', ' '*1024) +        nbytes, addr = self.cli_conn.recvfrom_buf(buf) +        self.assertEqual(nbytes, len(MSG)) +        msg = buf.tostring()[:len(MSG)] +        self.assertEqual(msg, MSG) + +    def _testRecvFromBuf(self): +        buf = buffer(MSG) +        self.serv_conn.send(buf) +  def test_main(): -    tests = [GeneralModuleTests, BasicTCPTest, TCPTimeoutTest, TestExceptions] +    tests = [GeneralModuleTests, BasicTCPTest, TCPTimeoutTest, TestExceptions, +             BufferIOTest]      if sys.platform != 'mac':          tests.extend([ BasicUDPTest, UDPTimeoutTest ])  | 
