Issue #28683: Fix the tests that bind() a unix socket and raise PermissionError

on Android for a non-root user.
This commit is contained in:
Xavier de Gaye 2016-12-14 11:52:28 +01:00
parent 1351c31aa9
commit e88ed05006
5 changed files with 33 additions and 8 deletions

View file

@ -96,6 +96,7 @@ __all__ = [
"setswitchinterval", "android_not_root",
# network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
"bind_unix_socket",
# processes
'temp_umask', "reap_children",
# logging
@ -708,6 +709,15 @@ def bind_port(sock, host=HOST):
port = sock.getsockname()[1]
return port
def bind_unix_socket(sock, addr):
"""Bind a unix socket, raising SkipTest if PermissionError is raised."""
assert sock.family == socket.AF_UNIX
try:
sock.bind(addr)
except PermissionError:
sock.close()
raise unittest.SkipTest('cannot bind AF_UNIX sockets')
def _is_ipv6_enabled():
"""Check whether IPv6 is enabled on this host."""
if socket.has_ipv6: