diff options
author | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-12-14 10:52:28 (GMT) |
---|---|---|
committer | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-12-14 10:52:28 (GMT) |
commit | e88ed05006d4eef73e550149efa5ec11c6336dcc (patch) | |
tree | fcc6a625175d8475fb86f7852da849d88070c3a1 /Lib/test/support | |
parent | 1351c31aa9651b278d7ef8ec79af3b646a520235 (diff) | |
download | cpython-e88ed05006d4eef73e550149efa5ec11c6336dcc.zip cpython-e88ed05006d4eef73e550149efa5ec11c6336dcc.tar.gz cpython-e88ed05006d4eef73e550149efa5ec11c6336dcc.tar.bz2 |
Issue #28683: Fix the tests that bind() a unix socket and raise PermissionError
on Android for a non-root user.
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index ed1af2b..15d8fc8 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -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: |