diff options
| author | lines9686-rgb <282495677+lines9686-rgb@users.noreply.github.com> | 2026-11-23 00:07:12 +0300 |
|---|---|---|
| committer | lines9686-rgb <282495677+lines9686-rgb@users.noreply.github.com> | 2026-11-23 00:07:12 +0300 |
| commit | 14acb49902d06ad23ce58b6e8dc40c19fa3e68fd (patch) | |
| tree | 8f848e2dcc797a09af974629978e4853823a678d /tests/winbatch.py | |
| parent | 51a6feece1b8cb1fee7f59d8528b752d1b707182 (diff) | |
tests/winbatch: skip, naming the letters, when cmd.exe can't read a path
Review of #2984 (@iurysf): with 8.3 names off, a path with letters outside the
OEM code page made open(..., encoding="oem") raise UnicodeEncodeError mid-test.
cmd.exe couldn't run that batch file in any encoding, so write_python_cmd now
raises unittest.SkipTest that names the letters (Windows' "oem" codec reports no
useful position, so they are found per character) and writes nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/winbatch.py')
| -rw-r--r-- | tests/winbatch.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/tests/winbatch.py b/tests/winbatch.py index a82d91330..55d302853 100644 --- a/tests/winbatch.py +++ b/tests/winbatch.py | |||
| @@ -17,9 +17,28 @@ def batch_path(path): | |||
| 17 | return buf.value if 0 < n < len(buf) else path | 17 | return buf.value if 0 < n < len(buf) else path |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | def _encodes(char): | ||
| 21 | try: | ||
| 22 | char.encode("oem") | ||
| 23 | return True | ||
| 24 | except UnicodeEncodeError: | ||
| 25 | return False | ||
| 26 | |||
| 27 | |||
| 20 | def write_python_cmd(cmd_path, python, script): | 28 | def write_python_cmd(cmd_path, python, script): |
| 21 | """Write cmd_path as a batch file that runs `python script` with the batch file's arguments.""" | 29 | """Write cmd_path as a batch file that runs `python script` with the batch file's arguments. |
| 22 | # "oem" for a path that keeps non-ASCII letters (no short name): the code page cmd.exe reads it with. | 30 | |
| 23 | with open(cmd_path, "w", encoding="oem") as f: | 31 | Raises unittest.SkipTest when a path has no 8.3 name and letters outside the OEM code page (Cyrillic on a |
| 24 | f.write(f'@"{batch_path(python)}" "{batch_path(script)}" %*\n') | 32 | cp850 machine with 8.3 names off, say): cmd.exe couldn't run such a file in any encoding.""" |
| 33 | line = f'@"{batch_path(python)}" "{batch_path(script)}" %*\n' | ||
| 34 | try: | ||
| 35 | data = line.encode("oem") # the code page cmd.exe reads a batch file with | ||
| 36 | except UnicodeEncodeError: | ||
| 37 | import unittest | ||
| 38 | # Windows' "oem" codec doesn't report a useful position, so name the letters it can't encode here. | ||
| 39 | letters = "".join(sorted({c for c in line if not _encodes(c)})) | ||
| 40 | raise unittest.SkipTest(f"{letters!r} in a path has no 8.3 name and is outside the OEM code page," | ||
| 41 | " so cmd.exe can't run a batch file that names it; use an ASCII TEMP") from None | ||
| 42 | with open(cmd_path, "wb") as f: | ||
| 43 | f.write(data) | ||
| 25 | return cmd_path | 44 | return cmd_path |