Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,15 @@ def test_python_legacy_windows_fs_encoding(self):

@unittest.skipUnless(support.MS_WINDOWS, 'Test only applicable on Windows')
def test_python_legacy_windows_stdio(self):
code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding)"
expected = 'cp'
rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSSTDIO='1')
self.assertIn(expected.encode(), out)
code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding, file=sys.stderr)"
env = os.environ.copy()
env['PYTHONLEGACYWINDOWSSTDIO'] = '1'
p = subprocess.Popen([sys.executable, '-c', code],
stderr=subprocess.PIPE, env=env)
out = p.stderr.read()
p.stderr.close()
p.wait()
self.assertNotIn(b'utf-8', out)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be true. It's entirely possible to set the default encoding to UTF-8 in Windows itself, at which point the legacy stdio will also be UTF-8.

Checking the type of the stdin/stdout objects in the subprocess is probably the best way. The real purpose of this environment variable is to go back to using FileIO rather than _WindowsConsoleIO, and the encoding is only a side-effect of that.

And if we just make the child process assert, then we can check the exit code rather than reading the output.


@unittest.skipIf("-fsanitize" in sysconfig.get_config_vars().get('PY_CFLAGS', ()),
"PYTHONMALLOCSTATS doesn't work with ASAN")
Expand Down
Loading