mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
embedart: fix behaviour on IM unparseable output, add tests
Test all EmbedCoverArtPlugin.check_art_similarity() code paths. Improve #1241.
This commit is contained in:
parent
29739dbe04
commit
b436e75a9e
2 changed files with 36 additions and 0 deletions
|
|
@ -211,6 +211,7 @@ class EmbedCoverArtPlugin(BeetsPlugin):
|
|||
except ValueError:
|
||||
self._log.debug(u'IM output is not a number: {0!r}',
|
||||
out_str)
|
||||
return
|
||||
|
||||
self._log.info(u'compare PHASH score is {0}', phash_diff)
|
||||
if phash_diff > compare_threshold:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
# included in all copies or substantial portions of the Software.
|
||||
|
||||
import os.path
|
||||
from mock import Mock, patch
|
||||
|
||||
import _common
|
||||
from _common import unittest
|
||||
from helper import TestHelper, capture_log
|
||||
|
|
@ -21,6 +23,7 @@ from beets.mediafile import MediaFile
|
|||
from beets import config, logging
|
||||
from beets.util import syspath
|
||||
from beets.util.artresizer import ArtResizer
|
||||
from beetsplug.embedart import EmbedCoverArtPlugin
|
||||
|
||||
|
||||
def require_artresizer_compare(test):
|
||||
|
|
@ -110,6 +113,38 @@ class EmbedartCliTest(unittest.TestCase, TestHelper):
|
|||
self.abbey_similarpath))
|
||||
|
||||
|
||||
class EmbedartTest(unittest.TestCase):
|
||||
@patch('beetsplug.embedart.subprocess')
|
||||
def test_imagemagick_response(self, mock_subprocess):
|
||||
embed = EmbedCoverArtPlugin()
|
||||
embed.extract = Mock(return_value=True)
|
||||
proc = mock_subprocess.Popen.return_value
|
||||
|
||||
# everything is fine
|
||||
proc.returncode = 0
|
||||
proc.communicate.return_value = "10", "tagada"
|
||||
self.assertTrue(embed.check_art_similarity(None, None, 20))
|
||||
self.assertFalse(embed.check_art_similarity(None, None, 5))
|
||||
|
||||
# small failure
|
||||
proc.returncode = 1
|
||||
proc.communicate.return_value = "tagada", "10"
|
||||
self.assertTrue(embed.check_art_similarity(None, None, 20))
|
||||
self.assertFalse(embed.check_art_similarity(None, None, 5))
|
||||
|
||||
# bigger failure
|
||||
proc.returncode = 2
|
||||
self.assertIsNone(embed.check_art_similarity(None, None, 20))
|
||||
|
||||
# IM result parsing problems
|
||||
proc.returncode = 0
|
||||
proc.communicate.return_value = "foo", "bar"
|
||||
self.assertIsNone(embed.check_art_similarity(None, None, 20))
|
||||
|
||||
proc.returncode = 1
|
||||
self.assertIsNone(embed.check_art_similarity(None, None, 20))
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue