[Python-checkins] python/dist/src/Lib/test test_socket.py,1.39,1.40

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Thu, 18 Jul 2002 10:08:37 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv8306/Lib/test

Modified Files:
	test_socket.py 
Log Message:
Add default timeout functionality.  This adds setdefaulttimeout() and
getdefaulttimeout() functions to the socket and _socket modules, and
appropriate tests.


Index: test_socket.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_socket.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** test_socket.py	20 Jun 2002 03:40:16 -0000	1.39
--- test_socket.py	18 Jul 2002 17:08:35 -0000	1.40
***************
*** 298,301 ****
--- 298,331 ----
                  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()."""