diff options
author | Xiang Zhang <angwerzx@126.com> | 2017-03-07 03:06:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 03:06:09 (GMT) |
commit | d36a71637cefdddc02efd884f1b2c204f370afaa (patch) | |
tree | e2f419a17b3711e98594c3119d38b3b49a3c11bb /Lib/test/test_socket.py | |
parent | fea967658d2dff1e2afc45311e1ee6a40e3176c2 (diff) | |
download | cpython-d36a71637cefdddc02efd884f1b2c204f370afaa.zip cpython-d36a71637cefdddc02efd884f1b2c204f370afaa.tar.gz cpython-d36a71637cefdddc02efd884f1b2c204f370afaa.tar.bz2 |
bpo-28728: clarify possible test failure due to ISP (GH-412)
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 81f7cf7..f8e5b36 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -803,11 +803,6 @@ class GeneralModuleTests(unittest.TestCase): self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) def test_host_resolution(self): - for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2', - '1:1:1:1:1:1:1:1:1']: - self.assertRaises(OSError, socket.gethostbyname, addr) - self.assertRaises(OSError, socket.gethostbyaddr, addr) - for addr in [support.HOST, '10.0.0.1', '255.255.255.255']: self.assertEqual(socket.gethostbyname(addr), addr) @@ -816,6 +811,21 @@ class GeneralModuleTests(unittest.TestCase): for host in [support.HOST]: self.assertIn(host, socket.gethostbyaddr(host)[2]) + def test_host_resolution_bad_address(self): + # These are all malformed IP addresses and expected not to resolve to + # any result. But some ISPs, e.g. AWS, may successfully resolve these + # IPs. + explanation = ( + "resolving an invalid IP address did not raise OSError; " + "can be caused by a broken DNS server" + ) + for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2', + '1:1:1:1:1:1:1:1:1']: + with self.assertRaises(OSError): + socket.gethostbyname(addr) + with self.assertRaises(OSError, msg=explanation): + socket.gethostbyaddr(addr) + @unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.sethostname()") @unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.gethostname()") def test_sethostname(self): |