diff options
author | Guido van Rossum <guido@python.org> | 2002-06-12 19:57:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-06-12 19:57:18 (GMT) |
commit | aa6a664bbbfc611cf0131b954b715b4c917dc78c (patch) | |
tree | 46c1f52ac0c31ce7d5f256dcd149c376d99ab0f5 /Lib/test/test_timeout.py | |
parent | 24e4af8c729dd2905e3025415338179b95bf3986 (diff) | |
download | cpython-aa6a664bbbfc611cf0131b954b715b4c917dc78c.zip cpython-aa6a664bbbfc611cf0131b954b715b4c917dc78c.tar.gz cpython-aa6a664bbbfc611cf0131b954b715b4c917dc78c.tar.bz2 |
Add some more basic tests to validate the argument checking of
settimeout(), test settimeout(None), and the interaction between
settimeout() and setblocking().
Diffstat (limited to 'Lib/test/test_timeout.py')
-rw-r--r-- | Lib/test/test_timeout.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index c1269a8..db284c8 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -1,4 +1,4 @@ -#!/home/bernie/src/python23/dist/src/python +"""Unit tests for socket timeout feature.""" import unittest import test_support @@ -6,8 +6,10 @@ import test_support import time import socket + class CreationTestCase(unittest.TestCase): """Test Case for socket.gettimeout() and socket.settimeout()""" + def setUp(self): self.__s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -39,9 +41,57 @@ class CreationTestCase(unittest.TestCase): self.assertEqual(type(self.__s.gettimeout()), type(1.0), "return type of gettimeout() is not FloatType") + self.__s.settimeout(None) + self.assertEqual(type(self.__s.gettimeout()), type(None), + "return type of gettimeout() is not None") + + def testTypeCheck(self): + "Test type checking by settimeout" + self.__s.settimeout(0) + self.__s.settimeout(0L) + self.__s.settimeout(0.0) + self.__s.settimeout(None) + self.assertRaises(TypeError, self.__s.settimeout, "") + self.assertRaises(TypeError, self.__s.settimeout, u"") + self.assertRaises(TypeError, self.__s.settimeout, ()) + self.assertRaises(TypeError, self.__s.settimeout, []) + self.assertRaises(TypeError, self.__s.settimeout, {}) + self.assertRaises(TypeError, self.__s.settimeout, 0j) + + def testRangeCheck(self): + "Test range checking by settimeout" + self.assertRaises(ValueError, self.__s.settimeout, -1) + self.assertRaises(ValueError, self.__s.settimeout, -1L) + self.assertRaises(ValueError, self.__s.settimeout, -1.0) + + def testTimeoutThenoBlocking(self): + "Test settimeout followed by setblocking" + self.__s.settimeout(10) + self.__s.setblocking(1) + self.assertEqual(self.__s.gettimeout(), None) + self.__s.setblocking(0) + self.assertEqual(self.__s.gettimeout(), None) + + self.__s.settimeout(10) + self.__s.setblocking(0) + self.assertEqual(self.__s.gettimeout(), None) + self.__s.setblocking(1) + self.assertEqual(self.__s.gettimeout(), None) + + def testBlockingThenTimeout(self): + "Test setblocking followed by settimeout" + self.__s.setblocking(0) + self.__s.settimeout(1) + self.assertEqual(self.__s.gettimeout(), 1) + + self.__s.setblocking(1) + self.__s.settimeout(1) + self.assertEqual(self.__s.gettimeout(), 1) + class TimeoutTestCase(unittest.TestCase): """Test Case for socket.socket() timeout functions""" + def setUp(self): self.__s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__addr_remote = ('www.google.com', 80) |