Fix test.helper.has_program(): encode command

subprocess.subprocess.check_call() should receive a byte string command
otherwise it fails with a UnicodeDecodeError on systems with non-ascii
elements in the system path.

Discovered while reviewing PR #1344.
This commit is contained in:
Bruno Cauet 2015-03-04 12:09:40 +01:00
parent 8113c7ba85
commit 69786b8538

View file

@ -51,6 +51,7 @@ from beets.library import Library, Item, Album
from beets import importer
from beets.autotag.hooks import AlbumInfo, TrackInfo
from beets.mediafile import MediaFile, Image
from beets.ui import _encoding
# TODO Move AutotagMock here
from test import _common
@ -117,9 +118,13 @@ def capture_stdout():
def has_program(cmd, args=['--version']):
"""Returns `True` if `cmd` can be executed.
"""
full_cmd = [cmd] + args
for i, elem in enumerate(full_cmd):
if isinstance(elem, unicode):
full_cmd[i] = elem.encode(_encoding())
try:
with open(os.devnull, 'wb') as devnull:
subprocess.check_call([cmd] + args, stderr=devnull,
subprocess.check_call(full_cmd, stderr=devnull,
stdout=devnull, stdin=devnull)
except OSError:
return False