Skip to content

Commit 7b70fbc

Browse files
committed
Run the pipe encoding test through this interpreter, not cat
The test piped through `cat`, which cmd.exe does not provide. On a Windows system without Unix utilities installed it would fail before reaching the encoding behavior it exists to check -- and Windows is exactly what the UTF-8 redirection fix targets. Use a sys.executable pass-through instead, matching the pipe tests already in tests/test_command_toolbar.py. Reverting either the pipe or the redirect encoding still fails these tests.
1 parent be0026e commit 7b70fbc

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎tests/test_suite_environment.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import os
9+
import sys
910

1011
import pytest
1112

@@ -45,9 +46,14 @@ def test_redirection_to_a_file_uses_utf8(tmp_path) -> None:
4546
assert "ENCODING=utf-8" in target.read_text(encoding="utf-8")
4647

4748

49+
#: A pass-through filter, run with this interpreter so the test does not depend on Unix
50+
#: utilities being installed. `cmd.exe` has no `cat`, and this fix exists for Windows.
51+
PASS_THROUGH = "import sys; sys.stdin.reconfigure(encoding='utf-8'); sys.stdout.write(sys.stdin.read())"
52+
53+
4854
def test_piping_uses_utf8(tmp_path) -> None:
4955
"""The same applies to the pipe the subprocess reads from."""
5056
app = EncodingProbe(allow_cli_args=False)
5157
target = tmp_path / "piped.txt"
52-
app.onecmd_plus_hooks(f'show_encoding | cat > "{target}"')
58+
app.onecmd_plus_hooks(f'show_encoding | "{sys.executable}" -c "{PASS_THROUGH}" > "{target}"')
5359
assert "ENCODING=utf-8" in target.read_text(encoding="utf-8")

0 commit comments

Comments
 (0)