mirror of
https://github.com/beetbox/beets.git
synced 2025-12-29 03:52:51 +01:00
Add tests for minwidth and enforce_ratio
This commit is contained in:
parent
b5ec26c949
commit
2c6f29bfb6
1 changed files with 66 additions and 0 deletions
|
|
@ -357,6 +357,72 @@ class ArtImporterTest(UseThePlugin):
|
|||
self._fetch_art(True)
|
||||
|
||||
|
||||
class ArtForAlbumTest(UseThePlugin):
|
||||
""" Tests that fetchart.art_for_album respects the size
|
||||
configuration (e.g., minwidth, enforce_ratio)
|
||||
"""
|
||||
|
||||
IMG_225x225 = os.path.join(_common.RSRC, 'abbey.jpg')
|
||||
IMG_348x348 = os.path.join(_common.RSRC, 'abbey-different.jpg')
|
||||
IMG_500x490 = os.path.join(_common.RSRC, 'abbey-similar.jpg')
|
||||
|
||||
def setUp(self):
|
||||
super(ArtForAlbumTest, self).setUp()
|
||||
|
||||
self.old_fs_source_get = self.plugin.fs_source.get
|
||||
self.old_fetch_img = self.plugin._fetch_image
|
||||
self.old_source_urls = self.plugin._source_urls
|
||||
|
||||
def fs_source_get(*_):
|
||||
return self.image_file
|
||||
|
||||
def source_urls(_):
|
||||
return ['']
|
||||
|
||||
def fetch_img(_):
|
||||
return self.image_file
|
||||
|
||||
self.plugin.fs_source.get = fs_source_get
|
||||
self.plugin._source_urls = source_urls
|
||||
self.plugin._fetch_image = fetch_img
|
||||
|
||||
def tearDown(self):
|
||||
self.plugin.fs_source.get = self.old_fs_source_get
|
||||
self.plugin._source_urls = self.old_source_urls
|
||||
self.plugin._fetch_image = self.old_fetch_img
|
||||
super(ArtForAlbumTest, self).tearDown()
|
||||
|
||||
def _assertImageIsValidArt(self, image_file, should_exist):
|
||||
self.assertExists(image_file)
|
||||
self.image_file = image_file
|
||||
|
||||
local_artpath = self.plugin.art_for_album(None, [''], True)
|
||||
remote_artpath = self.plugin.art_for_album(None, [], False)
|
||||
|
||||
self.assertEqual(local_artpath, remote_artpath)
|
||||
|
||||
if should_exist:
|
||||
self.assertEqual(local_artpath, self.image_file)
|
||||
self.assertExists(local_artpath)
|
||||
return local_artpath
|
||||
else:
|
||||
self.assertIsNone(local_artpath)
|
||||
|
||||
def test_respect_minwidth(self):
|
||||
self.plugin.minwidth = 300
|
||||
self._assertImageIsValidArt(self.IMG_225x225, False)
|
||||
self._assertImageIsValidArt(self.IMG_348x348, True)
|
||||
|
||||
def test_respect_enforce_ratio_yes(self):
|
||||
self.plugin.enforce_ratio = True
|
||||
self._assertImageIsValidArt(self.IMG_500x490, False)
|
||||
self._assertImageIsValidArt(self.IMG_225x225, True)
|
||||
|
||||
def test_respect_enforce_ratio_no(self):
|
||||
self.plugin.enforce_ratio = False
|
||||
self._assertImageIsValidArt(self.IMG_500x490, True)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue