diff --git a/test/test_replaygain.py b/test/test_replaygain.py index e63034a26..4d22f3208 100644 --- a/test/test_replaygain.py +++ b/test/test_replaygain.py @@ -47,8 +47,48 @@ def reset_replaygain(item): item.store() +class GstBackendMixin(): + backend = 'gstreamer' + has_r128_support = True + + def test_backend(self): + """Check whether the backend actually has all required functionality. + """ + 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)) + + +class CmdBackendMixin(): + backend = 'command' + has_r128_support = False + + def test_backend(self): + """Check whether the backend actually has all required functionality. + """ + pass + + +class FfmpegBackendMixin(): + backend = 'ffmpeg' + has_r128_support = True + + def test_backend(self): + """Check whether the backend actually has all required functionality. + """ + pass + + class ReplayGainCliTestBase(TestHelper): def setUp(self): + # Implemented by Mixins, see above. This may decide to skip the test. + self.test_backend() + self.setup_beets(disk=True) self.config['replaygain']['backend'] = self.backend @@ -132,9 +172,9 @@ class ReplayGainCliTestBase(TestHelper): self.assertNotEqual(max(peaks), 0.0) def test_cli_writes_only_r128_tags(self): - if self.backend == "command": - # opus not supported by command backend - return + if not self.has_r128_support: + self.skipTest("r128 tags for opus not supported on backend {}" + .format(self.backend)) album = self._add_album(2, ext="opus") @@ -183,30 +223,21 @@ class ReplayGainCliTestBase(TestHelper): @unittest.skipIf(not GST_AVAILABLE, 'gstreamer cannot be found') -class ReplayGainGstCliTest(ReplayGainCliTestBase, unittest.TestCase): - backend = '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().setUp() +class ReplayGainGstCliTest(ReplayGainCliTestBase, unittest.TestCase, + GstBackendMixin): + pass @unittest.skipIf(not GAIN_PROG_AVAILABLE, 'no *gain command found') -class ReplayGainCmdCliTest(ReplayGainCliTestBase, unittest.TestCase): - backend = 'command' +class ReplayGainCmdCliTest(ReplayGainCliTestBase, unittest.TestCase, + CmdBackendMixin): + pass @unittest.skipIf(not FFMPEG_AVAILABLE, 'ffmpeg cannot be found') -class ReplayGainFfmpegTest(ReplayGainCliTestBase, unittest.TestCase): - backend = 'ffmpeg' +class ReplayGainFfmpegCliTest(ReplayGainCliTestBase, unittest.TestCase, + FfmpegBackendMixin): + pass def suite():