Skip to content

Commit

Permalink
Merge pull request #2583 from yacoob/master
Browse files Browse the repository at this point in the history
Fix a lastgenre crash
  • Loading branch information
sampsyo committed Jun 11, 2017
2 parents f6dc981 + f6830b4 commit 15a7dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
12 changes: 12 additions & 0 deletions test/test_lastgenre.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit 15a7dfc

Please sign in to comment.