diff options
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 92e727d640..b902633327 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -897,18 +897,28 @@ class GeneralModuleTests(unittest.TestCase): self.assertRaises(OverflowError, func, 1<<34) def testNtoHErrors(self): - good_values = [ 1, 2, 3, 1, 2, 3 ] - bad_values = [ -1, -2, -3, -1, -2, -3 ] - for k in good_values: - socket.ntohl(k) + import _testcapi + s_good_values = [0, 1, 2, 0xffff] + l_good_values = s_good_values + [0xffffffff] + l_bad_values = [-1, -2, 1<<32, 1<<1000] + s_bad_values = l_bad_values + [_testcapi.INT_MIN - 1, + _testcapi.INT_MAX + 1] + s_deprecated_values = [1<<16, _testcapi.INT_MAX] + for k in s_good_values: socket.ntohs(k) - socket.htonl(k) socket.htons(k) - for k in bad_values: - self.assertRaises(OverflowError, socket.ntohl, k) + for k in l_good_values: + socket.ntohl(k) + socket.htonl(k) + for k in s_bad_values: self.assertRaises(OverflowError, socket.ntohs, k) - self.assertRaises(OverflowError, socket.htonl, k) self.assertRaises(OverflowError, socket.htons, k) + for k in l_bad_values: + self.assertRaises(OverflowError, socket.ntohl, k) + self.assertRaises(OverflowError, socket.htonl, k) + for k in s_deprecated_values: + self.assertWarns(DeprecationWarning, socket.ntohs, k) + self.assertWarns(DeprecationWarning, socket.htons, k) def testGetServBy(self): eq = self.assertEqual @@ -931,8 +941,11 @@ class GeneralModuleTests(unittest.TestCase): else: raise OSError # Try same call with optional protocol omitted - port2 = socket.getservbyname(service) - eq(port, port2) + # Issue #26936: Android getservbyname() was broken before API 23. + if (not hasattr(sys, 'getandroidapilevel') or + sys.getandroidapilevel() >= 23): + port2 = socket.getservbyname(service) + eq(port, port2) # Try udp, but don't barf if it doesn't exist try: udpport = socket.getservbyname(service, 'udp') @@ -941,7 +954,9 @@ class GeneralModuleTests(unittest.TestCase): else: eq(udpport, port) # Now make sure the lookup by port returns the same service name - eq(socket.getservbyport(port2), service) + # Issue #26936: Android getservbyport() is broken. + if not support.is_android: + eq(socket.getservbyport(port2), service) eq(socket.getservbyport(port, 'tcp'), service) if udpport is not None: eq(socket.getservbyport(udpport, 'udp'), service) @@ -1274,7 +1289,10 @@ class GeneralModuleTests(unittest.TestCase): socket.getaddrinfo('::1', 80) # port can be a string service name such as "http", a numeric # port number or None - socket.getaddrinfo(HOST, "http") + # Issue #26936: Android getaddrinfo() was broken before API level 23. + if (not hasattr(sys, 'getandroidapilevel') or + sys.getandroidapilevel() >= 23): + socket.getaddrinfo(HOST, "http") socket.getaddrinfo(HOST, 80) socket.getaddrinfo(HOST, None) # test family and socktype filters |