16
16
"""
17
17
import _common
18
18
from _common import unittest
19
- from helper import TestHelper
19
+ import helper
20
20
21
21
import beets .library
22
22
from beets import dbcore
23
23
from beets .dbcore import types
24
+ from beets .dbcore .query import NoneQuery
24
25
from beets .library import Library , Item
25
26
26
27
28
+ class TestHelper (helper .TestHelper ):
29
+
30
+ def assertInResult (self , item , results ):
31
+ result_ids = map (lambda i : i .id , results )
32
+ self .assertIn (item .id , result_ids )
33
+
34
+ def assertNotInResult (self , item , results ):
35
+ result_ids = map (lambda i : i .id , results )
36
+ self .assertNotIn (item .id , result_ids )
37
+
38
+
27
39
class AnyFieldQueryTest (_common .LibTestCase ):
28
40
def test_no_restriction (self ):
29
41
q = dbcore .query .AnyFieldQuery (
@@ -469,14 +481,6 @@ def test_flex_parse_any_string(self):
469
481
self .assertInResult (item_false , matched )
470
482
self .assertNotInResult (item_true , matched )
471
483
472
- def assertInResult (self , item , results ):
473
- result_ids = map (lambda i : i .id , results )
474
- self .assertIn (item .id , result_ids )
475
-
476
- def assertNotInResult (self , item , results ):
477
- result_ids = map (lambda i : i .id , results )
478
- self .assertNotIn (item .id , result_ids )
479
-
480
484
481
485
class DefaultSearchFieldsTest (DummyDataTestCase ):
482
486
def test_albums_matches_album (self ):
@@ -496,6 +500,30 @@ def test_items_does_not_match_year(self):
496
500
self .assert_matched (items , [])
497
501
498
502
503
+ class NoneQueryTest (unittest .TestCase , TestHelper ):
504
+
505
+ def setUp (self ):
506
+ self .lib = Library (':memory:' )
507
+
508
+ def test_match_singletons (self ):
509
+ singleton = self .add_item ()
510
+ album_item = self .add_album ().items ().get ()
511
+
512
+ matched = self .lib .items (NoneQuery ('album_id' ))
513
+ self .assertInResult (singleton , matched )
514
+ self .assertNotInResult (album_item , matched )
515
+
516
+ def test_match_after_set_none (self ):
517
+ item = self .add_item (rg_track_gain = 0 )
518
+ matched = self .lib .items (NoneQuery ('rg_track_gain' ))
519
+ self .assertNotInResult (item , matched )
520
+
521
+ item ['rg_track_gain' ] = None
522
+ item .store ()
523
+ matched = self .lib .items (NoneQuery ('rg_track_gain' ))
524
+ self .assertInResult (item , matched )
525
+
526
+
499
527
def suite ():
500
528
return unittest .TestLoader ().loadTestsFromName (__name__ )
501
529
0 commit comments