From ee46a5150f4d97f03eaef509d098f739f3ae88ce Mon Sep 17 00:00:00 2001 From: Jakub Turski Date: Fri, 2 Jun 2017 15:48:05 +0100 Subject: [PATCH 1/4] Don't crash if non-canonical genre and prefer_specific: yes. Also, add a test for this. --- beetsplug/lastgenre/__init__.py | 1 + test/test_lastgenre.py | 11 +++++++++++ 2 files changed, 12 insertions(+) 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..db2ea903ec 100644 --- a/test/test_lastgenre.py +++ b/test/test_lastgenre.py @@ -213,6 +213,17 @@ 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,count=99) + # 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__) From a43f5fdace8631b836998a040a25acd27731f565 Mon Sep 17 00:00:00 2001 From: Jakub Turski Date: Fri, 2 Jun 2017 15:50:58 +0100 Subject: [PATCH 2/4] Remove unnecessary test setup parameter. --- test/test_lastgenre.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_lastgenre.py b/test/test_lastgenre.py index db2ea903ec..d8ba60cf94 100644 --- a/test/test_lastgenre.py +++ b/test/test_lastgenre.py @@ -214,7 +214,7 @@ def mock_fetch_artist_genre(self, obj): u'fallback')) def test_sort_by_depth(self): - self._setup_config(canonical=True,count=99) + self._setup_config(canonical=True) # Normal case. tags = ('electronic', 'ambient', 'post-rock', 'downtempo') res = self.plugin._sort_by_depth(tags) From 0e7a0a62d43c23cb27b08c79246cffaa82a8f0a1 Mon Sep 17 00:00:00 2001 From: Jakub Turski Date: Fri, 2 Jun 2017 16:04:05 +0100 Subject: [PATCH 3/4] Fix excessive line length. --- test/test_lastgenre.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_lastgenre.py b/test/test_lastgenre.py index d8ba60cf94..18cb81a0a9 100644 --- a/test/test_lastgenre.py +++ b/test/test_lastgenre.py @@ -218,7 +218,8 @@ def test_sort_by_depth(self): # Normal case. tags = ('electronic', 'ambient', 'post-rock', 'downtempo') res = self.plugin._sort_by_depth(tags) - self.assertEqual(res, ['post-rock', 'downtempo', 'ambient', 'electronic']) + self.assertEqual( + res, ['post-rock', 'downtempo', 'ambient', 'electronic']) # Non-canonical tag ('chillout') present. tags = ('electronic', 'ambient', 'chillout') res = self.plugin._sort_by_depth(tags) From f6830b4bc3dafcef2f71a92904213e0905e02ae7 Mon Sep 17 00:00:00 2001 From: Jakub Turski Date: Fri, 2 Jun 2017 16:27:49 +0100 Subject: [PATCH 4/4] Here, flake8, be happy. --- test/test_lastgenre.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_lastgenre.py b/test/test_lastgenre.py index 18cb81a0a9..a70c65ca10 100644 --- a/test/test_lastgenre.py +++ b/test/test_lastgenre.py @@ -219,7 +219,7 @@ def test_sort_by_depth(self): tags = ('electronic', 'ambient', 'post-rock', 'downtempo') res = self.plugin._sort_by_depth(tags) self.assertEqual( - res, ['post-rock', 'downtempo', 'ambient', 'electronic']) + res, ['post-rock', 'downtempo', 'ambient', 'electronic']) # Non-canonical tag ('chillout') present. tags = ('electronic', 'ambient', 'chillout') res = self.plugin._sort_by_depth(tags)