summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-06-29 04:40:22 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-06-29 04:40:22 (GMT)
commit11a35f545b39ebd09171869f9987dabd85f03254 (patch)
tree320addeb670e74c71e183041374ce787efbab060 /Lib
parent10f3018023f5d862c79f95bcec3ab40e17dbe81a (diff)
downloadcpython-11a35f545b39ebd09171869f9987dabd85f03254.zip
cpython-11a35f545b39ebd09171869f9987dabd85f03254.tar.gz
cpython-11a35f545b39ebd09171869f9987dabd85f03254.tar.bz2
SF patch #760257: add socket.timeout exception
(Contributed by Bob Halley) Add unittests for the new socket.timeout exception.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py59
1 files changed, 57 insertions, 2 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index ab1e766..b2db601 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -682,10 +682,65 @@ class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase):
bufsize = 2 # Exercise the buffering code
+class TCPTimeoutTest(SocketTCPTest):
+
+ def testTCPTimeout(self):
+ def raise_timeout(*args, **kwargs):
+ self.serv.settimeout(1.0)
+ self.serv.accept()
+ self.failUnlessRaises(socket.timeout, raise_timeout,
+ "Error generating a timeout exception (TCP)")
+
+ def testTimeoutZero(self):
+ ok = False
+ try:
+ self.serv.settimeout(0.0)
+ foo = self.serv.accept()
+ except socket.timeout:
+ self.fail("caught timeout instead of error (TCP)")
+ except socket.error:
+ ok = True
+ except:
+ self.fail("caught unexpected exception (TCP)")
+ if not ok:
+ self.fail("accept() returned success when we did not expect it")
+
+class UDPTimeoutTest(SocketTCPTest):
+
+ def testUDPTimeout(self):
+ def raise_timeout(*args, **kwargs):
+ self.serv.settimeout(1.0)
+ self.serv.recv(1024)
+ self.failUnlessRaises(socket.timeout, raise_timeout,
+ "Error generating a timeout exception (UDP)")
+
+ def testTimeoutZero(self):
+ ok = False
+ try:
+ self.serv.settimeout(0.0)
+ foo = self.serv.recv(1024)
+ except socket.timeout:
+ self.fail("caught timeout instead of error (UDP)")
+ except socket.error:
+ ok = True
+ except:
+ self.fail("caught unexpected exception (UDP)")
+ if not ok:
+ self.fail("recv() returned success when we did not expect it")
+
+class TestExceptions(unittest.TestCase):
+
+ def testExceptionTree(self):
+ self.assert_(issubclass(socket.error, Exception))
+ self.assert_(issubclass(socket.herror, socket.error))
+ self.assert_(issubclass(socket.gaierror, socket.error))
+ self.assert_(issubclass(socket.timeout, socket.error))
+
+
def test_main():
- tests = [ GeneralModuleTests, BasicTCPTest ]
+ tests = [GeneralModuleTests, BasicTCPTest, TCPTimeoutTest, TestExceptions]
if sys.platform != 'mac':
- tests.append(BasicUDPTest)
+ tests.extend([ BasicUDPTest, UDPTimeoutTest ])
tests.extend([
NonBlockingTCPTests,