Fix for #411: iHate fails with singletons.

This commit is contained in:
Mathijs de Bruin 2013-11-07 13:51:35 +01:00
parent 3ccd231765
commit 2bab3135b3
2 changed files with 52 additions and 13 deletions

View file

@ -76,10 +76,10 @@ class IHatePlugin(BeetsPlugin):
if genre and genre_patterns:
if cls.match_patterns(genre, genre_patterns):
hate = True
if not hate and task.cur_album and album_patterns:
if not hate and getattr(task, 'cur_album', None) and album_patterns:
if cls.match_patterns(task.cur_album, album_patterns):
hate = True
if not hate and task.cur_artist and artist_patterns:
if not hate and getattr(task, 'cur_artist', None) and artist_patterns:
if cls.match_patterns(task.cur_artist, artist_patterns):
hate = True
if hate and whitelist_patterns:

View file

@ -8,7 +8,9 @@ from beetsplug.ihate import IHatePlugin
class IHatePluginTest(unittest.TestCase):
def test_hate(self):
def test_hate_album(self):
""" iHate tests for album """
genre_p = []
artist_p = []
album_p = []
@ -44,6 +46,43 @@ class IHatePluginTest(unittest.TestCase):
self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
def test_hate_singleton(self):
""" iHate tests for singleton """
genre_p = []
artist_p = []
album_p = []
white_p = []
task = ImportTask()
task.cur_artist = u'Test Artist'
task.items = [Item(genre='Test Genre')]
self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
genre_p = 'some_genre test\sgenre'.split()
self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
genre_p = []
artist_p = 'bad_artist test\sartist'
self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
artist_p = []
album_p = 'tribute christmas test'.split()
self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
album_p = []
white_p = 'goodband test\sartist another_band'.split()
genre_p = 'some_genre test\sgenre'.split()
self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
genre_p = []
artist_p = 'bad_artist test\sartist'
self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
artist_p = []
album_p = 'tribute christmas test'.split()
self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
album_p, white_p))
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)