From d0c2b5b0ae8ea2d727c965840fa35dfdc7fecce1 Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Tue, 13 Dec 2016 09:22:01 +0100 Subject: [PATCH] Issue #26936: Fix the test_socket failures on Android - getservbyname(), getservbyport() and getaddrinfo() are broken on some Android API levels. --- Lib/test/test_socket.py | 16 ++++++++++++---- Misc/NEWS | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index a5657c70c66..8dad49f18d9 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -932,8 +932,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') @@ -942,7 +945,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) @@ -1275,7 +1280,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 diff --git a/Misc/NEWS b/Misc/NEWS index baa2d5e89fa..fe9dc958908 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -588,6 +588,9 @@ Tools/Demos Tests ----- + - Issue #26936: Fix the test_socket failures on Android - getservbyname(), + getservbyport() and getaddrinfo() are broken on some Android API levels. + - Issue #28666: Now test.support.rmtree is able to remove unwritable or unreadable directories.