mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 01:25:47 +01:00
patch rather than overwriting Item
This commit is contained in:
parent
e9a77cac72
commit
21c734bff8
2 changed files with 6 additions and 19 deletions
|
|
@ -19,6 +19,7 @@ import sys
|
|||
import unittest
|
||||
from contextlib import contextmanager
|
||||
from functools import partial
|
||||
from mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -715,10 +716,6 @@ class PathQueryTest(ItemInDBTestCase, AssertsMixin):
|
|||
|
||||
|
||||
class IntQueryTest(BeetsTestCase):
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
Item._types = {}
|
||||
|
||||
def test_exact_value_match(self):
|
||||
item = self.add_item(bpm=120)
|
||||
matched = self.lib.items("bpm:120").get()
|
||||
|
|
@ -732,14 +729,14 @@ class IntQueryTest(BeetsTestCase):
|
|||
assert 1 == len(matched)
|
||||
assert item.id == matched.get().id
|
||||
|
||||
@patch("beets.library.Item._types", {"myint": types.Integer()})
|
||||
def test_flex_range_match(self):
|
||||
Item._types = {"myint": types.Integer()}
|
||||
item = self.add_item(myint=2)
|
||||
matched = self.lib.items("myint:2").get()
|
||||
assert item.id == matched.id
|
||||
|
||||
@patch("beets.library.Item._types", {"myint": types.Integer()})
|
||||
def test_flex_dont_match_missing(self):
|
||||
Item._types = {"myint": types.Integer()}
|
||||
self.add_item()
|
||||
matched = self.lib.items("myint:2").get()
|
||||
assert matched is None
|
||||
|
|
@ -750,15 +747,8 @@ class IntQueryTest(BeetsTestCase):
|
|||
assert matched is None
|
||||
|
||||
|
||||
@patch("beets.library.Item._types", {"flexbool": types.Boolean()})
|
||||
class BoolQueryTest(BeetsTestCase, AssertsMixin):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
Item._types = {"flexbool": types.Boolean()}
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
Item._types = {}
|
||||
|
||||
def test_parse_true(self):
|
||||
item_true = self.add_item(comp=True)
|
||||
item_false = self.add_item(comp=False)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
"""Various tests for querying the library database."""
|
||||
|
||||
from mock import patch
|
||||
import beets.library
|
||||
from beets import config, dbcore
|
||||
from beets.dbcore import types
|
||||
|
|
@ -472,10 +473,6 @@ class CaseSensitivityTest(DummyDataTestCase, BeetsTestCase):
|
|||
class NonExistingFieldTest(DummyDataTestCase):
|
||||
"""Test sorting by non-existing fields"""
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
Item._types = {}
|
||||
|
||||
def test_non_existing_fields_not_fail(self):
|
||||
qs = ["foo+", "foo-", "--", "-+", "+-", "++", "-foo-", "-foo+", "---"]
|
||||
|
||||
|
|
@ -519,10 +516,10 @@ class NonExistingFieldTest(DummyDataTestCase):
|
|||
# items without field last
|
||||
assert [i.id for i in results_desc] == [ids[2], ids[1], ids[0], ids[3]]
|
||||
|
||||
@patch("beets.library.Item._types", {"foo": types.Integer()})
|
||||
def test_int_field_present_in_some_items(self):
|
||||
"""Test ordering by a field not present on all items."""
|
||||
# append int-valued 'foo' to two items (1,2)
|
||||
Item._types = {"foo": types.Integer()}
|
||||
items = self.lib.items("id+")
|
||||
ids = [i.id for i in items]
|
||||
items[1].foo = 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue