Commit 9c39f3c4 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #11811: Factor out detection of IPv6 support on the current host

and make it available as `test.support.IPV6_ENABLED`.  Patch by
Charles-François Natali.
parent 70eb79c6
...@@ -33,16 +33,15 @@ __all__ = [ ...@@ -33,16 +33,15 @@ __all__ = [
"verbose", "use_resources", "max_memuse", "record_original_stdout", "verbose", "use_resources", "max_memuse", "record_original_stdout",
"get_original_stdout", "unload", "unlink", "rmtree", "forget", "get_original_stdout", "unload", "unlink", "rmtree", "forget",
"is_resource_enabled", "requires", "find_unused_port", "bind_port", "is_resource_enabled", "requires", "find_unused_port", "bind_port",
"is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd", "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd",
"findfile", "sortdict", "check_syntax_error", "open_urlresource", "findfile", "sortdict", "check_syntax_error", "open_urlresource",
"check_warnings", "CleanImport", "EnvironmentVarGuard", "check_warnings", "CleanImport", "EnvironmentVarGuard",
"TransientResource", "captured_output", "captured_stdout", "TransientResource", "captured_output", "captured_stdout", "time_out",
"time_out", "socket_peer_reset", "ioerror_peer_reset", "socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask',
"run_with_locale", 'temp_umask', "transient_internet", "transient_internet", "set_memlimit", "bigmemtest", "bigaddrspacetest",
"set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", "BasicTestRunner", "run_unittest", "run_doctest", "threading_setup",
"run_unittest", "run_doctest", "threading_setup", "threading_cleanup", "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail",
"reap_children", "cpython_only", "check_impl_detail", "get_attribute", "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754",
"swap_item", "swap_attr", "requires_IEEE_754",
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink"] "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink"]
...@@ -381,6 +380,21 @@ def bind_port(sock, host=HOST): ...@@ -381,6 +380,21 @@ def bind_port(sock, host=HOST):
port = sock.getsockname()[1] port = sock.getsockname()[1]
return port return port
def _is_ipv6_enabled():
"""Check whether IPv6 is enabled on this host."""
if socket.has_ipv6:
try:
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.bind(('::1', 0))
except (socket.error, socket.gaierror):
pass
else:
sock.close()
return True
return False
IPV6_ENABLED = _is_ipv6_enabled()
# decorator for skipping tests on non-IEEE 754 platforms # decorator for skipping tests on non-IEEE 754 platforms
requires_IEEE_754 = unittest.skipUnless( requires_IEEE_754 = unittest.skipUnless(
float.__getformat__("double").startswith("IEEE"), float.__getformat__("double").startswith("IEEE"),
......
...@@ -873,7 +873,7 @@ class TestTimeouts(TestCase): ...@@ -873,7 +873,7 @@ class TestTimeouts(TestCase):
def test_main(): def test_main():
tests = [TestFTPClass, TestTimeouts] tests = [TestFTPClass, TestTimeouts]
if socket.has_ipv6: if support.IPV6_ENABLED:
try: try:
DummyFTPServer((HOST, 0), af=socket.AF_INET6) DummyFTPServer((HOST, 0), af=socket.AF_INET6)
except socket.error: except socket.error:
......
...@@ -24,18 +24,6 @@ try: ...@@ -24,18 +24,6 @@ try:
except ImportError: except ImportError:
fcntl = False fcntl = False
def try_address(host, port=0, family=socket.AF_INET):
"""Try to bind a socket on the given host:port and return True
if that has been possible."""
try:
sock = socket.socket(family, socket.SOCK_STREAM)
sock.bind((host, port))
except (socket.error, socket.gaierror):
return False
else:
sock.close()
return True
def linux_version(): def linux_version():
try: try:
# platform.release() is something like '2.6.33.7-desktop-2mnb' # platform.release() is something like '2.6.33.7-desktop-2mnb'
...@@ -46,7 +34,6 @@ def linux_version(): ...@@ -46,7 +34,6 @@ def linux_version():
HOST = support.HOST HOST = support.HOST
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8') ## test unicode string and carriage return MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8') ## test unicode string and carriage return
SUPPORTS_IPV6 = socket.has_ipv6 and try_address('::1', family=socket.AF_INET6)
try: try:
import _thread as thread import _thread as thread
...@@ -645,7 +632,7 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -645,7 +632,7 @@ class GeneralModuleTests(unittest.TestCase):
socket.getaddrinfo('localhost', 80) socket.getaddrinfo('localhost', 80)
socket.getaddrinfo('127.0.0.1', 80) socket.getaddrinfo('127.0.0.1', 80)
socket.getaddrinfo(None, 80) socket.getaddrinfo(None, 80)
if SUPPORTS_IPV6: if support.IPV6_ENABLED:
socket.getaddrinfo('::1', 80) socket.getaddrinfo('::1', 80)
# port can be a string service name such as "http", a numeric # port can be a string service name such as "http", a numeric
# port number or None # port number or None
......
...@@ -523,6 +523,10 @@ Extensions ...@@ -523,6 +523,10 @@ Extensions
Tests Tests
----- -----
- Issue #11811: Factor out detection of IPv6 support on the current host
and make it available as ``test.support.IPV6_ENABLED``. Patch by
Charles-François Natali.
- Issue #10914: Add a minimal embedding test to test_capi. - Issue #10914: Add a minimal embedding test to test_capi.
- Issue #11223: Skip test_lock_acquire_interruption() and - Issue #11223: Skip test_lock_acquire_interruption() and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment