aboutsummaryrefslogtreecommitdiffstats
path: root/playlist_unittest.py
blob: b407e4de9b813a83d6abd0bd920cd4f9b78babf3 (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
from 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() == 0

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])

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

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

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

    def testCallback(song):
        nonlocal songSetByCallback
        songSetByCallback = song

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

    assert songAddedByUser == songSetByCallback
    assert uut.getCurrentSong() == 0

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

    def testCallback(song):
        nonlocal songSetByCallback
        songSetByCallback = song

    uut = Playlist(testCallback)
    assert songSetByCallback == None

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

    uut.addSong(songAddedByUser)
    uut.setCurrentSong(10)
    assert songSetByCallback == songAddedByUser
    assert uut.getCurrentSong() == 0