@@ -972,10 +972,25 @@ def test_python_legacy_windows_fs_encoding(self):
972
972
973
973
@unittest .skipUnless (support .MS_WINDOWS , 'Test only applicable on Windows' )
974
974
def test_python_legacy_windows_stdio (self ):
975
- code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding)"
976
- expected = 'cp'
977
- rc , out , err = assert_python_ok ('-c' , code , PYTHONLEGACYWINDOWSSTDIO = '1' )
978
- self .assertIn (expected .encode (), out )
975
+ # Test that _WindowsConsoleIO is used when PYTHONLEGACYWINDOWSSTDIO
976
+ # is not set.
977
+ # We cannot use PIPE becase it prevents creating new console.
978
+ # So we use exit code.
979
+ code = "import sys; sys.exit(type(sys.stdout.buffer.raw).__name__ != '_WindowsConsoleIO')"
980
+ env = os .environ .copy ()
981
+ env ["PYTHONLEGACYWINDOWSSTDIO" ] = ""
982
+ p = subprocess .run ([sys .executable , "-c" , code ],
983
+ creationflags = subprocess .CREATE_NEW_CONSOLE ,
984
+ env = env )
985
+ self .assertEqual (p .returncode , 0 )
986
+
987
+ # Then test that FIleIO is used when PYTHONLEGACYWINDOWSSTDIO is set.
988
+ code = "import sys; sys.exit(type(sys.stdout.buffer.raw).__name__ != 'FileIO')"
989
+ env ["PYTHONLEGACYWINDOWSSTDIO" ] = "1"
990
+ p = subprocess .run ([sys .executable , "-c" , code ],
991
+ creationflags = subprocess .CREATE_NEW_CONSOLE ,
992
+ env = env )
993
+ self .assertEqual (p .returncode , 0 )
979
994
980
995
@unittest .skipIf ("-fsanitize" in sysconfig .get_config_vars ().get ('PY_CFLAGS' , ()),
981
996
"PYTHONMALLOCSTATS doesn't work with ASAN" )
0 commit comments