Surrounded with try/finally to socket's default timeout setting

changes in the tests, so failing one test won't produce strange
results in others. Also relaxed the timeout settings in the test
(where actually the value didn't mean anything).
This commit is contained in:
Facundo Batista 2007-03-23 20:23:08 +00:00
parent e6a7039451
commit 14553b08a1
2 changed files with 20 additions and 16 deletions

View file

@ -844,22 +844,24 @@ class NetworkConnectionAttributesTest(unittest.TestCase):
self.assertTrue(sock.gettimeout() is None)
# a value, named
sock = socket.create_connection((HOST, PORT), timeout=10)
self.assertEqual(sock.gettimeout(), 10)
sock = socket.create_connection((HOST, PORT), timeout=30)
self.assertEqual(sock.gettimeout(), 30)
# a value, just the value
sock = socket.create_connection((HOST, PORT), 10)
self.assertEqual(sock.gettimeout(), 10)
sock = socket.create_connection((HOST, PORT), 30)
self.assertEqual(sock.gettimeout(), 30)
# None, having other default
previous = socket.getdefaulttimeout()
socket.setdefaulttimeout(10)
sock = socket.create_connection((HOST, PORT), timeout=None)
socket.setdefaulttimeout(previous)
self.assertEqual(sock.gettimeout(), 10)
socket.setdefaulttimeout(30)
try:
sock = socket.create_connection((HOST, PORT), timeout=None)
finally:
socket.setdefaulttimeout(previous)
self.assertEqual(sock.gettimeout(), 30)
def testFamily(self):
sock = socket.create_connection((HOST, PORT), timeout=10)
sock = socket.create_connection((HOST, PORT), timeout=30)
self.assertEqual(sock.family, 2)