From 533746166d9146ec95e0594c963da47d29059fff Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 24 Jul 2026 15:51:58 +0300 Subject: [PATCH] [3.14] gh-154592: Fix test_peg_generator in non-UTF-8 locales with a non-ASCII work dir (GH-154593) (GH-154602) (cherry picked from commit da46947470013f3e36221bfc6b73c10725a95c8b) Co-authored-by: Claude Opus 4.8 --- Lib/test/test_peg_generator/test_c_parser.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_peg_generator/test_c_parser.py b/Lib/test/test_peg_generator/test_c_parser.py index aa01a9b8f7ed..be091c01498c 100644 --- a/Lib/test/test_peg_generator/test_c_parser.py +++ b/Lib/test/test_peg_generator/test_c_parser.py @@ -100,10 +100,16 @@ class TestCParser(unittest.TestCase): with contextlib.ExitStack() as stack: python_exe = stack.enter_context(support.setup_venv_with_pip_setuptools("venv")) - sitepackages = subprocess.check_output( - [python_exe, "-c", "import sysconfig; print(sysconfig.get_path('platlib'))"], - text=True, - ).strip() + + def get_sysconfig_path(name): + # Force UTF-8 to emit the non-ASCII venv path in any locale. + return subprocess.check_output( + [python_exe, "-X", "utf8", "-c", + f"import sysconfig; print(sysconfig.get_path({name!r}))"], + encoding="utf-8", + ).strip() + + sitepackages = get_sysconfig_path("platlib") stack.enter_context(import_helper.DirsOnSysPath(sitepackages)) cls.addClassCleanup(stack.pop_all().close) -- 2.47.3