diff --git a/beetsplug/ihate.py b/beetsplug/ihate.py index d385f2d18..de14d4256 100644 --- a/beetsplug/ihate.py +++ b/beetsplug/ihate.py @@ -63,7 +63,7 @@ class IHatePlugin(BeetsPlugin): return False @classmethod - def do_i_hate_this(cls, task, genre_patterns, artist_patterns, + def do_i_hate_this(cls, task, genre_patterns, artist_patterns, album_patterns, whitelist_patterns): """Process group of patterns (warn or skip) and returns True if task is hated and not whitelisted. @@ -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: diff --git a/test/test_ihate.py b/test/test_ihate.py index 9c241fc54..09533d194 100644 --- a/test/test_ihate.py +++ b/test/test_ihate.py @@ -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 = [] @@ -17,31 +19,68 @@ class IHatePluginTest(unittest.TestCase): task.cur_artist = u'Test Artist' task.cur_album = u'Test Album' task.items = [Item(genre='Test Genre')] - self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, + 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, + 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, + 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.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, + album_p = 'tribute christmas test'.split() + self.assertTrue(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, + 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, + 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 = 'tribute christmas test'.split() + 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))