Test and fix unicode issues in logs. Fixes #699

The helper functions for creating test fixtures now include unicode characters.
This commit is contained in:
Thomas Scholtes 2014-04-17 12:11:14 +02:00
parent 115a0b06d3
commit ea04344560
4 changed files with 29 additions and 22 deletions

View file

@ -101,7 +101,8 @@ def encode(source, dest):
'dest': pipes.quote(dest),
})
log.debug(u'convert: executing: {0}'.format(command))
log.debug(u'convert: executing: {0}'
.format(util.displayable_path(command)))
try:
util.command_output(command, shell=True)

View file

@ -21,7 +21,7 @@ import sys
from beets import ui
from beets.plugins import BeetsPlugin
from beets.util import syspath, command_output
from beets.util import syspath, command_output, displayable_path
from beets import config
log = logging.getLogger('beets')
@ -179,7 +179,8 @@ class CommandBackend(Backend):
cmd = cmd + [syspath(i.path) for i in items]
log.debug(u'replaygain: analyzing {0} files'.format(len(items)))
log.debug(u"replaygain: executing %s" % " ".join(cmd))
log.debug(u"replaygain: executing {0}"
.format(" ".join(map(displayable_path, cmd))))
output = call(cmd)
log.debug(u'replaygain: analysis finished')
results = self.parse_tool_output(output,

View file

@ -204,16 +204,35 @@ class TestHelper(object):
paths=[import_dir])
def add_item_fixtures(self, ext='mp3', count=1):
"""Add a number of items with files to the database.
"""
items = []
paths = glob(os.path.join(_common.RSRC, '*.' + ext))
for path in paths[0:count]:
path = os.path.join(_common.RSRC, 'full.' + ext)
for i in range(count):
item = Item.from_path(str(path))
item.album = u'\xc3\xa4lbum {0}'.format(i) # Check unicode paths
item.title = u't\xc3\x8ftle {0}'.format(i)
item.add(self.lib)
item.move(copy=True)
item.store()
items.append(item)
return items
def add_album_fixture(self, track_count=1):
"""Add an album with files to the database.
"""
items = []
path = os.path.join(_common.RSRC, 'full.mp3')
for i in range(track_count):
item = Item.from_path(str(path))
item.album = u'\xc3\xa4lbum' # Check unicode paths
item.title = u't\xc3\x8ftle {0}'.format(i)
item.add(self.lib)
item.move(copy=True)
item.store()
items.append(item)
return self.lib.add_album(items)
def create_mediafile_fixture(self, ext='mp3'):
"""Copies a fixture mediafile with the extension to a temporary
location and returns the path.

View file

@ -50,28 +50,14 @@ class ReplayGainCliTestBase(TestHelper):
raise
self.config['replaygain']['backend'] = self.backend
self.config['plugins'] = ['replaygain']
self.setupLibrary(2)
album = self.add_album_fixture(2)
for item in album.items():
self._reset_replaygain(item)
def tearDown(self):
self.teardown_beets()
self.unload_plugins()
def setupLibrary(self, file_count):
"""Add an album to the library with ``file_count`` items.
"""
album = Album(id=1)
album.add(self.lib)
fixture_glob = os.path.join(_common.RSRC, '*.mp3')
for src in glob(fixture_glob)[0:file_count]:
dst = os.path.join(self.libdir, os.path.basename(src))
shutil.copy(src, dst)
item = Item.from_path(dst)
item.album_id = 1
item.add(self.lib)
self._reset_replaygain(item)
def _reset_replaygain(self, item):
item['rg_track_peak'] = None
item['rg_track_gain'] = None