"""
-Collect various informations about Python to help debugging test failures.
+Collect various information about Python to help debugging test failures.
"""
from __future__ import print_function
import errno
def get_infos(self):
"""
- Get informations as a key:value dictionary where values are strings.
+ Get information as a key:value dictionary where values are strings.
"""
return {key: str(value) for key, value in self.info.items()}
info_add(name, value)
+def copy_attr(info_add, name, mod, attr_name):
+ try:
+ value = getattr(mod, attr_name)
+ except AttributeError:
+ return
+ info_add(name, value)
+
+
def call_func(info_add, name, mod, func_name, *, formatter=None):
try:
func = getattr(mod, func_name)
info_add('locale.encoding', locale.getpreferredencoding(False))
+def collect_builtins(info_add):
+ info_add('builtins.float.float_format', float.__getformat__("float"))
+ info_add('builtins.float.double_format', float.__getformat__("double"))
+
+
def collect_os(info_add):
import os
)
copy_attributes(info_add, os, 'os.%s', attributes, formatter=format_attr)
- info_add("os.cwd", os.getcwd())
+ call_func(info_add, 'os.cwd', os, 'getcwd')
call_func(info_add, 'os.uid', os, 'getuid')
call_func(info_add, 'os.gid', os, 'getgid')
call_func(info_add, 'os.uname', os, 'uname')
- if hasattr(os, 'getgroups'):
- groups = os.getgroups()
- groups = map(str, groups)
- groups = ', '.join(groups)
- info_add("os.groups", groups)
+ def format_groups(groups):
+ return ', '.join(map(str, groups))
+
+ call_func(info_add, 'os.groups', os, 'getgroups', formatter=format_groups)
if hasattr(os, 'getlogin'):
try:
else:
info_add("os.login", login)
- if hasattr(os, 'cpu_count'):
- cpu_count = os.cpu_count()
- if cpu_count:
- info_add('os.cpu_count', cpu_count)
-
+ call_func(info_add, 'os.cpu_count', os, 'cpu_count')
call_func(info_add, 'os.loadavg', os, 'getloadavg')
# Get environment variables: filter to list
)
for name, value in os.environ.items():
uname = name.upper()
- if (uname in ENV_VARS or uname.startswith(("PYTHON", "LC_"))
+ if (uname in ENV_VARS
+ # Copy PYTHON* and LC_* variables
+ or uname.startswith(("PYTHON", "LC_"))
# Visual Studio: VS140COMNTOOLS
or (uname.startswith("VS") and uname.endswith("COMNTOOLS"))):
info_add('os.environ[%s]' % name, value)
)
copy_attributes(info_add, time, 'time.%s', attributes)
- if not hasattr(time, 'get_clock_info'):
- return
-
- for clock in ('time', 'perf_counter'):
- tinfo = time.get_clock_info(clock)
- info_add('time.%s' % clock, tinfo)
+ if hasattr(time, 'get_clock_info'):
+ for clock in ('time', 'perf_counter'):
+ tinfo = time.get_clock_info(clock)
+ info_add('time.%s' % clock, tinfo)
def collect_sysconfig(info_add):
'CCSHARED',
'CFLAGS',
'CFLAGSFORSHARED',
- 'PY_LDFLAGS',
'CONFIG_ARGS',
'HOST_GNU_TYPE',
'MACHDEP',
'OPT',
'PY_CFLAGS',
'PY_CFLAGS_NODIST',
+ 'PY_LDFLAGS',
'Py_DEBUG',
'Py_ENABLE_SHARED',
'SHELL',
copy_attributes(info_add, _decimal, '_decimal.%s', attributes)
+def collect_testcapi(info_add):
+ try:
+ import _testcapi
+ except ImportError:
+ return
+
+ call_func(info_add, 'pymem.allocator', _testcapi, 'pymem_getallocatorsname')
+ copy_attr(info_add, 'pymem.with_pymalloc', _testcapi, 'WITH_PYMALLOC')
+
+
+def collect_resource(info_add):
+ try:
+ import resource
+ except ImportError:
+ return
+
+ limits = [attr for attr in dir(resource) if attr.startswith('RLIMIT_')]
+ for name in limits:
+ key = getattr(resource, name)
+ value = resource.getrlimit(key)
+ info_add('resource.%s' % name, value)
+
+
+def collect_test_socket(info_add):
+ try:
+ from test import test_socket
+ except ImportError:
+ return
+
+ # all check attributes like HAVE_SOCKET_CAN
+ attributes = [name for name in dir(test_socket)
+ if name.startswith('HAVE_')]
+ copy_attributes(info_add, test_socket, 'test_socket.%s', attributes)
+
+
+def collect_test_support(info_add):
+ try:
+ from test import support
+ except ImportError:
+ return
+
+ attributes = ('IPV6_ENABLED',)
+ copy_attributes(info_add, support, 'test_support.%s', attributes)
+
+ call_func(info_add, 'test_support._is_gui_available', support, '_is_gui_available')
+ call_func(info_add, 'test_support.python_is_optimized', support, 'python_is_optimized')
+
+
def collect_info(info):
error = False
info_add = info.add
# collect_os() should be the first, to check the getrandom() status
collect_os,
+ collect_builtins,
collect_gdb,
collect_locale,
collect_platform,
collect_zlib,
collect_expat,
collect_decimal,
+ collect_testcapi,
+ collect_resource,
+
+ # Collecting from tests should be last as they have side effects.
+ collect_test_socket,
+ collect_test_support,
):
try:
collect_func(info_add)