summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-07-18 17:08:35 (GMT)
committerGuido van Rossum <guido@python.org>2002-07-18 17:08:35 (GMT)
commit9d0c8cee660030391e7017674f176fa2b496adde (patch)
treecec6c500182747d0e15985b54eddd72d3eb74224 /Lib/test/test_socket.py
parent8b6ec79b74284873696b24ab979fb1cb579b86f8 (diff)
downloadcpython-9d0c8cee660030391e7017674f176fa2b496adde.zip
cpython-9d0c8cee660030391e7017674f176fa2b496adde.tar.gz
cpython-9d0c8cee660030391e7017674f176fa2b496adde.tar.bz2
Add default timeout functionality. This adds setdefaulttimeout() and
getdefaulttimeout() functions to the socket and _socket modules, and appropriate tests.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index c9ef5d6..b9b9db6 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -297,6 +297,36 @@ class GeneralModuleTests(unittest.TestCase):
except socket.error:
pass
+ def testDefaultTimeout(self):
+ """Testing default timeout."""
+ # The default timeout should initially be None
+ self.assertEqual(socket.getdefaulttimeout(), None)
+ s = socket.socket()
+ self.assertEqual(s.gettimeout(), None)
+ s.close()
+
+ # Set the default timeout to 10, and see if it propagates
+ socket.setdefaulttimeout(10)
+ self.assertEqual(socket.getdefaulttimeout(), 10)
+ s = socket.socket()
+ self.assertEqual(s.gettimeout(), 10)
+ s.close()
+
+ # Reset the default timeout to None, and see if it propagates
+ socket.setdefaulttimeout(None)
+ self.assertEqual(socket.getdefaulttimeout(), None)
+ s = socket.socket()
+ self.assertEqual(s.gettimeout(), None)
+ s.close()
+
+ # Check that setting it to an invalid value raises ValueError
+ self.assertRaises(ValueError, socket.setdefaulttimeout, -1)
+
+ # Check that setting it to an invalid type raises TypeError
+ self.assertRaises(TypeError, socket.setdefaulttimeout, "spam")
+
+ # XXX The following three don't test module-level functionality...
+
def testSockName(self):
"""Testing getsockname()."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)