diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2011-04-28 17:18:10 (GMT) | 
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-04-28 17:18:10 (GMT) | 
| commit | 9c39f3c4ec0cfc3655b95c3637c4222ecb173f33 (patch) | |
| tree | b3ba0194360d3f57dd49784248493476ec921773 /Lib/test/support.py | |
| parent | 70eb79c669547509d82b3e2d8fac7fa1b6244f75 (diff) | |
| download | cpython-9c39f3c4ec0cfc3655b95c3637c4222ecb173f33.zip cpython-9c39f3c4ec0cfc3655b95c3637c4222ecb173f33.tar.gz cpython-9c39f3c4ec0cfc3655b95c3637c4222ecb173f33.tar.bz2  | |
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.
Diffstat (limited to 'Lib/test/support.py')
| -rw-r--r-- | Lib/test/support.py | 30 | 
1 files changed, 22 insertions, 8 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index fbf6de4..800f0e5 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -33,16 +33,15 @@ __all__ = [      "verbose", "use_resources", "max_memuse", "record_original_stdout",      "get_original_stdout", "unload", "unlink", "rmtree", "forget",      "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",      "check_warnings", "CleanImport", "EnvironmentVarGuard", -    "TransientResource", "captured_output", "captured_stdout", -    "time_out", "socket_peer_reset", "ioerror_peer_reset", -    "run_with_locale", 'temp_umask', "transient_internet", -    "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", -    "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", -    "reap_children", "cpython_only", "check_impl_detail", "get_attribute", -    "swap_item", "swap_attr", "requires_IEEE_754", +    "TransientResource", "captured_output", "captured_stdout", "time_out", +    "socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask', +    "transient_internet", "set_memlimit", "bigmemtest", "bigaddrspacetest", +    "BasicTestRunner", "run_unittest", "run_doctest", "threading_setup", +    "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", +    "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754",      "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink"] @@ -381,6 +380,21 @@ def bind_port(sock, host=HOST):      port = sock.getsockname()[1]      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  requires_IEEE_754 = unittest.skipUnless(      float.__getformat__("double").startswith("IEEE"),  | 
