aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test/solo_tool_integrationtest.py
blob: 7b274a35c8954a2bc3752f9f724824b8b3122082 (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
149
150
151
152
153
154
from fixtures import soloTool as uut, songPool, mockPlayer, testSongs

def test_playerControls(uut, mockPlayer):
    assert not mockPlayer.playing
    assert not uut.playing
    uut.play()
    assert mockPlayer.playing
    assert uut.playing
    uut.pause()
    assert not mockPlayer.playing
    assert not uut.playing

    assert mockPlayer.rate == 1.0
    uut.rate = 0.5
    assert mockPlayer.rate == 0.5
    assert uut.rate == 0.5

    assert mockPlayer.position == 0.0
    uut.position = 0.5
    assert mockPlayer.position == 0.5
    assert uut.position == 0.5

    assert mockPlayer.volume == 1.0
    uut.volume = 0.5
    assert mockPlayer.volume == 0.5
    assert uut.volume == 0.5

def test_sanitizePlaybackRate(uut):
    # Initial value
    assert uut.rate == 1.0

    # Valid rates are >= 0.0, invalid is ignored
    uut.rate = -0.1
    assert uut.rate == 1.0

    uut.rate = 0.0
    assert uut.rate == 0.0
    
    uut.rate = 0.0001
    assert uut.rate == 0.0001

    uut.rate = 150.0
    assert uut.rate == 150.0

def test_sanitizePlaybackPosition(uut):
    # Initial value
    assert uut.position == 0.0

    # Valid positions are in [0, 1], invalid is limited
    uut.position = 0.2
    assert uut.position == 0.2

    uut.position = -0.1
    assert uut.position == 0.0

    uut.position = 1.0
    assert uut.position == 1.0

    uut.position = 0.4
    assert uut.position == 0.4

    uut.position = 1.5
    assert uut.position == 1.0

def test_sanitizePlaybackVolume(uut):
    # Initial value
    assert uut.volume == 1.0

    # Valid volumes are >= 0.0, invalid is ignored
    uut.volume = -0.1
    assert uut.volume == 1.0

    uut.volume = 0.0
    assert uut.volume == 0.0

    uut.volume = 1.0
    assert uut.volume == 1.0

    uut.volume = 150.0
    assert uut.volume == 150.0

def test_playingStateNotification(uut, mockPlayer, testSongs):
    uut.addSong(testSongs[0])

    called = False
    receivedValue = None
    def callback(value):
        nonlocal called, receivedValue
        called = True
        receivedValue = value

    uut.registerPlayingStateCallback(callback)

    assert not mockPlayer.playing
    assert not called

    uut.play()
    assert called
    assert receivedValue == True
    called = False
    uut.play()
    assert not called

    uut.pause()
    assert called
    assert receivedValue == False
    called = False
    uut.pause()
    assert not called

def test_playbackVolumeNotification(uut, mockPlayer, testSongs):
    uut.addSong(testSongs[0])

    called = False
    receivedValue = None
    def callback(value):
        nonlocal called, receivedValue
        called = True
        receivedValue = value

    uut.registerVolumeCallback(callback)

    assert not called

    uut.volume = 0.3
    assert called
    assert receivedValue == 0.3
    called = False

    uut.volume = 0.3
    assert not called

def test_playbackRateNotification(uut, mockPlayer, testSongs):
    uut.addSong(testSongs[0])

    called = False
    receivedValue = None
    def callback(value):
        nonlocal called, receivedValue
        called = True
        receivedValue = value

    uut.registerRateCallback(callback)

    assert not called

    uut.rate = 0.5
    assert called
    assert receivedValue == 0.5
    called = False

    uut.rate = 0.5
    assert not called