diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 3b0059817..def10e83b 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -207,7 +207,8 @@ def art_in_path(path, cover_names, cautious): images = [] for fn in os.listdir(path): for ext in IMAGE_EXTENSIONS: - if fn.lower().endswith('.' + ext): + if fn.lower().endswith('.' + ext) and \ + os.path.isfile(os.path.join(path, fn)): images.append(fn) # Look for "preferred" filenames. diff --git a/test/test_fetchart.py b/test/test_fetchart.py index 5e36f9145..12c06ae2a 100644 --- a/test/test_fetchart.py +++ b/test/test_fetchart.py @@ -12,7 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -import os.path +import os from _common import unittest from helper import TestHelper @@ -22,25 +22,31 @@ class FetchartCliTest(unittest.TestCase, TestHelper): def setUp(self): self.setup_beets() self.load_plugins('fetchart') + self.config['fetchart']['cover_names'] = 'c\xc3\xb6ver.jpg' + self.config['art_filename'] = 'mycover' + self.album = self.add_album() def tearDown(self): self.unload_plugins() self.teardown_beets() def test_set_art_from_folder(self): - self.config['fetchart']['cover_names'] = 'c\xc3\xb6ver.jpg' - self.config['art_filename'] = 'mycover' - album = self.add_album() - self.touch('c\xc3\xb6ver.jpg', dir=album.path, content='IMAGE') + self.touch('c\xc3\xb6ver.jpg', dir=self.album.path, content='IMAGE') self.run_command('fetchart') - cover_path = os.path.join(album.path, 'mycover.jpg') + cover_path = os.path.join(self.album.path, 'mycover.jpg') - album.load() - self.assertEqual(album['artpath'], cover_path) + self.album.load() + self.assertEqual(self.album['artpath'], cover_path) with open(cover_path, 'r') as f: self.assertEqual(f.read(), 'IMAGE') + def test_filesystem_does_not_pick_up_folder(self): + os.makedirs(os.path.join(self.album.path, 'mycover.jpg')) + self.run_command('fetchart') + self.album.load() + self.assertEqual(self.album['artpath'], None) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)