mirror of
https://github.com/beetbox/beets.git
synced 2026-01-03 22:42:44 +01:00
A bunch more tests for Results
This commit is contained in:
parent
9d5fdbb37f
commit
e949fe2d93
1 changed files with 38 additions and 2 deletions
|
|
@ -470,8 +470,12 @@ class SortFromStringsTest(unittest.TestCase):
|
|||
class ResultsIteratorTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.db = TestDatabase1(':memory:')
|
||||
TestModel1().add(self.db)
|
||||
TestModel1().add(self.db)
|
||||
model = TestModel1()
|
||||
model['foo'] = 'baz'
|
||||
model.add(self.db)
|
||||
model = TestModel1()
|
||||
model['foo'] = 'bar'
|
||||
model.add(self.db)
|
||||
|
||||
def tearDown(self):
|
||||
self.db._connection().close()
|
||||
|
|
@ -493,6 +497,38 @@ class ResultsIteratorTest(unittest.TestCase):
|
|||
list(it2)
|
||||
self.assertEqual(len(list(it1)), 1)
|
||||
|
||||
def test_slow_query(self):
|
||||
q = dbcore.query.SubstringQuery('foo', 'ba', False)
|
||||
objs = self.db._fetch(TestModel1, q)
|
||||
self.assertEqual(len(list(objs)), 2)
|
||||
|
||||
def test_slow_query_negative(self):
|
||||
q = dbcore.query.SubstringQuery('foo', 'qux', False)
|
||||
objs = self.db._fetch(TestModel1, q)
|
||||
self.assertEqual(len(list(objs)), 0)
|
||||
|
||||
def test_iterate_slow_sort(self):
|
||||
s = dbcore.query.SlowFieldSort('foo')
|
||||
res = self.db._fetch(TestModel1, sort=s)
|
||||
objs = list(res)
|
||||
self.assertEqual(objs[0].foo, 'bar')
|
||||
self.assertEqual(objs[1].foo, 'baz')
|
||||
|
||||
def test_unsorted_subscript(self):
|
||||
objs = self.db._fetch(TestModel1)
|
||||
self.assertEqual(objs[0].foo, 'baz')
|
||||
self.assertEqual(objs[1].foo, 'bar')
|
||||
|
||||
def test_slow_sort_subscript(self):
|
||||
s = dbcore.query.SlowFieldSort('foo')
|
||||
objs = self.db._fetch(TestModel1, sort=s)
|
||||
self.assertEqual(objs[0].foo, 'bar')
|
||||
self.assertEqual(objs[1].foo, 'baz')
|
||||
|
||||
def test_length(self):
|
||||
objs = self.db._fetch(TestModel1)
|
||||
self.assertEqual(len(objs), 2)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue