From e5ac6da78e3433a1b94676f6523e358d6089f263 Mon Sep 17 00:00:00 2001 From: kaliko Date: Wed, 4 Nov 2015 12:05:21 +0100 Subject: [PATCH] Prevent adding empty track to history (Closes #5) --- sima/lib/track.py | 2 ++ sima/plugins/core/history.py | 4 +++- tests/test_track.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sima/lib/track.py b/sima/lib/track.py index 4a2e720..a774a4c 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -99,6 +99,8 @@ class Track: return hash(self) != hash(other) def __bool__(self): + if not self._file: + return False return not self._empty @property diff --git a/sima/plugins/core/history.py b/sima/plugins/core/history.py index b791053..ae98a3f 100644 --- a/sima/plugins/core/history.py +++ b/sima/plugins/core/history.py @@ -42,7 +42,9 @@ class History(Plugin): def callback_next_song(self): current = self.player.current - self.log.debug('add history: "{}"'.format(current)) + self.log.debug('add history: "%s"', current) + if not current: + self.log.warning('Cannot add "%s" to history (empty or missing file)', current) self.sdb.add_history(current) diff --git a/tests/test_track.py b/tests/test_track.py index 80a709e..62eb306 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -33,6 +33,8 @@ class TestTrackObject(unittest.TestCase): def test_boolean_type(self): self.assertFalse(bool(Track())) + for trk in [{}, {'artist': 'Devolt'}, {'artist': 'Devolt', 'file':''}]: + self.assertFalse(bool(Track(**trk))) def test_albumartist(self): trk = Track(albumartist='album_artist', artist='track_artist') -- 2.39.5