@@ -976,11 +976,19 @@ def test_python_legacy_windows_fs_encoding(self):
976976
977977 @unittest .skipUnless (support .MS_WINDOWS , 'Test only applicable on Windows' )
978978 def test_python_legacy_windows_stdio (self ):
979- code = 'import sys; print(sys.stdin.encoding, sys.stdout.encoding)'
980- expected = 'cp'
981- rc , out , err = assert_python_ok ('-Xutf8=0' , '-c' , code ,
982- PYTHONLEGACYWINDOWSSTDIO = '1' )
983- self .assertIn (expected .encode (), out )
979+ def get_stderr_class (legacy_windows_stdio ):
980+ code = 'import sys; print(type(sys.stderr.buffer.raw))'
981+ env = {'PYTHONLEGACYWINDOWSSTDIO' : str (int (legacy_windows_stdio ))}
982+ # use stderr=None as legacy_windows_stdio doesn't affect pipes
983+ p = spawn_python ('-c' , code , env = env , stderr = None )
984+ out = kill_python (p ).strip ().decode ('ascii' , 'ignore' )
985+ return out .removeprefix ("<class '" ).removesuffix ("'>" )
986+
987+ out = get_stderr_class (legacy_windows_stdio = True )
988+ self .assertEqual ('_io.FileIO' , out )
989+
990+ out = get_stderr_class (legacy_windows_stdio = False )
991+ self .assertEqual ('_io._WindowsConsoleIO' , out )
984992
985993 @unittest .skipIf ("-fsanitize" in sysconfig .get_config_vars ().get ('PY_CFLAGS' , ()),
986994 "PYTHONMALLOCSTATS doesn't work with ASAN" )
0 commit comments