summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-05-20 06:53:44 (GMT)
committerGitHub <noreply@github.com>2025-05-20 06:53:44 (GMT)
commit90aa13ae478f1eb1d5d02867382c33ee7670ab5c (patch)
tree580f992f3e251289f999afe631d9cf95ea4ba14f
parent07a2033fcfabcbfb28450f3106b396b474561e57 (diff)
downloadcpython-90aa13ae478f1eb1d5d02867382c33ee7670ab5c.zip
cpython-90aa13ae478f1eb1d5d02867382c33ee7670ab5c.tar.gz
cpython-90aa13ae478f1eb1d5d02867382c33ee7670ab5c.tar.bz2
[3.14] gh-133374: fix test_python_legacy_windows_stdio (GH-134080) (GH-134314)
(cherry picked from commit 652d6938ef8c42c1c4c180c3f0e257c26c6677da) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
-rw-r--r--Lib/test/test_cmd_line.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 1b40e0d..f540973 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -972,10 +972,25 @@ class CmdLineTest(unittest.TestCase):
@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)
+ # Test that _WindowsConsoleIO is used when PYTHONLEGACYWINDOWSSTDIO
+ # is not set.
+ # We cannot use PIPE becase it prevents creating new console.
+ # So we use exit code.
+ code = "import sys; sys.exit(type(sys.stdout.buffer.raw).__name__ != '_WindowsConsoleIO')"
+ env = os.environ.copy()
+ env["PYTHONLEGACYWINDOWSSTDIO"] = ""
+ p = subprocess.run([sys.executable, "-c", code],
+ creationflags=subprocess.CREATE_NEW_CONSOLE,
+ env=env)
+ self.assertEqual(p.returncode, 0)
+
+ # Then test that FIleIO is used when PYTHONLEGACYWINDOWSSTDIO is set.
+ code = "import sys; sys.exit(type(sys.stdout.buffer.raw).__name__ != 'FileIO')"
+ env["PYTHONLEGACYWINDOWSSTDIO"] = "1"
+ p = subprocess.run([sys.executable, "-c", code],
+ creationflags=subprocess.CREATE_NEW_CONSOLE,
+ env=env)
+ self.assertEqual(p.returncode, 0)
@unittest.skipIf("-fsanitize" in sysconfig.get_config_vars().get('PY_CFLAGS', ()),
"PYTHONMALLOCSTATS doesn't work with ASAN")