Skip to content

Commit 24e6ba3

Browse files
committed
Tests for case insensitive sort
- Changed old values to be capitalized (more natural) - Introduced specific tests for case sensitivity which adds lower-values
1 parent 0302c44 commit 24e6ba3

File tree

1 file changed

+121
-40
lines changed

1 file changed

+121
-40
lines changed

test/test_sort.py

Lines changed: 121 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,65 +32,65 @@ def setUp(self):
3232
self.lib = beets.library.Library(':memory:')
3333

3434
albums = [_common.album() for _ in range(3)]
35-
albums[0].album = "album A"
35+
albums[0].album = "Album A"
3636
albums[0].genre = "Rock"
3737
albums[0].year = "2001"
38-
albums[0].flex1 = "flex1-1"
39-
albums[0].flex2 = "flex2-A"
40-
albums[0].albumartist = "foo"
38+
albums[0].flex1 = "Flex1-1"
39+
albums[0].flex2 = "Flex2-A"
40+
albums[0].albumartist = "Foo"
4141
albums[0].albumartist_sort = None
42-
albums[1].album = "album B"
42+
albums[1].album = "Album B"
4343
albums[1].genre = "Rock"
4444
albums[1].year = "2001"
45-
albums[1].flex1 = "flex1-2"
46-
albums[1].flex2 = "flex2-A"
47-
albums[1].albumartist = "bar"
45+
albums[1].flex1 = "Flex1-2"
46+
albums[1].flex2 = "Flex2-A"
47+
albums[1].albumartist = "Bar"
4848
albums[1].albumartist_sort = None
49-
albums[2].album = "album C"
49+
albums[2].album = "Album C"
5050
albums[2].genre = "Jazz"
5151
albums[2].year = "2005"
52-
albums[2].flex1 = "flex1-1"
53-
albums[2].flex2 = "flex2-B"
54-
albums[2].albumartist = "baz"
52+
albums[2].flex1 = "Flex1-1"
53+
albums[2].flex2 = "Flex2-B"
54+
albums[2].albumartist = "Baz"
5555
albums[2].albumartist_sort = None
5656
for album in albums:
5757
self.lib.add(album)
5858

5959
items = [_common.item() for _ in range(4)]
60-
items[0].title = 'foo bar'
61-
items[0].artist = 'one'
62-
items[0].album = 'baz'
60+
items[0].title = 'Foo bar'
61+
items[0].artist = 'One'
62+
items[0].album = 'Baz'
6363
items[0].year = 2001
6464
items[0].comp = True
65-
items[0].flex1 = "flex1-0"
66-
items[0].flex2 = "flex2-A"
65+
items[0].flex1 = "Flex1-0"
66+
items[0].flex2 = "Flex2-A"
6767
items[0].album_id = albums[0].id
6868
items[0].artist_sort = None
69-
items[1].title = 'baz qux'
70-
items[1].artist = 'two'
71-
items[1].album = 'baz'
69+
items[1].title = 'Baz qux'
70+
items[1].artist = 'Two'
71+
items[1].album = 'Baz'
7272
items[1].year = 2002
7373
items[1].comp = True
74-
items[1].flex1 = "flex1-1"
75-
items[1].flex2 = "flex2-A"
74+
items[1].flex1 = "Flex1-1"
75+
items[1].flex2 = "Flex2-A"
7676
items[1].album_id = albums[0].id
7777
items[1].artist_sort = None
78-
items[2].title = 'beets 4 eva'
79-
items[2].artist = 'three'
80-
items[2].album = 'foo'
78+
items[2].title = 'Beets 4 eva'
79+
items[2].artist = 'Three'
80+
items[2].album = 'Foo'
8181
items[2].year = 2003
8282
items[2].comp = False
83-
items[2].flex1 = "flex1-2"
84-
items[2].flex2 = "flex1-B"
83+
items[2].flex1 = "Flex1-2"
84+
items[2].flex2 = "Flex1-B"
8585
items[2].album_id = albums[1].id
8686
items[2].artist_sort = None
87-
items[3].title = 'beets 4 eva'
88-
items[3].artist = 'three'
89-
items[3].album = 'foo2'
87+
items[3].title = 'Beets 4 eva'
88+
items[3].artist = 'Three'
89+
items[3].album = 'Foo2'
9090
items[3].year = 2004
9191
items[3].comp = False
92-
items[3].flex1 = "flex1-2"
93-
items[3].flex2 = "flex1-C"
92+
items[3].flex1 = "Flex1-2"
93+
items[3].flex2 = "Flex1-C"
9494
items[3].album_id = albums[2].id
9595
items[3].artist_sort = None
9696
for item in items:
@@ -132,8 +132,8 @@ def test_sort_two_field_asc(self):
132132
results = self.lib.items(q, sort)
133133
self.assertLessEqual(results[0]['album'], results[1]['album'])
134134
self.assertLessEqual(results[1]['album'], results[2]['album'])
135-
self.assertEqual(results[0]['album'], 'baz')
136-
self.assertEqual(results[1]['album'], 'baz')
135+
self.assertEqual(results[0]['album'], 'Baz')
136+
self.assertEqual(results[1]['album'], 'Baz')
137137
self.assertLessEqual(results[0]['year'], results[1]['year'])
138138
# same thing with query string
139139
q = 'album+ year+'
@@ -148,7 +148,7 @@ def test_sort_asc(self):
148148
sort = dbcore.query.SlowFieldSort("flex1", True)
149149
results = self.lib.items(q, sort)
150150
self.assertLessEqual(results[0]['flex1'], results[1]['flex1'])
151-
self.assertEqual(results[0]['flex1'], 'flex1-0')
151+
self.assertEqual(results[0]['flex1'], 'Flex1-0')
152152
# same thing with query string
153153
q = 'flex1+'
154154
results2 = self.lib.items(q)
@@ -162,7 +162,7 @@ def test_sort_desc(self):
162162
self.assertGreaterEqual(results[0]['flex1'], results[1]['flex1'])
163163
self.assertGreaterEqual(results[1]['flex1'], results[2]['flex1'])
164164
self.assertGreaterEqual(results[2]['flex1'], results[3]['flex1'])
165-
self.assertEqual(results[0]['flex1'], 'flex1-2')
165+
self.assertEqual(results[0]['flex1'], 'Flex1-2')
166166
# same thing with query string
167167
q = 'flex1-'
168168
results2 = self.lib.items(q)
@@ -179,8 +179,8 @@ def test_sort_two_field(self):
179179
results = self.lib.items(q, sort)
180180
self.assertGreaterEqual(results[0]['flex2'], results[1]['flex2'])
181181
self.assertGreaterEqual(results[1]['flex2'], results[2]['flex2'])
182-
self.assertEqual(results[0]['flex2'], 'flex2-A')
183-
self.assertEqual(results[1]['flex2'], 'flex2-A')
182+
self.assertEqual(results[0]['flex2'], 'Flex2-A')
183+
self.assertEqual(results[1]['flex2'], 'Flex2-A')
184184
self.assertLessEqual(results[0]['flex1'], results[1]['flex1'])
185185
# same thing with query string
186186
q = 'flex2- flex1+'
@@ -269,8 +269,8 @@ def test_sort_two_field_asc(self):
269269
results = self.lib.albums(q, sort)
270270
self.assertLessEqual(results[0]['flex2'], results[1]['flex2'])
271271
self.assertLessEqual(results[1]['flex2'], results[2]['flex2'])
272-
self.assertEqual(results[0]['flex2'], 'flex2-A')
273-
self.assertEqual(results[1]['flex2'], 'flex2-A')
272+
self.assertEqual(results[0]['flex2'], 'Flex2-A')
273+
self.assertEqual(results[1]['flex2'], 'Flex2-A')
274274
self.assertLessEqual(results[0]['flex1'], results[1]['flex1'])
275275
# same thing with query string
276276
q = 'flex2+ flex1+'
@@ -358,6 +358,87 @@ def test_config_opposite_sort_album(self):
358358
self.assertGreater(results[0].albumartist, results[1].albumartist)
359359

360360

361+
class CaseSensitivityTest(DummyDataTestCase, _common.TestCase):
362+
"""If case_insensitive is false, lower-case values should be placed
363+
after all upper-case values. E.g., `Foo Qux bar`
364+
"""
365+
366+
def setUp(self):
367+
super(CaseSensitivityTest, self).setUp()
368+
369+
album = _common.album()
370+
album.album = "album"
371+
album.genre = "alternative"
372+
album.year = "2001"
373+
album.flex1 = "flex1"
374+
album.flex2 = "flex2-A"
375+
album.albumartist = "bar"
376+
album.albumartist_sort = None
377+
self.lib.add(album)
378+
379+
item = _common.item()
380+
item.title = 'another'
381+
item.artist = 'lowercase'
382+
item.album = 'album'
383+
item.year = 2001
384+
item.comp = True
385+
item.flex1 = "flex1"
386+
item.flex2 = "flex2-A"
387+
item.album_id = album.id
388+
item.artist_sort = None
389+
self.lib.add(item)
390+
391+
self.new_album = album
392+
self.new_item = item
393+
394+
def tearDown(self):
395+
self.new_item.remove(delete=True)
396+
self.new_album.remove(delete=True)
397+
super(CaseSensitivityTest, self).tearDown()
398+
399+
def test_smart_artist_case_insensitive(self):
400+
config['sort_case_insensitive'] = True
401+
q = 'artist+'
402+
results = list(self.lib.items(q))
403+
self.assertEqual(results[0].artist, 'lowercase')
404+
self.assertEqual(results[1].artist, 'One')
405+
406+
def test_smart_artist_case_sensitive(self):
407+
config['sort_case_insensitive'] = False
408+
q = 'artist+'
409+
results = list(self.lib.items(q))
410+
self.assertEqual(results[0].artist, 'One')
411+
self.assertEqual(results[-1].artist, 'lowercase')
412+
413+
def test_fixed_field_case_insensitive(self):
414+
config['sort_case_insensitive'] = True
415+
q = 'album+'
416+
results = list(self.lib.albums(q))
417+
self.assertEqual(results[0].album, 'album')
418+
self.assertEqual(results[1].album, 'Album A')
419+
420+
def test_fixed_field_case_sensitive(self):
421+
config['sort_case_insensitive'] = False
422+
q = 'album+'
423+
results = list(self.lib.albums(q))
424+
self.assertEqual(results[0].album, 'Album A')
425+
self.assertEqual(results[-1].album, 'album')
426+
427+
def test_flex_field_case_insensitive(self):
428+
config['sort_case_insensitive'] = True
429+
q = 'flex1+'
430+
results = list(self.lib.items(q))
431+
self.assertEqual(results[0].flex1, 'flex1')
432+
self.assertEqual(results[1].flex1, 'Flex1-0')
433+
434+
def test_flex_field_case_sensitive(self):
435+
config['sort_case_insensitive'] = False
436+
q = 'flex1+'
437+
results = list(self.lib.items(q))
438+
self.assertEqual(results[0].flex1, 'Flex1-0')
439+
self.assertEqual(results[-1].flex1, 'flex1')
440+
441+
361442
def suite():
362443
return unittest.TestLoader().loadTestsFromName(__name__)
363444

0 commit comments

Comments
 (0)