diff options
author | Trent Nelson <trent@trent.me> | 2012-10-17 10:15:40 (GMT) |
---|---|---|
committer | Trent Nelson <trent@trent.me> | 2012-10-17 10:15:40 (GMT) |
commit | 016884cbaae5905576779f3859a3dff509429110 (patch) | |
tree | 04c6e1476aa7c4e482f0585ba5ca83cf6003a975 /Lib/test/test_socket.py | |
parent | 5595ab564cd0a01b1efdba5a03b2521e393fe7a4 (diff) | |
parent | 45bb613e25a34eca3c286ee668821f3ca1859a0b (diff) | |
download | cpython-016884cbaae5905576779f3859a3dff509429110.zip cpython-016884cbaae5905576779f3859a3dff509429110.tar.gz cpython-016884cbaae5905576779f3859a3dff509429110.tar.bz2 |
Issue #16257: make test_create_connection() handle ENETUNREACH.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d7c9a31..cb10921 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4109,7 +4109,26 @@ class NetworkConnectionNoServer(unittest.TestCase): port = support.find_unused_port() with self.assertRaises(socket.error) as cm: socket.create_connection((HOST, port)) - self.assertEqual(cm.exception.errno, errno.ECONNREFUSED) + + # Issue #16257: create_connection() calls getaddrinfo() against + # 'localhost'. This may result in an IPV6 addr being returned + # as well as an IPV4 one: + # >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM) + # >>> [(2, 2, 0, '', ('127.0.0.1', 41230)), + # (26, 2, 0, '', ('::1', 41230, 0, 0))] + # + # create_connection() enumerates through all the addresses returned + # and if it doesn't successfully bind to any of them, it propagates + # the last exception it encountered. + # + # On Solaris, ENETUNREACH is returned in this circumstance instead + # of ECONNREFUSED. So, if that errno exists, add it to our list of + # expected errnos. + expected_errnos = [ errno.ECONNREFUSED, ] + if hasattr(errno, 'ENETUNREACH'): + expected_errnos.append(errno.ENETUNREACH) + + self.assertIn(cm.exception.errno, expected_errnos) def test_create_connection_timeout(self): # Issue #9792: create_connection() should not recast timeout errors |