@@ -544,6 +544,42 @@ def test_ioencoding(self):
544544 out = p .communicate ()[0 ].strip ()
545545 self .assertEqual (out , b'?' )
546546
547+ env ["PYTHONIOENCODING" ] = "ascii"
548+ p = subprocess .Popen ([sys .executable , "-c" , 'print(chr(0xa2))' ],
549+ stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
550+ env = env )
551+ out , err = p .communicate ()
552+ self .assertEqual (out , b'' )
553+ self .assertIn (b'UnicodeEncodeError:' , err )
554+ self .assertIn (rb"'\xa2'" , err )
555+
556+ env ["PYTHONIOENCODING" ] = "ascii:"
557+ p = subprocess .Popen ([sys .executable , "-c" , 'print(chr(0xa2))' ],
558+ stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
559+ env = env )
560+ out , err = p .communicate ()
561+ self .assertEqual (out , b'' )
562+ self .assertIn (b'UnicodeEncodeError:' , err )
563+ self .assertIn (rb"'\xa2'" , err )
564+
565+ env ["PYTHONIOENCODING" ] = ":surrogateescape"
566+ p = subprocess .Popen ([sys .executable , "-c" , 'print(chr(0xdcbd))' ],
567+ stdout = subprocess .PIPE , env = env )
568+ out = p .communicate ()[0 ].strip ()
569+ self .assertEqual (out , b'\xbd ' )
570+
571+ @unittest .skipUnless (test .support .FS_NONASCII ,
572+ 'requires OS support of non-ASCII encodings' )
573+ def test_ioencoding_nonascii (self ):
574+ env = dict (os .environ )
575+
576+ env ["PYTHONIOENCODING" ] = ""
577+ p = subprocess .Popen ([sys .executable , "-c" ,
578+ 'print(%a)' % test .support .FS_NONASCII ],
579+ stdout = subprocess .PIPE , env = env )
580+ out = p .communicate ()[0 ].strip ()
581+ self .assertEqual (out , os .fsencode (test .support .FS_NONASCII ))
582+
547583 @unittest .skipIf (sys .base_prefix != sys .prefix ,
548584 'Test is not venv-compatible' )
549585 def test_executable (self ):
0 commit comments