-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-133374: Fix test_python_legacy_windows_stdio in test_cmd_line #133375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| # Most tests are executed with environment variables ignored | ||
| # See test_cmd_line_script.py for testing of script execution | ||
|
|
||
| import io | ||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
@@ -971,11 +972,19 @@ def test_python_legacy_windows_fs_encoding(self): | |
| self.assertIn(expected.encode(), out) | ||
|
|
||
| @unittest.skipUnless(support.MS_WINDOWS, 'Test only applicable on Windows') | ||
| @unittest.skipUnless(type(sys.stdin.buffer.raw) == io._WindowsConsoleIO, | ||
| 'Requires real console handles') | ||
| 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' | ||
| # Use Popen directly to ensure stdin/out are console handles | ||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 And if we just make the child process |
||
|
|
||
| @unittest.skipIf("-fsanitize" in sysconfig.get_config_vars().get('PY_CFLAGS', ()), | ||
| "PYTHONMALLOCSTATS doesn't work with ASAN") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.