mirror of
https://github.com/beetbox/beets.git
synced 2025-12-16 13:43:53 +01:00
Include import of __future__ features division, absolute_imports and print_function everywhere. Don't add unicode_literals yet for it is harder to convert. Goal is smoothing the transition to python 3.
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Tests for the 'ihate' plugin"""
|
|
|
|
from __future__ import division, absolute_import, print_function
|
|
|
|
from test._common import unittest
|
|
from beets import importer
|
|
from beets.library import Item
|
|
from beetsplug.ihate import IHatePlugin
|
|
|
|
|
|
class IHatePluginTest(unittest.TestCase):
|
|
|
|
def test_hate(self):
|
|
|
|
match_pattern = {}
|
|
test_item = Item(
|
|
genre='TestGenre',
|
|
album=u'TestAlbum',
|
|
artist=u'TestArtist')
|
|
task = importer.SingletonImportTask(None, test_item)
|
|
|
|
# Empty query should let it pass.
|
|
self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))
|
|
|
|
# 1 query match.
|
|
match_pattern = ["artist:bad_artist", "artist:TestArtist"]
|
|
self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
|
|
|
|
# 2 query matches, either should trigger.
|
|
match_pattern = ["album:test", "artist:testartist"]
|
|
self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
|
|
|
|
# Query is blocked by AND clause.
|
|
match_pattern = ["album:notthis genre:testgenre"]
|
|
self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))
|
|
|
|
# Both queries are blocked by AND clause with unmatched condition.
|
|
match_pattern = ["album:notthis genre:testgenre",
|
|
"artist:testartist album:notthis"]
|
|
self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))
|
|
|
|
# Only one query should fire.
|
|
match_pattern = ["album:testalbum genre:testgenre",
|
|
"artist:testartist album:notthis"]
|
|
self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
|
|
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(defaultTest='suite')
|