From 66b81ed081ede147800eeef79f1817f169fea8e0 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Tue, 2 Dec 2014 11:54:36 +0100 Subject: [PATCH] echonest: test conversion failure --- beetsplug/echonest.py | 5 +++-- test/test_echonest.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/beetsplug/echonest.py b/beetsplug/echonest.py index a59d59d96..a3cf9495a 100644 --- a/beetsplug/echonest.py +++ b/beetsplug/echonest.py @@ -267,7 +267,7 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin): if item.format not in ALLOWED_FORMATS: if config['echonest']['convert']: tmp = source = self.convert(source) - else: + if not tmp: return if os.stat(source).st_size > UPLOAD_MAX_SIZE: @@ -279,7 +279,8 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin): else: return - return (source, tmp) + if source: + return (source, tmp) def convert(self, source): """Converts an item in an unsupported media format to ogg. Config diff --git a/test/test_echonest.py b/test/test_echonest.py index bdaf6e229..d845b8a6b 100644 --- a/test/test_echonest.py +++ b/test/test_echonest.py @@ -106,6 +106,23 @@ class EchonestCliTest(unittest.TestCase, TestHelper): self.assertNotEqual(item.path, echonest_track.call_args[1]['filename']) + @patch('pyechonest.song.profile') + @patch('pyechonest.song.search') + @patch('pyechonest.track.track_from_filename') + @patch('beetsplug.echonest.CONVERT_COMMAND', 'false') + def test_analyze_convert_fail(self, echonest_track, echonest_search, + echonest_profile): + item = self.add_item(title='title', length=10, format='FLAC', + path=os.path.join(RSRC, 'min.flac')) + echonest_search.return_value = [] + echonest_profile.return_value = [self.profile(item, energy=0.2)] + echonest_track.return_value = self.track(item) + + self.run_command('echonest') + item.load() + self.assertNotIn('energy', item) + self.assertEqual(0, echonest_track.call_count) + @patch('pyechonest.song.profile') @patch('pyechonest.song.search') @patch('pyechonest.track.track_from_filename')