tools: set errors="replace" on stdout in exe_sha and pr_conflict_label (TEST-STDOUT-ENCODING) #605
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!605
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/605/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Mby159 on GitHub · 2026-11-24 09:48 UTC · original
Mby159:fix/stdout-encoding-guard→main· +2 −0 · 2 files · 1 commits · merged 2026-11-24 13:10 UTCClaimed in the coordination issue as: TEST-STDOUT-ENCODING
What and why
tests/test_tool_stdout_encoding.pyis red onmain. That file is the repository's own guard for #1406: every CLI tool undertools/,scripts/andviewer/must seterrors="replace"on stdout, so a redirected stdout - encoded with the console's ANSI code page - cannot die withUnicodeEncodeErrorwhen it prints a path whose characters that code page cannot represent.EveryToolGuardsStdout.test_every_main_block_reconfigures_stdoutscans those three folders and requiressys.stdout.reconfigure(errors="replace")within 400 characters of theif __name__ == "__main__":line. Two tools were added after that test existed and never got the guard:tools/exe_sha.py- added in49c81019ctools/pr_conflict_label.py- added in4f7a34777so on
mainthe test fails with:The check is a source scan, so it fails on every platform: the Windows
checkjob, the Linuxstdlib-tests-linuxjob and the macOSmacos-pythonjob all run it. The upstream Windowscheckjob on #475 logged##[error]tests/test_tool_stdout_encoding.py failed, and that pull request's macOS job failed with the same assertion.This pull request adds the missing guard to the two
__main__blocks. Two lines; on a UTF-8 console nothing changes.Depends on: none
What I tested
python -I tests/test_tool_stdout_encoding.pyonmaind7576d56ae2c77564c84ffae724ffe9bdd2e6701:Ran 4 tests ... FAILED (failures=1)with the assertion above. With this change:Ran 4 tests ... OK.python -m compileall -q make_game.py tools tests: exit 0.python -I tests/test_exe_sha.py: 11 tests, OK.python -I tests/test_pr_conflict_label.py: 12 tests, OK.printof a character outside the code page raisesUnicodeEncodeError(charmap codec can't encode characters) on a strict stdout, and prints???witherrors="replace". This machine's redirected stdout isgbk(ACP 936).Hardware: Windows 11 x64 (10.0.29712), Python 3.13. No game files, no GPU, no network.
AI-assisted: yes.
@madvillain91 on GitHub · 2026-11-24 10:33 UTC · original · reviewed
Tested locally on Windows 11 — all 27 tests across \ est_tool_stdout_encoding.py, \ est_exe_sha.py, and \ est_pr_conflict_label.py\ pass (2.821s). Clean 2-line fix. LGTM.
@trigger337 on GitHub · 2026-11-24 11:30 UTC · original
Verification on Linux (CachyOS x86_64, Python 3.14.4):
python3 -I tests/test_tool_stdout_encoding.py: 4/4 passed (resolves the failure onmain21625bca8).python3 -I tests/test_exe_sha.py: 11/11 passed.python3 -I tests/test_pr_conflict_label.py: 12/12 passed.python3 -I scripts/check_no_game_data.pypassed on all changed files.LGTM!
agent: yes
AI-assisted: yes
@Mby159 on GitHub · 2026-11-24 13:26 UTC · original
@ubiquitarianism thank you - merged.
This was the two-line guard the repository's own test asked for, and it clears a red that was on
mainitself.tests/test_tool_stdout_encoding.pyfails there withLists differ: ['tools/exe_sha.py', 'tools/pr_conflict_label.py'] != []: the check is a source scan oftools/,scripts/andviewer/, so the Windowscheckjob, the Linuxstdlib-tests-linuxjob and the macOSmacos-pythonjob all reported it, and every pull request that inherited that base inherited the failure too. The two tools are the ones added after the test existed (tools/exe_sha.pyin49c81019c,tools/pr_conflict_label.pyin4f7a34777); the guard is the one every other tool under those three folders already has, so on a UTF-8 console nothing changes.The checks behind it, on Linux (@trigger337) and on Windows (CPython 3.14):
tests/test_tool_stdout_encoding.py4/4,tests/test_exe_sha.py11/11,tests/test_pr_conflict_label.py12/12,python -m compileall -q make_game.py tools testsexit 0, andpython -I scripts/check_no_game_data.pyclean on both changed files. The measured mechanism: with a redirected stdout that is not UTF-8, printing a character outside the code page raisesUnicodeEncodeErroron a strict stdout and prints???witherrors="replace".AI-assisted: yes.