aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test/playlist_unittest.py
blob: 842ce518b8cd956004395e98ce9355ade7af3ada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from solo_tool.playlist import Playlist

def test_addAndSelectOneSong():
    songAddedByUser = "/path/to/song"
    songSetByCallback = None

    def testCallback(song):
        nonlocal songSetByCallback
        songSetByCallback = song

    uut = Playlist(testCallback)
    uut.addSong(songAddedByUser)
    uut.setCurrentSong(0)

    assert songAddedByUser == songSetByCallback
    assert uut.getCurrentSong() == songAddedByUser
    assert uut.getCurrentSongIndex() == 0
    assert uut.getSongs() == [songAddedByUser]

def test_addTwoSongsAndSelectBoth():
    songAddedByUser = ["/path/to/song", "/path/to/second/song"]
    songSetByCallback = None

    def testCallback(song):
        nonlocal songSetByCallback
        songSetByCallback = song

    uut = Playlist(testCallback)
    uut.addSong(songAddedByUser[0])
    uut.addSong(songAddedByUser[1])
    assert uut.getSongs() == songAddedByUser

    uut.setCurrentSong(0)
    assert songAddedByUser[0] == songSetByCallback
    assert uut.getCurrentSong() == songAddedByUser[0]
    assert uut.getCurrentSongIndex() == 0

    uut.setCurrentSong(1)
    assert songAddedByUser[1] == songSetByCallback
    assert uut.getCurrentSong() == songAddedByUser[1]
    assert uut.getCurrentSongIndex() == 1

def test_firstAddedSongIsNotSelected():
    songAddedByUser = "/path/to/song"
    songSetByCallback = None

    def testCallback(song):
        nonlocal songSetByCallback
        songSetByCallback = song

    uut = Playlist(testCallback)
    uut.addSong(songAddedByUser)

    assert songSetByCallback == None
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None
    assert uut.getSongs() == [songAddedByUser]

def test_invalidSongSelection():
    songAddedByUser = "/path/to/song"
    songSetByCallback = None

    def testCallback(song):
        nonlocal songSetByCallback
        songSetByCallback = song

    uut = Playlist(testCallback)
    assert songSetByCallback == None
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None

    uut.setCurrentSong(10)
    assert songSetByCallback == None
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None

    uut.addSong(songAddedByUser)
    uut.setCurrentSong(10)
    assert songSetByCallback == None
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None
    assert uut.getSongs() == [songAddedByUser]

def test_clearPlaylist():
    songAddedByUser = ["/path/to/song", "/path/to/second/song"]

    def dummy(index):
        pass

    uut = Playlist(dummy)
    for s in songAddedByUser:
        uut.addSong(s)
    uut.setCurrentSong(0)

    assert uut.getSongs() == songAddedByUser
    assert uut.getCurrentSong() == songAddedByUser[0]
    assert uut.getCurrentSongIndex() == 0

    uut.clear()

    assert uut.getSongs() == []
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None

def test_nextSong():
    songAddedByUser = ["/path/to/song", "/path/to/second/song"]
    
    uut = Playlist(lambda index: None)
    for s in songAddedByUser:
        uut.addSong(s)
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None

    uut.nextSong()
    assert uut.getCurrentSong() == songAddedByUser[0]
    assert uut.getCurrentSongIndex() == 0
    
    uut.nextSong()
    assert uut.getCurrentSong() == songAddedByUser[1]
    assert uut.getCurrentSongIndex() == 1

    uut.nextSong()
    assert uut.getCurrentSong() == songAddedByUser[1]
    assert uut.getCurrentSongIndex() == 1

def test_previousSong():
    songAddedByUser = ["/path/to/song", "/path/to/second/song"]
    
    uut = Playlist(lambda index: None)
    for s in songAddedByUser:
        uut.addSong(s)
    assert uut.getCurrentSong() == None
    assert uut.getCurrentSongIndex() == None

    uut.previousSong()
    assert uut.getCurrentSong() == songAddedByUser[0]
    assert uut.getCurrentSongIndex() == 0
    
    uut.previousSong()
    assert uut.getCurrentSong() == songAddedByUser[0]
    assert uut.getCurrentSongIndex() == 0

    uut.setCurrentSong(1)
    assert uut.getCurrentSong() == songAddedByUser[1]
    assert uut.getCurrentSongIndex() == 1
    uut.previousSong()
    assert uut.getCurrentSong() == songAddedByUser[0]
    assert uut.getCurrentSongIndex() == 0