mirror of
https://github.com/beetbox/beets.git
synced 2026-01-09 09:22:55 +01:00
Check for convert failures
This commit is contained in:
parent
ad74da1149
commit
1c1c73b062
2 changed files with 16 additions and 6 deletions
10
beets/art.py
10
beets/art.py
|
|
@ -149,9 +149,15 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
|
|||
convert_proc.stdout.close()
|
||||
|
||||
stdout, stderr = compare_proc.communicate()
|
||||
if convert_proc.returncode:
|
||||
log.debug(
|
||||
u'ImageMagick convert failed with status {}',
|
||||
convert_proc.returncode,
|
||||
)
|
||||
return
|
||||
if compare_proc.returncode:
|
||||
if compare_proc.returncode != 1:
|
||||
log.debug(u'IM phashes compare failed for {0}, {1}',
|
||||
log.debug(u'ImageMagick compare failed: {0}, {1}',
|
||||
displayable_path(imagepath),
|
||||
displayable_path(art))
|
||||
return
|
||||
|
|
@ -165,7 +171,7 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
|
|||
log.debug(u'IM output is not a number: {0!r}', out_str)
|
||||
return
|
||||
|
||||
log.debug(u'compare PHASH score is {0}', phash_diff)
|
||||
log.debug(u'ImageMagick copmare score: {0}', phash_diff)
|
||||
return phash_diff <= compare_threshold
|
||||
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -181,14 +181,14 @@ class ArtSimilarityTest(unittest.TestCase):
|
|||
popen.communicate.return_value = stdout, stderr
|
||||
return popen
|
||||
|
||||
def _mock_popens(self, mock_extract, mock_subprocess, convert_status=0,
|
||||
convert_stdout="", convert_stderr=""):
|
||||
def _mock_popens(self, mock_extract, mock_subprocess, compare_status=0,
|
||||
compare_stdout="", compare_stderr="", convert_status=0):
|
||||
mock_extract.return_value = b'extracted_path'
|
||||
mock_subprocess.Popen.side_effect = [
|
||||
# The `convert` call.
|
||||
self._popen(),
|
||||
self._popen(convert_status),
|
||||
# The `compare` call.
|
||||
self._popen(convert_status, convert_stdout, convert_stderr),
|
||||
self._popen(compare_status, compare_stdout, compare_stderr),
|
||||
]
|
||||
|
||||
def test_compare_success_similar(self, mock_extract, mock_subprocess):
|
||||
|
|
@ -220,6 +220,10 @@ class ArtSimilarityTest(unittest.TestCase):
|
|||
self._mock_popens(mock_extract, mock_subprocess, 1, "foo", "bar")
|
||||
self.assertIsNone(self._similarity(20))
|
||||
|
||||
def test_convert_failure(self, mock_extract, mock_subprocess):
|
||||
self._mock_popens(mock_extract, mock_subprocess, convert_status=1)
|
||||
self.assertIsNone(self._similarity(20))
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue