diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 750d78bf7..dc3b8150d 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -329,7 +329,7 @@ class FfmpegBackend(Backend): def sum_of_track_powers(track_gain, track_n_blocks): # convert `LU to target_level` -> LUFS - loudness = target_level_lufs - track_gain + loudness = target_level_lufs - track_gain.gain # This reverses ITU-R BS.1770-4 p. 6 equation (5) to convert # from loudness to power. The result is the average gating @@ -586,7 +586,7 @@ class CommandBackend(Backend): When computing album gain, the last TrackGain object returned is the album gain """ - if len(items) == 0: + if not items: self._log.debug('no supported tracks to analyze') return [] @@ -1375,7 +1375,7 @@ class ReplayGainPlugin(BeetsPlugin): pass def close_pool(self): - """Regularly lose the `ThreadPool` instance in `self.pool`. + """Regularly close the `ThreadPool` instance in `self.pool`. """ if self.pool is not None: self.pool.close() diff --git a/test/helper.py b/test/helper.py index 5ee8263eb..c1412cc43 100644 --- a/test/helper.py +++ b/test/helper.py @@ -373,11 +373,20 @@ class TestHelper: items.append(item) return items - def add_album_fixture(self, track_count=1, ext='mp3', disc_count=1): + def add_album_fixture( + self, + track_count=1, + fname='full', + ext='mp3', + disc_count=1, + ): """Add an album with files to the database. """ items = [] - path = os.path.join(_common.RSRC, util.bytestring_path('full.' + ext)) + path = os.path.join( + _common.RSRC, + util.bytestring_path(f'{fname}.{ext}'), + ) for discnumber in range(1, disc_count + 1): for i in range(track_count): item = Item.from_path(path) diff --git a/test/rsrc/whitenoise.flac b/test/rsrc/whitenoise.flac new file mode 100644 index 000000000..08724d514 Binary files /dev/null and b/test/rsrc/whitenoise.flac differ diff --git a/test/rsrc/whitenoise.mp3 b/test/rsrc/whitenoise.mp3 new file mode 100644 index 000000000..5d178b6ed Binary files /dev/null and b/test/rsrc/whitenoise.mp3 differ diff --git a/test/rsrc/whitenoise.opus b/test/rsrc/whitenoise.opus new file mode 100644 index 000000000..0cb70bc15 Binary files /dev/null and b/test/rsrc/whitenoise.opus differ diff --git a/test/test_replaygain.py b/test/test_replaygain.py index 47e27b844..554fe98e3 100644 --- a/test/test_replaygain.py +++ b/test/test_replaygain.py @@ -85,6 +85,8 @@ class FfmpegBackendMixin(): class ReplayGainCliTestBase(TestHelper): + FNAME: str + def setUp(self): # Implemented by Mixins, see above. This may decide to skip the test. self.test_backend() @@ -99,7 +101,8 @@ class ReplayGainCliTestBase(TestHelper): self.unload_plugins() def _add_album(self, *args, **kwargs): - album = self.add_album_fixture(*args, **kwargs) + # Use a file with non-zero volume (most test assets are total silence) + album = self.add_album_fixture(*args, fname=self.FNAME, **kwargs) for item in album.items(): reset_replaygain(item) @@ -305,19 +308,25 @@ class ReplayGainCliTestBase(TestHelper): @unittest.skipIf(not GST_AVAILABLE, 'gstreamer cannot be found') class ReplayGainGstCliTest(ReplayGainCliTestBase, unittest.TestCase, GstBackendMixin): - pass + FNAME = "full" # file contains only silence @unittest.skipIf(not GAIN_PROG_AVAILABLE, 'no *gain command found') class ReplayGainCmdCliTest(ReplayGainCliTestBase, unittest.TestCase, CmdBackendMixin): - pass + FNAME = "full" # file contains only silence @unittest.skipIf(not FFMPEG_AVAILABLE, 'ffmpeg cannot be found') class ReplayGainFfmpegCliTest(ReplayGainCliTestBase, unittest.TestCase, FfmpegBackendMixin): - pass + FNAME = "full" # file contains only silence + + +@unittest.skipIf(not FFMPEG_AVAILABLE, 'ffmpeg cannot be found') +class ReplayGainFfmpegNoiseCliTest(ReplayGainCliTestBase, unittest.TestCase, + FfmpegBackendMixin): + FNAME = "whitenoise" class ImportTest(TestHelper):