diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 2756f452c0..4374310ba3 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -174,6 +174,7 @@ def _sort_by_depth(self, tags): genre tree. """ depth_tag_pairs = [(self._get_depth(t), t) for t in tags] + depth_tag_pairs = [e for e in depth_tag_pairs if e[0] is not None] depth_tag_pairs.sort(reverse=True) return [p[1] for p in depth_tag_pairs] diff --git a/test/test_lastgenre.py b/test/test_lastgenre.py index f57471f1cf..a70c65ca10 100644 --- a/test/test_lastgenre.py +++ b/test/test_lastgenre.py @@ -213,6 +213,18 @@ def mock_fetch_artist_genre(self, obj): self.assertEqual(res, (config['lastgenre']['fallback'].get(), u'fallback')) + def test_sort_by_depth(self): + self._setup_config(canonical=True) + # Normal case. + tags = ('electronic', 'ambient', 'post-rock', 'downtempo') + res = self.plugin._sort_by_depth(tags) + self.assertEqual( + res, ['post-rock', 'downtempo', 'ambient', 'electronic']) + # Non-canonical tag ('chillout') present. + tags = ('electronic', 'ambient', 'chillout') + res = self.plugin._sort_by_depth(tags) + self.assertEqual(res, ['ambient', 'electronic']) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)