From ea0434456000c4754a964a314f3332b37bf90f87 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Thu, 17 Apr 2014 12:11:14 +0200 Subject: [PATCH] Test and fix unicode issues in logs. Fixes #699 The helper functions for creating test fixtures now include unicode characters. --- beetsplug/convert.py | 3 ++- beetsplug/replaygain.py | 5 +++-- test/helper.py | 23 +++++++++++++++++++++-- test/test_replaygain.py | 20 +++----------------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 23f223662..2d8984f5d 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -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) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 54566be11..55593fa15 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -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, diff --git a/test/helper.py b/test/helper.py index 2dbef8e48..56580411d 100644 --- a/test/helper.py +++ b/test/helper.py @@ -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. diff --git a/test/test_replaygain.py b/test/test_replaygain.py index 1e5a675de..12678f469 100644 --- a/test/test_replaygain.py +++ b/test/test_replaygain.py @@ -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