4646def check_output (cmd , encoding = None ):
4747 p = subprocess .Popen (cmd ,
4848 stdout = subprocess .PIPE ,
49- stderr = subprocess .PIPE ,
50- encoding = encoding )
49+ stderr = subprocess .PIPE )
5150 out , err = p .communicate ()
5251 if p .returncode :
5352 if verbose and err :
54- print (err .decode ('utf-8' , 'backslashreplace' ))
53+ print (err .decode (encoding or 'utf-8' , 'backslashreplace' ))
5554 raise subprocess .CalledProcessError (
5655 p .returncode , cmd , out , err )
56+ if encoding :
57+ return (
58+ out .decode (encoding , 'backslashreplace' ),
59+ err .decode (encoding , 'backslashreplace' ),
60+ )
5761 return out , err
5862
5963class BaseTest (unittest .TestCase ):
@@ -281,8 +285,8 @@ def test_sysconfig(self):
281285 ('get_config_h_filename()' , sysconfig .get_config_h_filename ())):
282286 with self .subTest (call ):
283287 cmd [2 ] = 'import sysconfig; print(sysconfig.%s)' % call
284- out , err = check_output (cmd )
285- self .assertEqual (out .strip (), expected . encode () , err )
288+ out , err = check_output (cmd , encoding = 'utf-8' )
289+ self .assertEqual (out .strip (), expected , err )
286290
287291 @requireVenvCreate
288292 @unittest .skipUnless (can_symlink (), 'Needs symlinks' )
@@ -303,8 +307,8 @@ def test_sysconfig_symlinks(self):
303307 ('get_config_h_filename()' , sysconfig .get_config_h_filename ())):
304308 with self .subTest (call ):
305309 cmd [2 ] = 'import sysconfig; print(sysconfig.%s)' % call
306- out , err = check_output (cmd )
307- self .assertEqual (out .strip (), expected . encode () , err )
310+ out , err = check_output (cmd , encoding = 'utf-8' )
311+ self .assertEqual (out .strip (), expected , err )
308312
309313 if sys .platform == 'win32' :
310314 ENV_SUBDIRS = (
0 commit comments