@@ -496,11 +496,16 @@ def __hash__(self):
496496 self .assertRaises (TypeError , sys .intern , S ("abc" ))
497497
498498 def test_undecodable_code (self ):
499- non_decodable = b"\xff "
499+ # Raise SkipTest() if sys.executable is not encodable to ascii
500+ test .support .workaroundIssue8611 ()
501+
502+ undecodable = b"\xff "
500503 env = os .environ .copy ()
501504 env ['LANG' ] = 'C'
502- code = b'import locale; '
503- code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())'
505+ code = (
506+ b'import locale; '
507+ b'print(ascii("' + undecodable + b'"), '
508+ b'locale.getpreferredencoding())' )
504509 p = subprocess .Popen (
505510 [sys .executable , "-c" , code ],
506511 stdout = subprocess .PIPE , stderr = subprocess .STDOUT ,
@@ -587,28 +592,23 @@ def get_fsencoding(env):
587592 env = env )
588593 return output .rstrip ().decode ('ascii' )
589594
595+ # Raise SkipTest() if sys.executable is not encodable to ascii
596+ test .support .workaroundIssue8611 ()
597+
598+ # Even in C locale
599+ env = os .environ .copy ()
600+ env ['LANG' ] = 'C'
590601 try :
591- sys .executable .encode ('ascii' )
592- except UnicodeEncodeError :
593- # Python doesn't start with ASCII locale if its path is not ASCII,
594- # see issue #8611
602+ del env ['PYTHONFSENCODING' ]
603+ except KeyError :
595604 pass
596- else :
597- # Even in C locale
598- env = os .environ .copy ()
599- env ['LANG' ] = 'C'
600- try :
601- del env ['PYTHONFSENCODING' ]
602- except KeyError :
603- pass
604- self .check_fsencoding (get_fsencoding (env ), 'ascii' )
605-
606- # Filesystem encoding is hardcoded on Windows and Mac OS X
607- for encoding in ('ascii' , 'cp850' , 'iso8859-1' , 'utf-8' ):
608- env = os .environ .copy ()
609- env ['PYTHONFSENCODING' ] = encoding
610- self .check_fsencoding (get_fsencoding (env ), encoding )
605+ self .check_fsencoding (get_fsencoding (env ), 'ascii' )
611606
607+ # Filesystem encoding is hardcoded on Windows and Mac OS X
608+ for encoding in ('ascii' , 'cp850' , 'iso8859-1' , 'utf-8' ):
609+ env = os .environ .copy ()
610+ env ['PYTHONFSENCODING' ] = encoding
611+ self .check_fsencoding (get_fsencoding (env ), encoding )
612612
613613 def test_setfilesystemencoding (self ):
614614 old = sys .getfilesystemencoding ()
0 commit comments