~andrewsomething/exaile/karmic

« back to all changes in this revision

Viewing changes to tests/playlists.py

  • Committer: Aren Olson
  • Date: 2009-09-12 00:36:59 UTC
  • Revision ID: reacocard@gmail.com-20090912003659-w373sg0n04uoa8op
remove useless files, add soem of the fixes from lp bug 420019

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from tests.base import BaseTestCase
2
 
from xl import playlist
3
 
import time, hashlib
4
 
 
5
 
class BasePlaylistTestCase(BaseTestCase):
6
 
    """
7
 
        stub
8
 
    """
9
 
    pass
10
 
 
11
 
class SmartPlaylistTestCase(BasePlaylistTestCase):
12
 
    def setUp(self):
13
 
        BasePlaylistTestCase.setUp(self)
14
 
 
15
 
        self.sp_loc = ".testtemp/sp_exaile%s.playlist" % \
16
 
            hashlib.md5(str(time.time())).hexdigest()
17
 
        self.sp = playlist.SmartPlaylist(collection=self.collection)
18
 
        self.sp.add_param("artist", "=", "TestArtist")
19
 
        self.sp.add_param("album", "!=", "First")
20
 
 
21
 
    def testSearch(self, sp=None):
22
 
        if not sp: sp = self.sp
23
 
 
24
 
        p = sp.get_playlist()
25
 
        tracks = p.get_tracks()
26
 
 
27
 
        for i, track in enumerate(tracks):
28
 
            assert i+1 == track.get_track(), \
29
 
                "SmartPlaylist search failed"
30
 
 
31
 
    def testSaveLoad(self):
32
 
        self.sp.set_or_match(True)
33
 
        self.sp.save_to_location(self.sp_loc)
34
 
 
35
 
        # test playlist
36
 
        sp = playlist.SmartPlaylist(collection=self.collection)
37
 
        sp.load_from_location(self.sp_loc)
38
 
        
39
 
        assert sp.get_or_match() == True, "Loading saved smart playlist failed"
40
 
        sp.set_or_match(False)
41
 
 
42
 
        self.testSearch(sp)
43
 
        self.sp.set_or_match(False)
44
 
 
45
 
    def testReturnLimit(self):
46
 
        sp = playlist.SmartPlaylist(collection=self.collection)
47
 
        sp.set_return_limit(2)
48
 
 
49
 
        p = sp.get_playlist()
50
 
 
51
 
        assert len(p) == 2, "Return limit test failed"
52
 
 
53
 
    def testRandomSort(self):
54
 
        sp = playlist.SmartPlaylist(collection=self.collection)
55
 
        sp.set_random_sort(True)
56
 
 
57
 
        check = False
58
 
        p = sp.get_playlist()
59
 
 
60
 
        start = p.get_tracks()
61
 
 
62
 
        # if it's not different in 50 iterations, something *has* to be wrong
63
 
        for i in range(50):
64
 
            p = sp.get_playlist() 
65
 
            if start != p.get_tracks():
66
 
                check = True
67
 
                break
68
 
 
69
 
        assert check == True, "Random sort did not work in 50 iterations"