mirror of
https://github.com/beetbox/beets.git
synced 2025-12-29 20:12:33 +01:00
remove unused artists() and get() methods on library
This commit is contained in:
parent
3e90579a6c
commit
151df84150
2 changed files with 29 additions and 64 deletions
|
|
@ -548,14 +548,6 @@ class BaseLibrary(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get(self, query=None, default_fields=None):
|
||||
"""Returns a sequence of the items matching query, which may
|
||||
be None (match the entire library), a Query object, or a query
|
||||
string. If default_fields is specified, it restricts the fields
|
||||
that may be matched by unqualified query string terms.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def save(self):
|
||||
"""Ensure that the library is consistent on disk. A no-op by
|
||||
default.
|
||||
|
|
@ -587,15 +579,13 @@ class BaseLibrary(object):
|
|||
# Naive implementations are provided, but these methods should be
|
||||
# overridden if a better implementation exists.
|
||||
|
||||
def artists(self, query=None):
|
||||
"""Returns a sorted sequence of artists in the database,
|
||||
possibly filtered by a query. Unqualified query string terms
|
||||
only match the artist field.
|
||||
def _get(self, query=None, default_fields=None):
|
||||
"""Returns a sequence of the items matching query, which may
|
||||
be None (match the entire library), a Query object, or a query
|
||||
string. If default_fields is specified, it restricts the fields
|
||||
that may be matched by unqualified query string terms.
|
||||
"""
|
||||
out = set()
|
||||
for item in self.get(query, ARTIST_DEFAULT_FIELDS):
|
||||
out.add(item.artist)
|
||||
return sorted(out)
|
||||
raise NotImplementedError
|
||||
|
||||
def albums(self, artist=None, query=None):
|
||||
"""Returns a sorted list of BaseAlbum objects, possibly filtered
|
||||
|
|
@ -606,7 +596,7 @@ class BaseLibrary(object):
|
|||
# Gather the unique album/artist names and associated example
|
||||
# Items.
|
||||
specimens = {}
|
||||
for item in self.get(query, ALBUM_DEFAULT_FIELDS):
|
||||
for item in self._get(query, ALBUM_DEFAULT_FIELDS):
|
||||
if (artist is None or item.artist == artist):
|
||||
key = (item.artist, item.album)
|
||||
if key not in specimens:
|
||||
|
|
@ -628,7 +618,7 @@ class BaseLibrary(object):
|
|||
and comments.
|
||||
"""
|
||||
out = []
|
||||
for item in self.get(query, ITEM_DEFAULT_FIELDS):
|
||||
for item in self._get(query, ITEM_DEFAULT_FIELDS):
|
||||
if (artist is None or item.artist == artist) and \
|
||||
(album is None or item.album == album) and \
|
||||
(title is None or item.title == title):
|
||||
|
|
@ -856,9 +846,6 @@ class Library(BaseLibrary):
|
|||
item.id = new_id
|
||||
return new_id
|
||||
|
||||
def get(self, query=None):
|
||||
return self._get_query(query).execute(self)
|
||||
|
||||
def save(self):
|
||||
"""Writes the library to disk (completing an sqlite
|
||||
transaction).
|
||||
|
|
@ -928,16 +915,7 @@ class Library(BaseLibrary):
|
|||
util.prune_dirs(os.path.dirname(item.path), self.directory)
|
||||
|
||||
|
||||
# Browsing.
|
||||
|
||||
def artists(self, query=None):
|
||||
query = self._get_query(query, ARTIST_DEFAULT_FIELDS)
|
||||
where, subvals = query.clause()
|
||||
sql = "SELECT DISTINCT artist FROM items " + \
|
||||
"WHERE " + where + \
|
||||
" ORDER BY artist"
|
||||
c = self.conn.execute(sql, subvals)
|
||||
return [res[0] for res in c.fetchall()]
|
||||
# Querying.
|
||||
|
||||
def albums(self, artist=None, query=None):
|
||||
query = self._get_query(query, ALBUM_DEFAULT_FIELDS)
|
||||
|
|
|
|||
|
|
@ -68,15 +68,15 @@ class AnySubstringQueryTest(unittest.TestCase):
|
|||
|
||||
def test_no_restriction(self):
|
||||
q = beets.library.AnySubstringQuery('title')
|
||||
self.assertEqual(self.lib.get(q).next().title, 'the title')
|
||||
self.assertEqual(self.lib.items(query=q).next().title, 'the title')
|
||||
|
||||
def test_restriction_completeness(self):
|
||||
q = beets.library.AnySubstringQuery('title', ['title'])
|
||||
self.assertEqual(self.lib.get(q).next().title, 'the title')
|
||||
self.assertEqual(self.lib.items(query=q).next().title, 'the title')
|
||||
|
||||
def test_restriction_soundness(self):
|
||||
q = beets.library.AnySubstringQuery('title', ['artist'])
|
||||
self.assertRaises(StopIteration, self.lib.get(q).next)
|
||||
self.assertRaises(StopIteration, self.lib.items(query=q).next)
|
||||
|
||||
|
||||
# Convenient asserts for matching items.
|
||||
|
|
@ -87,9 +87,9 @@ class AssertsMixin(object):
|
|||
self.assertRaises(StopIteration, result_iterator.next)
|
||||
def assert_matched_all(self, result_iterator):
|
||||
self.assert_matched(result_iterator, 'Littlest Things')
|
||||
self.assert_matched(result_iterator, 'Take Pills')
|
||||
self.assert_matched(result_iterator, 'Lovers Who Uncover')
|
||||
self.assert_matched(result_iterator, 'Boracay')
|
||||
self.assert_matched(result_iterator, 'Take Pills')
|
||||
self.assert_done(result_iterator)
|
||||
|
||||
class GetTest(unittest.TestCase, AssertsMixin):
|
||||
|
|
@ -100,57 +100,57 @@ class GetTest(unittest.TestCase, AssertsMixin):
|
|||
|
||||
def test_get_empty(self):
|
||||
q = ''
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched_all(results)
|
||||
|
||||
def test_get_none(self):
|
||||
q = None
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched_all(results)
|
||||
|
||||
def test_get_one_keyed_term(self):
|
||||
q = 'artist:Lil'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_get_one_unkeyed_term(self):
|
||||
q = 'Terry'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_get_no_matches(self):
|
||||
q = 'popebear'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_done(results)
|
||||
|
||||
def test_invalid_key(self):
|
||||
q = 'pope:bear'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched_all(results)
|
||||
|
||||
def test_term_case_insensitive(self):
|
||||
q = 'UNCoVER'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_term_case_insensitive_with_key(self):
|
||||
q = 'album:stiLL'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_key_case_insensitive(self):
|
||||
q = 'ArTiST:Allen'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_unkeyed_term_matches_multiple_columns(self):
|
||||
q = 'little'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_matched(results, 'Boracay')
|
||||
|
|
@ -158,14 +158,14 @@ class GetTest(unittest.TestCase, AssertsMixin):
|
|||
|
||||
def test_keyed_term_matches_only_one_column(self):
|
||||
q = 'artist:little'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_mulitple_terms_narrow_search(self):
|
||||
q = 'little ones'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
|
@ -184,25 +184,25 @@ class MemoryGetTest(unittest.TestCase, AssertsMixin):
|
|||
|
||||
def test_singleton_true(self):
|
||||
q = 'singleton:true'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'singleton item')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_singleton_false(self):
|
||||
q = 'singleton:false'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'album item')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_compilation_true(self):
|
||||
q = 'comp:true'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'album item')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_compilation_false(self):
|
||||
q = 'comp:false'
|
||||
results = self.lib.get(q)
|
||||
results = self.lib.items(query=q)
|
||||
self.assert_matched(results, 'singleton item')
|
||||
self.assert_done(results)
|
||||
|
||||
|
|
@ -212,11 +212,6 @@ class BrowseTest(unittest.TestCase, AssertsMixin):
|
|||
os.path.join(_common.RSRC, 'test.blb')
|
||||
)
|
||||
|
||||
def test_artist_list(self):
|
||||
artists = list(self.lib.artists())
|
||||
self.assertEqual(artists, ['Lily Allen', 'Panda Bear',
|
||||
'The Little Ones'])
|
||||
|
||||
def test_album_list(self):
|
||||
albums = list(self.lib.albums())
|
||||
album_names = [a.album for a in albums]
|
||||
|
|
@ -233,14 +228,6 @@ class BrowseTest(unittest.TestCase, AssertsMixin):
|
|||
self.assert_matched(items, 'Boracay')
|
||||
self.assert_done(items)
|
||||
|
||||
def test_artists_matches_artist(self):
|
||||
artists = list(self.lib.artists(query='panda'))
|
||||
self.assertEqual(artists, ['Panda Bear'])
|
||||
|
||||
def test_artists_does_not_match_album(self):
|
||||
artists = list(self.lib.artists(query='alright'))
|
||||
self.assertEqual(artists, [])
|
||||
|
||||
def test_albums_matches_album(self):
|
||||
albums = list(self.lib.albums(query='person'))
|
||||
self.assertEqual(len(albums), 1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue