aboutsummaryrefslogtreecommitdiffstats
path: root/solo_tool_integrationtest.py
blob: b3a0978a56d15427251895b92eb1f3c2305bcc0a (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
from solo_tool import SoloTool
from time import sleep

class MockPlayer():
    STOPPED = 0
    PLAYING = 1
    PAUSED = 2

    def __init__(self):
        self.state = MockPlayer.STOPPED
        self.rate = 1.0
        self.position = 0.0
        self.volume = 1.0
        self.currentSong = ""

    def play(self):
        self.state = MockPlayer.PLAYING

    def stop(self):
        self.state = MockPlayer.STOPPED

    def pause(self):
        self.state = MockPlayer.PAUSED

    def setPlaybackRate(self, rate):
        self.rate = rate

    def getPlaybackRate(self):
        return self.rate

    def setPlaybackPosition(self, position):
        self.position = position

    def getPlaybackPosition(self):
        return self.position

    def setPlaybackVolume(self, volume):
        self.volume = volume

    def getPlaybackVolume(self):
        return self.volume

    def setCurrentSong(self, path):
        self.currentSong = path

def test_playerControls():
    mockPlayer = MockPlayer()
    uut = SoloTool(mockPlayer)
    
    assert mockPlayer.state == MockPlayer.STOPPED
    uut.play()
    assert mockPlayer.state == MockPlayer.PLAYING
    uut.pause()
    assert mockPlayer.state == MockPlayer.PAUSED
    uut.stop()
    assert mockPlayer.state == MockPlayer.STOPPED

    assert mockPlayer.rate == 1.0
    uut.setPlaybackRate(0.5)
    assert mockPlayer.rate == 0.5

    assert mockPlayer.position == 0.0
    uut.setPlaybackPosition(0.5)
    assert mockPlayer.position == 0.5

    assert mockPlayer.volume == 1.0
    uut.setPlaybackVolume(0.5)
    assert mockPlayer.volume == 0.5

def test_addAndSetSong():
    song = "test.flac"
    mockPlayer = MockPlayer()
    uut = SoloTool(mockPlayer)

    uut.addSong(song)
    assert mockPlayer.currentSong == ""
    
    uut.setSong(0)
    assert mockPlayer.currentSong == song

def test_addAndSetAbLimit():
    song = "test.flac"
    abLimit = [0.2, 0.4]
    mockPlayer = MockPlayer()
    uut = SoloTool(mockPlayer)

    uut.addSong(song)
    uut.setSong(0)

    uut.addAbLimit(abLimit[0], abLimit[1])

    mockPlayer.position = 0.0
    uut.tick()
    assert mockPlayer.position == 0.0

    mockPlayer.position = 0.5
    uut.tick()
    assert mockPlayer.position == 0.5

    uut.setAbLimit(0)

    uut.tick()
    assert mockPlayer.position == 0.2

    uut.tick()
    assert mockPlayer.position == 0.2