annotate Lib/test/test_timeout.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents c5ebacbba0be
children 0eb948364990
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
1 """Unit tests for socket timeout feature."""
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 import unittest
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 23831
diff changeset
4 from test import test_support
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 import time
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 import socket
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
9
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
10 class CreationTestCase(unittest.TestCase):
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
11 """Test case for socket.gettimeout() and socket.settimeout()"""
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
12
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 def setUp(self):
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
14 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 def tearDown(self):
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
17 self.sock.close()
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 def testObjectCreation(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
20 # Test Socket creation
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
21 self.assertEqual(self.sock.gettimeout(), None,
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
22 "timeout not disabled by default")
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 def testFloatReturnValue(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
25 # Test return value of gettimeout()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
26 self.sock.settimeout(7.345)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
27 self.assertEqual(self.sock.gettimeout(), 7.345)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
29 self.sock.settimeout(3)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
30 self.assertEqual(self.sock.gettimeout(), 3)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
31
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
32 self.sock.settimeout(None)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
33 self.assertEqual(self.sock.gettimeout(), None)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 def testReturnType(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
36 # Test return type of gettimeout()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
37 self.sock.settimeout(1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
38 self.assertEqual(type(self.sock.gettimeout()), type(1.0))
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
40 self.sock.settimeout(3.9)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
41 self.assertEqual(type(self.sock.gettimeout()), type(1.0))
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
42
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
43 def testTypeCheck(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
44 # Test type checking by settimeout()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
45 self.sock.settimeout(0)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
46 self.sock.settimeout(0L)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
47 self.sock.settimeout(0.0)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
48 self.sock.settimeout(None)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
49 self.assertRaises(TypeError, self.sock.settimeout, "")
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
50 self.assertRaises(TypeError, self.sock.settimeout, u"")
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
51 self.assertRaises(TypeError, self.sock.settimeout, ())
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
52 self.assertRaises(TypeError, self.sock.settimeout, [])
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
53 self.assertRaises(TypeError, self.sock.settimeout, {})
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
54 self.assertRaises(TypeError, self.sock.settimeout, 0j)
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
55
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
56 def testRangeCheck(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
57 # Test range checking by settimeout()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
58 self.assertRaises(ValueError, self.sock.settimeout, -1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
59 self.assertRaises(ValueError, self.sock.settimeout, -1L)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
60 self.assertRaises(ValueError, self.sock.settimeout, -1.0)
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
61
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23793
diff changeset
62 def testTimeoutThenBlocking(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
63 # Test settimeout() followed by setblocking()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
64 self.sock.settimeout(10)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
65 self.sock.setblocking(1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
66 self.assertEqual(self.sock.gettimeout(), None)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
67 self.sock.setblocking(0)
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23793
diff changeset
68 self.assertEqual(self.sock.gettimeout(), 0.0)
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
69
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
70 self.sock.settimeout(10)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
71 self.sock.setblocking(0)
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23793
diff changeset
72 self.assertEqual(self.sock.gettimeout(), 0.0)
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
73 self.sock.setblocking(1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
74 self.assertEqual(self.sock.gettimeout(), None)
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
75
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
76 def testBlockingThenTimeout(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
77 # Test setblocking() followed by settimeout()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
78 self.sock.setblocking(0)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
79 self.sock.settimeout(1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
80 self.assertEqual(self.sock.gettimeout(), 1)
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
81
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
82 self.sock.setblocking(1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
83 self.sock.settimeout(1)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
84 self.assertEqual(self.sock.gettimeout(), 1)
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
85
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
87 class TimeoutTestCase(unittest.TestCase):
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
88 """Test case for socket.socket() timeout functions"""
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
89
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
90 fuzz = 1.0
23791
cde6608739c4 Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
91
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 def setUp(self):
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
93 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
94 self.addr_remote = ('www.google.com', 80)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
95 self.addr_local = ('127.0.0.1', 25339)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 def tearDown(self):
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
98 self.sock.close()
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 def testConnectTimeout(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
101 # Test connect() timeout
25106
c0d5ff8555ad testConnectTimeout(): set the timeout to a smaller value; 0.02
Guido van Rossum <guido@python.org>
parents: 24964
diff changeset
102 _timeout = 0.001
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
103 self.sock.settimeout(_timeout)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 _t1 = time.time()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
106 self.failUnlessRaises(socket.error, self.sock.connect,
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
107 self.addr_remote)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 _t2 = time.time()
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 _delta = abs(_t1 - _t2)
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
111 self.assert_(_delta < _timeout + self.fuzz,
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
112 "timeout (%g) is %g seconds more than expected (%g)"
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
113 %(_delta, self.fuzz, _timeout))
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 def testRecvTimeout(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
116 # Test recv() timeout
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 _timeout = 0.02
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
118 self.sock.connect(self.addr_remote)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
119 self.sock.settimeout(_timeout)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 _t1 = time.time()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
122 self.failUnlessRaises(socket.error, self.sock.recv, 1024)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 _t2 = time.time()
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 _delta = abs(_t1 - _t2)
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
126 self.assert_(_delta < _timeout + self.fuzz,
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
127 "timeout (%g) is %g seconds more than expected (%g)"
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
128 %(_delta, self.fuzz, _timeout))
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 def testAcceptTimeout(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
131 # Test accept() timeout
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 _timeout = 2
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
133 self.sock.settimeout(_timeout)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
134 self.sock.bind(self.addr_local)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
135 self.sock.listen(5)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 _t1 = time.time()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
138 self.failUnlessRaises(socket.error, self.sock.accept)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 _t2 = time.time()
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 _delta = abs(_t1 - _t2)
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
142 self.assert_(_delta < _timeout + self.fuzz,
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
143 "timeout (%g) is %g seconds more than expected (%g)"
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
144 %(_delta, self.fuzz, _timeout))
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 def testRecvfromTimeout(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
147 # Test recvfrom() timeout
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 _timeout = 2
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
149 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
150 self.sock.settimeout(_timeout)
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
151 self.sock.bind(self.addr_local)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 _t1 = time.time()
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
154 self.failUnlessRaises(socket.error, self.sock.recvfrom, 8192)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 _t2 = time.time()
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 _delta = abs(_t1 - _t2)
23793
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
158 self.assert_(_delta < _timeout + self.fuzz,
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
159 "timeout (%g) is %g seconds more than expected (%g)"
7cdc531e6a50 Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents: 23791
diff changeset
160 %(_delta, self.fuzz, _timeout))
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 def testSend(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
163 # Test send() timeout
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 # couldn't figure out how to test it
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 pass
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 def testSendto(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
168 # Test sendto() timeout
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 # couldn't figure out how to test it
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 pass
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 def testSendall(self):
24964
d90a6add7ca3 Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
173 # Test sendall() timeout
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 # couldn't figure out how to test it
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 pass
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
27912
c5ebacbba0be Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25106
diff changeset
178 def test_main():
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 suite = unittest.TestSuite()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
180 suite.addTest(unittest.makeSuite(CreationTestCase))
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
181 suite.addTest(unittest.makeSuite(TimeoutTestCase))
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
182 test_support.run_suite(suite)
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 if __name__ == "__main__":
27912
c5ebacbba0be Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25106
diff changeset
185 test_main()