mirror of
https://github.com/beetbox/beets.git
synced 2026-07-16 14:07:40 -04:00
dbcore: rename Database._fetch to Database.get_results
This removes ambiguity with Library._fetch
This commit is contained in:
@@ -1384,7 +1384,7 @@ class Database:
|
||||
|
||||
# Querying.
|
||||
|
||||
def _fetch(
|
||||
def _get_results(
|
||||
self,
|
||||
model_cls: type[AnyModel],
|
||||
query: Query | None = None,
|
||||
@@ -1444,7 +1444,7 @@ class Database:
|
||||
|
||||
def _get(self, model_cls: type[AnyModel], id_: int) -> AnyModel | None:
|
||||
"""Get a Model object by its id or None if the id does not exist."""
|
||||
return self._fetch(model_cls, MatchQuery("id", id_)).get()
|
||||
return self._get_results(model_cls, MatchQuery("id", id_)).get()
|
||||
|
||||
|
||||
class Index(NamedTuple):
|
||||
|
||||
@@ -148,7 +148,7 @@ class Library(dbcore.Database):
|
||||
if parsed_sort and not isinstance(parsed_sort, NullSort):
|
||||
sort = parsed_sort
|
||||
|
||||
return super()._fetch(model_cls, query, sort)
|
||||
return super()._get_results(model_cls, query, sort)
|
||||
|
||||
@staticmethod
|
||||
def get_default_album_sort():
|
||||
|
||||
@@ -527,16 +527,16 @@ class ResultsIteratorTest(unittest.TestCase):
|
||||
self.db._connection().close()
|
||||
|
||||
def test_iterate_once(self):
|
||||
objs = self.db._fetch(ModelFixture1)
|
||||
objs = self.db._get_results(ModelFixture1)
|
||||
assert len(list(objs)) == 2
|
||||
|
||||
def test_iterate_twice(self):
|
||||
objs = self.db._fetch(ModelFixture1)
|
||||
objs = self.db._get_results(ModelFixture1)
|
||||
list(objs)
|
||||
assert len(list(objs)) == 2
|
||||
|
||||
def test_concurrent_iterators(self):
|
||||
results = self.db._fetch(ModelFixture1)
|
||||
results = self.db._get_results(ModelFixture1)
|
||||
it1 = iter(results)
|
||||
it2 = iter(results)
|
||||
next(it1)
|
||||
@@ -545,43 +545,46 @@ class ResultsIteratorTest(unittest.TestCase):
|
||||
|
||||
def test_slow_query(self):
|
||||
q = query.SubstringQuery("foo", "ba", False)
|
||||
objs = self.db._fetch(ModelFixture1, q)
|
||||
objs = self.db._get_results(ModelFixture1, q)
|
||||
assert len(list(objs)) == 2
|
||||
|
||||
def test_slow_query_negative(self):
|
||||
q = query.SubstringQuery("foo", "qux", False)
|
||||
objs = self.db._fetch(ModelFixture1, q)
|
||||
objs = self.db._get_results(ModelFixture1, q)
|
||||
assert len(list(objs)) == 0
|
||||
|
||||
def test_iterate_slow_sort(self):
|
||||
s = sort.SlowFieldSort("foo")
|
||||
res = self.db._fetch(ModelFixture1, sort=s)
|
||||
res = self.db._get_results(ModelFixture1, sort=s)
|
||||
objs = list(res)
|
||||
assert objs[0].foo == "bar"
|
||||
assert objs[1].foo == "baz"
|
||||
|
||||
def test_unsorted_subscript(self):
|
||||
objs = self.db._fetch(ModelFixture1)
|
||||
objs = self.db._get_results(ModelFixture1)
|
||||
assert objs[0].foo == "baz"
|
||||
assert objs[1].foo == "bar"
|
||||
|
||||
def test_slow_sort_subscript(self):
|
||||
s = sort.SlowFieldSort("foo")
|
||||
objs = self.db._fetch(ModelFixture1, sort=s)
|
||||
objs = self.db._get_results(ModelFixture1, sort=s)
|
||||
assert objs[0].foo == "bar"
|
||||
assert objs[1].foo == "baz"
|
||||
|
||||
def test_length(self):
|
||||
objs = self.db._fetch(ModelFixture1)
|
||||
objs = self.db._get_results(ModelFixture1)
|
||||
assert len(objs) == 2
|
||||
|
||||
def test_out_of_range(self):
|
||||
objs = self.db._fetch(ModelFixture1)
|
||||
objs = self.db._get_results(ModelFixture1)
|
||||
with pytest.raises(IndexError):
|
||||
objs[100]
|
||||
|
||||
def test_no_results(self):
|
||||
assert self.db._fetch(ModelFixture1, query.FalseQuery()).get() is None
|
||||
assert (
|
||||
self.db._get_results(ModelFixture1, query.FalseQuery()).get()
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
class TestException:
|
||||
|
||||
Reference in New Issue
Block a user