mirror of
https://github.com/beetbox/beets.git
synced 2026-02-23 07:44:38 +01:00
Added unit tests for regexps in query expressions.
This commit is contained in:
parent
10a4e14045
commit
46ec5db3fe
1 changed files with 90 additions and 11 deletions
|
|
@ -27,27 +27,37 @@ some_item = _common.item()
|
|||
class QueryParseTest(unittest.TestCase):
|
||||
def test_one_basic_term(self):
|
||||
q = 'test'
|
||||
r = (None, 'test')
|
||||
r = (None, 'test', False)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
|
||||
def test_one_keyed_term(self):
|
||||
q = 'test:val'
|
||||
r = ('test', 'val')
|
||||
r = ('test', 'val', False)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
def test_colon_at_end(self):
|
||||
q = 'test:'
|
||||
r = (None, 'test:')
|
||||
r = (None, 'test:', False)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
def test_colon_at_start(self):
|
||||
q = ':test'
|
||||
r = (None, ':test')
|
||||
|
||||
def test_one_basic_regexp(self):
|
||||
q = r':regexp'
|
||||
r = (None, 'regexp', True)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
|
||||
def test_keyed_regexp(self):
|
||||
q = r'test::regexp'
|
||||
r = ('test', 'regexp', True)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
def test_escaped_colon(self):
|
||||
q = r'test\:val'
|
||||
r = (None, 'test:val')
|
||||
r = (None, 'test:val', False)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
def test_escaped_colon_in_regexp(self):
|
||||
q = r':test\:regexp'
|
||||
r = (None, 'test:regexp', True)
|
||||
self.assertEqual(pqp(q), r)
|
||||
|
||||
class AnySubstringQueryTest(unittest.TestCase):
|
||||
|
|
@ -67,6 +77,27 @@ class AnySubstringQueryTest(unittest.TestCase):
|
|||
q = beets.library.AnySubstringQuery('title', ['artist'])
|
||||
self.assertRaises(StopIteration, self.lib.items(q).next)
|
||||
|
||||
class AnyRegexpQueryTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.lib = beets.library.Library(':memory:')
|
||||
self.lib.add(some_item)
|
||||
|
||||
def test_no_restriction(self):
|
||||
q = beets.library.AnyRegexpQuery(r'^the ti')
|
||||
self.assertEqual(self.lib.items(q).next().title, 'the title')
|
||||
|
||||
def test_restriction_completeness(self):
|
||||
q = beets.library.AnyRegexpQuery(r'^the ti', ['title'])
|
||||
self.assertEqual(self.lib.items(q).next().title, 'the title')
|
||||
|
||||
def test_restriction_soundness(self):
|
||||
q = beets.library.AnyRegexpQuery(r'^the ti', ['artist'])
|
||||
self.assertRaises(StopIteration, self.lib.items(q).next)
|
||||
|
||||
def test_restriction_soundness_2(self):
|
||||
q = beets.library.AnyRegexpQuery(r'the ti$', ['title'])
|
||||
self.assertRaises(StopIteration, self.lib.items(q).next)
|
||||
|
||||
|
||||
# Convenient asserts for matching items.
|
||||
class AssertsMixin(object):
|
||||
|
|
@ -103,12 +134,24 @@ class GetTest(unittest.TestCase, AssertsMixin):
|
|||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_get_one_keyed_regexp(self):
|
||||
q = r'artist::L.+y'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_get_one_unkeyed_term(self):
|
||||
q = 'Terry'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_get_one_unkeyed_regexp(self):
|
||||
q = r':y$'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_get_no_matches(self):
|
||||
q = 'popebear'
|
||||
results = self.lib.items(q)
|
||||
|
|
@ -125,6 +168,15 @@ class GetTest(unittest.TestCase, AssertsMixin):
|
|||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_regexp_case_sensitive(self):
|
||||
q = r':UNCoVER'
|
||||
results = self.lib.items(q)
|
||||
self.assert_done(results)
|
||||
q = r':Uncover'
|
||||
results = self.lib.items(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.items(q)
|
||||
|
|
@ -145,6 +197,14 @@ class GetTest(unittest.TestCase, AssertsMixin):
|
|||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_unkeyed_regexp_matches_multiple_columns(self):
|
||||
q = r':^T'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Take Pills')
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_keyed_term_matches_only_one_column(self):
|
||||
q = 'artist:little'
|
||||
results = self.lib.items(q)
|
||||
|
|
@ -152,13 +212,32 @@ class GetTest(unittest.TestCase, AssertsMixin):
|
|||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_mulitple_terms_narrow_search(self):
|
||||
def test_keyed_regexp_matches_only_one_column(self):
|
||||
q = r'album::\sS'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_multiple_terms_narrow_search(self):
|
||||
q = 'little ones'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_matched(results, 'Boracay')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_multiple_regexps_narrow_search(self):
|
||||
q = r':\sS :^T'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Lovers Who Uncover')
|
||||
self.assert_done(results)
|
||||
|
||||
def test_mixed_terms_regexps_narrow_search(self):
|
||||
q = r':\sS lily'
|
||||
results = self.lib.items(q)
|
||||
self.assert_matched(results, 'Littlest Things')
|
||||
self.assert_done(results)
|
||||
|
||||
class MemoryGetTest(unittest.TestCase, AssertsMixin):
|
||||
def setUp(self):
|
||||
self.album_item = _common.item()
|
||||
|
|
|
|||
Loading…
Reference in a new issue