diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index db4d202a6..acf996bd2 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -43,6 +43,11 @@ class FatalReplayGainError(Exception): """ +class FatalGstreamerPluginReplayGainError(FatalReplayGainError): + """Raised when a fatal error occurs in the GStreamerBackend when + loading the required plugins.""" + + def call(args): """Execute the command and return its output or raise a ReplayGainError on failure. @@ -391,7 +396,7 @@ class GStreamerBackend(Backend): if self._src is None or self._decbin is None or self._conv is None \ or self._res is None or self._rg is None: - raise FatalReplayGainError( + raise FatalGstreamerPluginReplayGainError( "Failed to load required GStreamer plugins" ) diff --git a/test/test_replaygain.py b/test/test_replaygain.py index edbfb96db..5b20f5f3b 100644 --- a/test/test_replaygain.py +++ b/test/test_replaygain.py @@ -20,7 +20,10 @@ from __future__ import (division, absolute_import, print_function, from test._common import unittest from test.helper import TestHelper, has_program +from beets import config from beets.mediafile import MediaFile +from beetsplug.replaygain import (FatalGstreamerPluginReplayGainError, + GStreamerBackend) try: import gi @@ -87,6 +90,13 @@ class ReplayGainCliTestBase(TestHelper): self.assertIsNone(mediafile.rg_track_gain) self.run_command('replaygain') + + # Skip the test if rg_track_peak and rg_track gain is None, assuming + # that it could only happen if the decoder plugins are missing. + if all(i.rg_track_peak is None and i.rg_track_gain is None + for i in self.lib.items()): + self.skipTest('decoder plugins could not be loaded.') + for item in self.lib.items(): self.assertIsNotNone(item.rg_track_peak) self.assertIsNotNone(item.rg_track_gain) @@ -132,6 +142,18 @@ class ReplayGainCliTestBase(TestHelper): class ReplayGainGstCliTest(ReplayGainCliTestBase, unittest.TestCase): backend = u'gstreamer' + def setUp(self): + try: + # Check if required plugins can be loaded by instantiating a + # GStreamerBackend (via its .__init__). + config['replaygain']['targetlevel'] = 89 + GStreamerBackend(config['replaygain'], None) + except FatalGstreamerPluginReplayGainError as e: + # Skip the test if plugins could not be loaded. + self.skipTest(str(e)) + + super(ReplayGainGstCliTest, self).setUp() + @unittest.skipIf(not GAIN_PROG_AVAILABLE, 'no *gain command found') class ReplayGainCmdCliTest(ReplayGainCliTestBase, unittest.TestCase):