From a61961673603972732e0469f0752b0ed857b79df Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Aug 2026 00:04:54 +0800 Subject: [PATCH] fix(test): read add_contributor.py with explicit UTF-8 encoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_cli_entrypoint_end_to_end copies add_contributor.py with read_text()/write_text() and no encoding argument, so both fall back to the system locale. add_contributor.py contains UTF-8 multi-byte characters (an em dash), which makes the read raise UnicodeDecodeError on any non-UTF-8 Windows locale (observed on cp950 / Traditional Chinese). The trailing mapping-file read gets the same treatment for symmetry. Same footgun class as the subprocess text=True sweep in #60741, just on the pathlib read_text/write_text side. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- tests/scripts/test_contributor_map.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/scripts/test_contributor_map.py b/tests/scripts/test_contributor_map.py index 92beb06bda9a2..40fd3567a2925 100644 --- a/tests/scripts/test_contributor_map.py +++ b/tests/scripts/test_contributor_map.py @@ -100,7 +100,12 @@ def test_cli_entrypoint_end_to_end(tmp_path): scripts = tmp_path / "scripts" scripts.mkdir() for name in ("add_contributor.py",): - (scripts / name).write_text((SCRIPTS_DIR / name).read_text()) + # Explicit encoding: add_contributor.py contains UTF-8 multi-byte + # characters (an em dash), so the locale-default read_text() raises + # UnicodeDecodeError on non-UTF-8 Windows locales (e.g. cp950). + (scripts / name).write_text( + (SCRIPTS_DIR / name).read_text(encoding="utf-8"), encoding="utf-8" + ) # Minimal stub release.py so the legacy lookup import works (scripts / "release.py").write_text("LEGACY_AUTHOR_MAP = {}\n") proc = subprocess.run( @@ -109,5 +114,5 @@ def test_cli_entrypoint_end_to_end(tmp_path): cwd=tmp_path, capture_output=True, text=True, ) assert proc.returncode == 0, proc.stderr - out = (tmp_path / "contributors" / "emails" / "cli@example.com").read_text() + out = (tmp_path / "contributors" / "emails" / "cli@example.com").read_text(encoding="utf-8") assert out.splitlines()[0] == "cliperson"