File: test_ihate.py

package info (click to toggle)
beets 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,016 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (45 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Tests for the 'ihate' plugin"""

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="TestAlbum", artist="TestArtist"
        )
        task = importer.SingletonImportTask(None, test_item)

        # Empty query should let it pass.
        assert not IHatePlugin.do_i_hate_this(task, match_pattern)

        # 1 query match.
        match_pattern = ["artist:bad_artist", "artist:TestArtist"]
        assert IHatePlugin.do_i_hate_this(task, match_pattern)

        # 2 query matches, either should trigger.
        match_pattern = ["album:test", "artist:testartist"]
        assert IHatePlugin.do_i_hate_this(task, match_pattern)

        # Query is blocked by AND clause.
        match_pattern = ["album:notthis genre:testgenre"]
        assert not 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",
        ]
        assert not IHatePlugin.do_i_hate_this(task, match_pattern)

        # Only one query should fire.
        match_pattern = [
            "album:testalbum genre:testgenre",
            "artist:testartist album:notthis",
        ]
        assert IHatePlugin.do_i_hate_this(task, match_pattern)