diff options
author | Dave Cole <djc@object-craft.com.au> | 2004-08-09 04:51:41 (GMT) |
---|---|---|
committer | Dave Cole <djc@object-craft.com.au> | 2004-08-09 04:51:41 (GMT) |
commit | 331708b226db74e745ef9972f9d4177348e4399d (patch) | |
tree | d0fece579509cedd357e981e2213cebf1e241967 /Lib/test/test_socket.py | |
parent | 80e53141b9227c39b7edb4677b8b1c14551866ec (diff) | |
download | cpython-331708b226db74e745ef9972f9d4177348e4399d.zip cpython-331708b226db74e745ef9972f9d4177348e4399d.tar.gz cpython-331708b226db74e745ef9972f9d4177348e4399d.tar.bz2 |
Patch #1003700: Add socketpair function to socket module.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index adeca56..2dc34aa 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -187,6 +187,28 @@ class SocketConnectedTest(ThreadedTCPSocketTest): self.serv_conn = None ThreadedTCPSocketTest.clientTearDown(self) +class SocketPairTest(unittest.TestCase, ThreadableTest): + + def __init__(self, methodName='runTest'): + unittest.TestCase.__init__(self, methodName=methodName) + ThreadableTest.__init__(self) + + def setUp(self): + self.serv, self.cli = socket.socketpair() + + def tearDown(self): + self.serv.close() + self.serv = None + + def clientSetUp(self): + pass + + def clientTearDown(self): + self.cli.close() + self.cli = None + ThreadableTest.clientTearDown(self) + + ####################################################################### ## Begin Tests @@ -541,6 +563,25 @@ class BasicUDPTest(ThreadedUDPSocketTest): def _testRecvFrom(self): self.cli.sendto(MSG, 0, (HOST, PORT)) +class BasicSocketPairTest(SocketPairTest): + + def __init__(self, methodName='runTest'): + SocketPairTest.__init__(self, methodName=methodName) + + def testRecv(self): + msg = self.serv.recv(1024) + self.assertEqual(msg, MSG) + + def _testRecv(self): + self.cli.send(MSG) + + def testSend(self): + self.serv.send(MSG) + + def _testSend(self): + msg = self.cli.recv(1024) + self.assertEqual(msg, MSG) + class NonBlockingTCPTests(ThreadedTCPSocketTest): def __init__(self, methodName='runTest'): @@ -786,6 +827,8 @@ def test_main(): LineBufferedFileObjectClassTestCase, SmallBufferedFileObjectClassTestCase ]) + if hasattr(socket, "socketpair"): + tests.append(BasicSocketPairTest) test_support.run_unittest(*tests) if __name__ == "__main__": |