Skip to content

Commit 4ab8d5e

Browse files
authored
[3.14] Backport regrtest changes from the main branch (#162298)
* [3.15] Backport regrtest changes from the main branch (#162281) * Enhance encodings in regrtest header (#161959) If the UTF-8 mode is disabled and/or if PYTHONCOERCECLOCALE environment variable is set to "0": mention it in the "== encodings" regrtest header. If the locale encoding and the filesystem encoding are equal, log "locale=FS=<encoding>" to have a shorter output. On Windows, log ANSI and OEM code pages. Backport to 3.15: add types and _winapi imports to libregrtest.utils. Backport to 3.14: add _winapi.GetOEMCP() function, only log utf8=1 if UTF-8 Mode is enabled in regrtest. (cherry picked from commit f4fbacf) * Display test header when running python -m test --tsan (#162249) When running "python -m test" with --tsan or --tsan-parallel, display the test header (log TSAN_OPTIONS env var). (cherry picked from commit 53f4cad) (cherry picked from commit ecf8cfe)
1 parent a8c8da2 commit 4ab8d5e

4 files changed

Lines changed: 67 additions & 3 deletions

File tree

‎Lib/test/libregrtest/main.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,11 @@ def find_tests(self, tests: TestList | None = None) -> tuple[TestTuple, TestList
203203

204204
if self.tsan:
205205
setup_tsan_tests(self.cmdline_args)
206+
self.want_header = True
206207

207208
if self.tsan_parallel:
208209
setup_tsan_parallel_tests(self.cmdline_args)
210+
self.want_header = True
209211

210212
alltests = findtests(testdir=self.test_dir,
211213
exclude=exclude_tests)

‎Lib/test/libregrtest/utils.py‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
import sysconfig
1313
import tempfile
1414
import textwrap
15+
import types
1516
from collections.abc import Callable
17+
_winapi: types.ModuleType | None
18+
try:
19+
import _winapi
20+
except ImportError:
21+
_winapi = None
1622

1723
from test import support
1824
from test.support import os_helper
@@ -636,8 +642,32 @@ def display_header(use_resources: dict[str, str | None],
636642
if process_cpu_count and process_cpu_count != cpu_count:
637643
cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)"
638644
print("== CPU count:", cpu_count)
639-
print("== encodings: locale=%s FS=%s"
640-
% (locale.getencoding(), sys.getfilesystemencoding()))
645+
646+
encodings = []
647+
if _winapi is not None:
648+
# Log ANSI and OEM code pages
649+
ansi = f'cp{_winapi.GetACP()}'
650+
oem = f'cp{_winapi.GetOEMCP()}'
651+
if ansi == oem:
652+
encodings.append(f'ansi=oem={ansi}')
653+
else:
654+
encodings.append(f'ansi={ansi}')
655+
encodings.append(f'oem={oem}')
656+
encodings.append(f'FS={sys.getfilesystemencoding()}')
657+
else:
658+
locale_encoding = locale.getencoding() # nl_langinfo(CODESET)
659+
fs_encoding = sys.getfilesystemencoding() # normalized name
660+
if locale_encoding.lower() == fs_encoding.lower():
661+
encodings.append(f'locale=FS={fs_encoding}')
662+
else:
663+
encodings.append(f'locale={locale_encoding}')
664+
encodings.append(f'FS={fs_encoding}')
665+
if sys.flags.utf8_mode:
666+
encodings.append('utf8=1')
667+
if (not sys.flags.ignore_environment
668+
and os.environ.get('PYTHONCOERCECLOCALE') == '0'):
669+
encodings.append('coerce=0')
670+
print(f"== encodings: {' '.join(encodings)}")
641671

642672
if use_resources:
643673
text = format_resources(use_resources)

‎Modules/_winapi.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,19 @@ _winapi_GetACP_impl(PyObject *module)
27462746
return PyLong_FromUnsignedLong(GetACP());
27472747
}
27482748

2749+
/*[clinic input]
2750+
_winapi.GetOEMCP
2751+
2752+
Get the current Windows ANSI code page identifier.
2753+
[clinic start generated code]*/
2754+
2755+
static PyObject *
2756+
_winapi_GetOEMCP_impl(PyObject *module)
2757+
/*[clinic end generated code: output=4def5b07a8be1b3b input=e8caf4353a28e28e]*/
2758+
{
2759+
return PyLong_FromUnsignedLong(GetOEMCP());
2760+
}
2761+
27492762
/*[clinic input]
27502763
_winapi.GetFileType -> DWORD
27512764
@@ -3017,6 +3030,7 @@ static PyMethodDef winapi_functions[] = {
30173030
_WINAPI_WAITFORSINGLEOBJECT_METHODDEF
30183031
_WINAPI_WRITEFILE_METHODDEF
30193032
_WINAPI_GETACP_METHODDEF
3033+
_WINAPI_GETOEMCP_METHODDEF
30203034
_WINAPI_GETFILETYPE_METHODDEF
30213035
_WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF
30223036
_WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF

‎Modules/clinic/_winapi.c.h‎

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)