Skip to content

Commit

Permalink
patch rather than overwriting Item
Browse files Browse the repository at this point in the history
  • Loading branch information
valrus committed Dec 31, 2024
1 parent e9a77ca commit 21c734b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
18 changes: 4 additions & 14 deletions test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import unittest
from contextlib import contextmanager
from functools import partial
from mock import patch

Check failure on line 22 in test/test_query.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Library stubs not installed for "mock"

import pytest

Expand Down Expand Up @@ -715,10 +716,6 @@ def test_detect_relative_path(self):


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()
Expand All @@ -732,14 +729,14 @@ def test_range_match(self):
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
Expand All @@ -750,15 +747,8 @@ def test_no_substring_match(self):
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)
Expand Down
7 changes: 2 additions & 5 deletions test/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Various tests for querying the library database."""

from mock import patch

Check failure on line 17 in test/test_sort.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Library stubs not installed for "mock"
import beets.library
from beets import config, dbcore
from beets.dbcore import types
Expand Down Expand Up @@ -472,10 +473,6 @@ def test_case_sensitive_only_affects_text(self):
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+", "---"]

Expand Down Expand Up @@ -519,10 +516,10 @@ def test_field_present_in_some_items(self):
# 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
Expand Down

0 comments on commit 21c734b

Please sign in to comment.