mirror of
https://github.com/beetbox/beets.git
synced 2026-01-01 13:33:02 +01:00
replaygain test: reorganize backend handling
in an attempt to make it simpler to add new test classes
This commit is contained in:
parent
80f7c58e5a
commit
1442594e5b
1 changed files with 52 additions and 21 deletions
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Reference in a new issue