aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test
diff options
context:
space:
mode:
Diffstat (limited to 'solo-tool-project/test')
-rw-r--r--solo-tool-project/test/fixtures.py32
-rw-r--r--solo-tool-project/test/handlers_integrationtest.py32
-rw-r--r--solo-tool-project/test/midi_launchpad_mini_integrationtest.py189
-rw-r--r--solo-tool-project/test/notifier_unittest.py3
-rw-r--r--solo-tool-project/test/player_mock.py27
-rw-r--r--solo-tool-project/test/session_manager_unittest.py55
-rw-r--r--solo-tool-project/test/solo_tool_integrationtest.py281
-rw-r--r--solo-tool-project/test/solo_tool_keypoints_integrationtest.py194
-rw-r--r--solo-tool-project/test/solo_tool_songs_integrationtest.py141
-rw-r--r--solo-tool-project/test/test.flacbin31743252 -> 0 bytes
-rw-r--r--solo-tool-project/test/test.mp3bin5389533 -> 0 bytes
-rw-r--r--solo-tool-project/test/test_session.json10
12 files changed, 525 insertions, 439 deletions
diff --git a/solo-tool-project/test/fixtures.py b/solo-tool-project/test/fixtures.py
new file mode 100644
index 0000000..f70901b
--- /dev/null
+++ b/solo-tool-project/test/fixtures.py
@@ -0,0 +1,32 @@
+import pytest
+from pathlib import Path
+import os
+
+from solo_tool.solo_tool import SoloTool
+from player_mock import Player as MockPlayer
+
+@pytest.fixture
+def mockPlayer():
+ return MockPlayer()
+
+@pytest.fixture
+def songPool(tmp_path):
+ return tmp_path / "songs"
+
+@pytest.fixture
+def soloTool(mockPlayer, songPool):
+ return SoloTool(songPool, player=mockPlayer)
+
+@pytest.fixture
+def testSongs(songPool):
+ songs = [
+ songPool / "test.flac",
+ songPool / "test.mp3",
+ songPool / "test.mp4"
+ ]
+
+ os.mkdir(songPool)
+ for song in songs:
+ song.touch()
+ return songs
+
diff --git a/solo-tool-project/test/handlers_integrationtest.py b/solo-tool-project/test/handlers_integrationtest.py
new file mode 100644
index 0000000..85050d6
--- /dev/null
+++ b/solo-tool-project/test/handlers_integrationtest.py
@@ -0,0 +1,32 @@
+import pytest
+
+from fixtures import soloTool, testSongs, mockPlayer, songPool
+
+from solo_tool.handlers import keyPointRelative
+
+testCases = [
+ ([0.1, 0.3], 0.0, +1, 0.1, "Start +1"),
+ ([0.1, 0.3], 0.1, +1, 0.3, "First +1"),
+ ([0.1, 0.3], 0.2, +1, 0.3, "Between +1"),
+ ([0.1, 0.3], 0.3, +1, 0.3, "Second +1"),
+ ([0.1, 0.3], 0.4, +1, 0.4, "End +1"),
+
+ ([0.1, 0.3], 0.0, -1, 0.0, "Start -1"),
+ ([0.1, 0.3], 0.1, -1, 0.1, "First -1"),
+ ([0.1, 0.3], 0.2, -1, 0.1, "Between -1"),
+ ([0.1, 0.3], 0.3, -1, 0.1, "Second -1"),
+ ([0.1, 0.3], 0.4, -1, 0.3, "End -1"),
+
+ ([0.0, 0.3], 0.0, -1, 0.0, "0.0 -1"),
+]
+
+@pytest.mark.parametrize("keyPoints,current,delta,expected,description", testCases)
+def test_keyPointRelativeEdgeCases(soloTool, testSongs, keyPoints, current, delta, expected, description):
+ soloTool.addSong(testSongs[0])
+ soloTool.keyPoints = keyPoints
+ soloTool.keyPoint = current
+
+ handler = keyPointRelative(soloTool, delta)
+ handler()
+
+ assert soloTool.keyPoint == expected, description
diff --git a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
index 9588f9f..be8ed88 100644
--- a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
+++ b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
@@ -2,8 +2,7 @@ import pytest
from mido import Message
from solo_tool.midi_controller_launchpad_mini import MidiController
-from solo_tool.solo_tool import SoloTool
-from player_mock import Player as PlayerMock
+from fixtures import songPool, soloTool, mockPlayer, testSongs
LED_RED = 3
LED_YELLOW = 126
@@ -20,7 +19,7 @@ rwd25PcButton = 49
previousSongButton = 48
playPauseButton = 112
-stopButton = 96
+jumpToStartButton = 96
nextKeyPositionButton = 119
previousKeyPositionButton = 118
@@ -52,14 +51,6 @@ class MidiWrapperMock:
return self.sentMessages[-1]
@pytest.fixture
-def playerMock():
- return PlayerMock()
-
-@pytest.fixture
-def soloTool(playerMock):
- return SoloTool(playerMock)
-
-@pytest.fixture
def midiWrapperMock():
return MidiWrapperMock()
@@ -67,99 +58,70 @@ def midiWrapperMock():
def uut(soloTool, midiWrapperMock):
return MidiController(soloTool, midiWrapperMock)
-def test_startStopAndPauseButtons(uut, midiWrapperMock, playerMock):
+def test_startAndPauseButtons(uut, midiWrapperMock, mockPlayer):
uut.connect()
- assert playerMock.state == PlayerMock.STOPPED
+ assert not mockPlayer.playing
midiWrapperMock.simulateInput(playPauseButton)
- assert playerMock.state == PlayerMock.PLAYING
+ assert mockPlayer.playing
assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
- midiWrapperMock.simulateInput(stopButton)
- assert playerMock.state == PlayerMock.STOPPED
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
-
- midiWrapperMock.simulateInput(playPauseButton)
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
-
midiWrapperMock.simulateInput(playPauseButton)
+ assert not mockPlayer.playing
assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
- assert playerMock.state == PlayerMock.PAUSED
- midiWrapperMock.simulateInput(playPauseButton)
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
- assert playerMock.state == PlayerMock.PLAYING
-
- midiWrapperMock.simulateInput(playPauseButton)
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
-
- midiWrapperMock.simulateInput(stopButton)
- assert playerMock.state == PlayerMock.STOPPED
-
-def test_startPauseButtonLed(uut, midiWrapperMock, playerMock, soloTool):
+def test_startPauseButtonLed(uut, midiWrapperMock, mockPlayer, soloTool):
uut.connect()
- assert playerMock.state == PlayerMock.STOPPED
+ assert not mockPlayer.playing
- playerMock.state = PlayerMock.PLAYING
- playerMock.simulatePlayingStateChanged()
+ mockPlayer.playing = True
+ mockPlayer.simulatePlayingStateChanged()
assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
- playerMock.state = PlayerMock.STOPPED
- playerMock.simulatePlayingStateChanged()
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
-
- playerMock.state = PlayerMock.PAUSED
- playerMock.simulatePlayingStateChanged()
+ mockPlayer.playing = False
+ mockPlayer.simulatePlayingStateChanged()
assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
- playerMock.state = PlayerMock.PLAYING
- playerMock.simulatePlayingStateChanged()
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
-
-def test_jumpToKeyPositionButton(uut, midiWrapperMock, soloTool, playerMock):
- soloTool.addSong("test.flac")
- soloTool.song = 0
+def test_jumpToKeyPositionButton(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
+ soloTool.addSong(testSongs[0])
uut.connect()
soloTool.keyPoint = 0.5
- assert playerMock.position == 0.0
+ assert mockPlayer.position == 0.0
midiWrapperMock.simulateInput(jumpToKeyPositionButton)
- assert playerMock.position == 0.5
+ assert mockPlayer.position == 0.5
-def test_previousAndNextSongButtons(uut, midiWrapperMock, soloTool, playerMock):
- songs = [
- "test.flac",
- "test.mp3"
- ]
- for s in songs:
+# TODO implement
+def test_jumpToStartButton(uut, midiWrapperMock, soloTool, mockPlayer):
+ pass
+
+def test_previousAndNextSongButtons(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
+ for s in testSongs:
soloTool.addSong(s)
uut.connect()
- assert playerMock.currentSong == None
- midiWrapperMock.simulateInput(nextSongButton)
- assert playerMock.currentSong == songs[0]
-
+ assert mockPlayer.currentSong == testSongs[0]
midiWrapperMock.simulateInput(nextSongButton)
- assert playerMock.currentSong == songs[1]
+ assert mockPlayer.currentSong == testSongs[1]
- midiWrapperMock.simulateInput(nextSongButton)
- assert playerMock.currentSong == songs[1]
+ for _ in testSongs:
+ midiWrapperMock.simulateInput(nextSongButton)
+ assert mockPlayer.currentSong == testSongs[-1]
midiWrapperMock.simulateInput(previousSongButton)
- assert playerMock.currentSong == songs[0]
+ assert mockPlayer.currentSong == testSongs[-2]
- midiWrapperMock.simulateInput(previousSongButton)
- assert playerMock.currentSong == songs[0]
+ for _ in testSongs:
+ midiWrapperMock.simulateInput(previousSongButton)
+ assert mockPlayer.currentSong == testSongs[0]
-def test_previousAndNextKeyPositionButtons(uut, midiWrapperMock, soloTool, playerMock):
- song = "test.flac"
+def test_previousAndNextKeyPositionButtons(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
keyPoints = [0.2, 0.1]
- soloTool.addSong(song)
- soloTool.song = 0
+ soloTool.addSong(testSongs[0])
soloTool.keyPoints = keyPoints
uut.connect()
@@ -167,18 +129,18 @@ def test_previousAndNextKeyPositionButtons(uut, midiWrapperMock, soloTool, playe
assert soloTool.keyPoint == 0.0
midiWrapperMock.simulateInput(nextKeyPositionButton)
- soloTool.keyPoint == 0.1
+ assert soloTool.keyPoint == 0.1
midiWrapperMock.simulateInput(nextKeyPositionButton)
- soloTool.keyPoint == 0.2
+ assert soloTool.keyPoint == 0.2
midiWrapperMock.simulateInput(previousKeyPositionButton)
- soloTool.keyPoint == 0.1
+ assert soloTool.keyPoint == 0.1
midiWrapperMock.simulateInput(previousKeyPositionButton)
- soloTool.keyPoint == 0.1
+ assert soloTool.keyPoint == 0.1
-def test_playbackRateButtons(uut, midiWrapperMock, soloTool, playerMock):
+def test_playbackRateButtons(uut, midiWrapperMock, soloTool, mockPlayer):
playbackRateOptions = {
16 : (0.5, [LED_YELLOW] * 1 + [LED_OFF] * 7),
17 : (0.6, [LED_YELLOW] * 2 + [LED_OFF] * 6),
@@ -190,18 +152,18 @@ def test_playbackRateButtons(uut, midiWrapperMock, soloTool, playerMock):
23 : (1.2, [LED_YELLOW] * 8)
}
uut.connect()
- assert playerMock.rate == 1.0
+ assert mockPlayer.rate == 1.0
for t, button in enumerate(playbackRateOptions):
midiWrapperMock.sentMessages.clear()
midiWrapperMock.simulateInput(button)
- assert playerMock.rate == playbackRateOptions[button][0]
+ assert mockPlayer.rate == playbackRateOptions[button][0]
for i, colour in enumerate(playbackRateOptions[button][1]):
assert midiWrapperMock.sentMessages[i] == (16 + i, colour, 0)
-def test_playbackRateLeds(uut, midiWrapperMock, soloTool, playerMock):
+def test_playbackRateLeds(uut, midiWrapperMock, soloTool, mockPlayer):
playbackRateOptions = [
(0.00, [LED_OFF] * 8),
(0.49, [LED_OFF] * 8),
@@ -231,19 +193,19 @@ def test_playbackRateLeds(uut, midiWrapperMock, soloTool, playerMock):
(1.5, [LED_YELLOW] * 8)
]
uut.connect()
- assert playerMock.rate == 1.0
+ assert mockPlayer.rate == 1.0
for t, (rate, leds) in enumerate(playbackRateOptions):
print(t)
midiWrapperMock.sentMessages.clear()
soloTool.rate = rate
- assert playerMock.rate == rate
+ assert mockPlayer.rate == rate
for i, colour in enumerate(leds):
assert midiWrapperMock.sentMessages[i] == (16 + i, colour, 0)
-def test_playbackVolumeButtons(uut, midiWrapperMock, soloTool, playerMock):
+def test_playbackVolumeButtons(uut, midiWrapperMock, soloTool, mockPlayer):
playbackVolumeOptions = {
0 : (0.5, [LED_GREEN] * 1 + [LED_OFF] * 7),
1 : (0.6, [LED_GREEN] * 2 + [LED_OFF] * 6),
@@ -255,18 +217,18 @@ def test_playbackVolumeButtons(uut, midiWrapperMock, soloTool, playerMock):
7 : (1.2, [LED_GREEN] * 8)
}
uut.connect()
- assert playerMock.volume == 1.0
+ assert mockPlayer.volume == 1.0
for t, button in enumerate(playbackVolumeOptions):
midiWrapperMock.sentMessages.clear()
midiWrapperMock.simulateInput(button)
- assert playerMock.volume == playbackVolumeOptions[button][0]
+ assert mockPlayer.volume == playbackVolumeOptions[button][0]
for i, colour in enumerate(playbackVolumeOptions[button][1]):
assert midiWrapperMock.sentMessages[i] == (i, colour, 0)
-def test_playbackVolumeLeds(uut, midiWrapperMock, soloTool, playerMock):
+def test_playbackVolumeLeds(uut, midiWrapperMock, soloTool, mockPlayer):
playbackVolumeOptions = [
(0.00, [LED_OFF] * 8),
(0.49, [LED_OFF] * 8),
@@ -296,13 +258,13 @@ def test_playbackVolumeLeds(uut, midiWrapperMock, soloTool, playerMock):
(1.5, [LED_GREEN] * 8)
]
uut.connect()
- assert playerMock.volume == 1.0
+ assert mockPlayer.volume == 1.0
for t, (volume, leds) in enumerate(playbackVolumeOptions):
midiWrapperMock.sentMessages.clear()
soloTool.volume = volume
- assert playerMock.volume == volume
+ assert mockPlayer.volume == volume
for i, colour in enumerate(leds):
assert midiWrapperMock.sentMessages[i] == (i, colour, 0)
@@ -321,7 +283,7 @@ def test_connectDisconnect(uut, midiWrapperMock):
[(i, LED_GREEN, 0) for i in range(0, 6)] + # volume row
[(i, LED_YELLOW, 0) for i in range(16, 22)] + # playback rate row
[
- (stopButton, LED_RED, 0),
+ (jumpToStartButton, LED_YELLOW, 0),
(playPauseButton, LED_YELLOW, 0),
(jumpToKeyPositionButton, LED_YELLOW, 0),
(previousKeyPositionButton, LED_RED, 0),
@@ -351,76 +313,67 @@ def test_connectDisconnect(uut, midiWrapperMock):
assert set(midiWrapperMock.sentMessages) == set(teardownMessages)
-def test_playingFeedbackWhenChangingSong(uut, midiWrapperMock, soloTool, playerMock):
- songs = [
- "test.flac",
- "test.mp3"
- ]
- for s in songs:
+def test_playingFeedbackWhenChangingSong(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
+ for s in testSongs:
soloTool.addSong(s)
uut.connect()
- soloTool.song = 0
soloTool.play()
- assert playerMock.state == PlayerMock.PLAYING
+ assert mockPlayer.playing
assert midiWrapperMock.getLatestMessage() == (playPauseButton, LED_GREEN, 0)
soloTool.song = 1
- assert playerMock.state == PlayerMock.STOPPED
+ assert not mockPlayer.playing
assert midiWrapperMock.getLatestMessage() == (playPauseButton, LED_YELLOW, 0)
-def test_setKeyPositionButton(uut, midiWrapperMock, soloTool, playerMock):
- song = "test.flac"
- soloTool.addSong(song)
- soloTool.song = 0
+def test_setKeyPositionButton(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
+ soloTool.addSong(testSongs[0])
uut.connect()
- playerMock.position = 0.3
+ mockPlayer.position = 0.3
midiWrapperMock.simulateInput(setKeyPositionButton)
assert soloTool.keyPoint == 0.3
- playerMock.position = 0.5
+ mockPlayer.position = 0.5
midiWrapperMock.simulateInput(setKeyPositionButton)
assert soloTool.keyPoint == 0.5
- playerMock.position = 0.7
+ mockPlayer.position = 0.7
midiWrapperMock.simulateInput(jumpToKeyPositionButton)
- assert playerMock.position == 0.5
+ assert mockPlayer.position == 0.5
-def test_seekButtons(uut, midiWrapperMock, soloTool, playerMock):
- song = "test.flac"
- soloTool.addSong(song)
- soloTool.song = 0
+def test_seekButtons(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
+ soloTool.addSong(testSongs[0])
uut.connect()
- assert playerMock.position == 0.0
+ assert mockPlayer.position == 0.0
midiWrapperMock.simulateInput(fwd25PcButton)
- assert playerMock.position == 0.25
+ assert mockPlayer.position == 0.25
midiWrapperMock.simulateInput(fwd5PcButton)
- assert playerMock.position == 0.30
+ assert mockPlayer.position == 0.30
midiWrapperMock.simulateInput(fwd1PcButton)
- assert playerMock.position == 0.31
+ assert mockPlayer.position == 0.31
midiWrapperMock.simulateInput(fwd25PcButton)
midiWrapperMock.simulateInput(fwd25PcButton)
midiWrapperMock.simulateInput(fwd25PcButton)
- assert playerMock.position == 1.0
+ assert mockPlayer.position == 1.0
midiWrapperMock.simulateInput(rwd25PcButton)
- assert playerMock.position == 0.75
+ assert mockPlayer.position == 0.75
midiWrapperMock.simulateInput(rwd5PcButton)
- assert playerMock.position == 0.70
+ assert mockPlayer.position == 0.70
midiWrapperMock.simulateInput(rwd1PcButton)
- assert playerMock.position == 0.69
+ assert mockPlayer.position == 0.69
midiWrapperMock.simulateInput(rwd25PcButton)
midiWrapperMock.simulateInput(rwd25PcButton)
midiWrapperMock.simulateInput(rwd25PcButton)
- assert playerMock.position == 0.0
+ assert mockPlayer.position == 0.0
diff --git a/solo-tool-project/test/notifier_unittest.py b/solo-tool-project/test/notifier_unittest.py
index 115d21a..5749149 100644
--- a/solo-tool-project/test/notifier_unittest.py
+++ b/solo-tool-project/test/notifier_unittest.py
@@ -38,6 +38,7 @@ def test_allEvents(uut):
checkEvent(uut, Notifier.PLAYBACK_RATE_EVENT)
checkEvent(uut, Notifier.CURRENT_SONG_EVENT)
checkEvent(uut, Notifier.CURRENT_KEY_POINT_EVENT)
+ checkEvent(uut, Notifier.KEY_POINT_LIST_EVENT)
def test_eventWithoutRegisteredCallbacks(uut):
uut.notify(Notifier.PLAYING_STATE_EVENT, 0)
@@ -59,7 +60,7 @@ def test_eventsWithMockPlayer(uut, mockPlayer):
assert called
assert receivedValue == expectedValue
- mockPlayer.state = 1
+ mockPlayer.playing = True
mockPlayer.volume = 75
checkEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged, True)
diff --git a/solo-tool-project/test/player_mock.py b/solo-tool-project/test/player_mock.py
index 3162e0f..e9e9ead 100644
--- a/solo-tool-project/test/player_mock.py
+++ b/solo-tool-project/test/player_mock.py
@@ -1,10 +1,6 @@
class Player():
- STOPPED = 0
- PLAYING = 1
- PAUSED = 2
-
def __init__(self):
- self.state = Player.STOPPED
+ self.playing = False
self.rate = 1.0
self.position = 0.0
self.volume = 1.0
@@ -13,25 +9,19 @@ class Player():
self.playbackVolumeChangedCallback = None
def play(self):
- previousState = self.state
- self.state = Player.PLAYING
- if previousState != Player.PLAYING:
- self.playingStateChangedCallback()
-
- def stop(self):
- previousState = self.state
- self.state = Player.STOPPED
- if previousState != Player.STOPPED:
+ previousState = self.playing
+ self.playing = True
+ if previousState != self.playing:
self.playingStateChangedCallback()
def pause(self):
- previousState = self.state
- self.state = Player.PAUSED
- if previousState != Player.PAUSED:
+ previousState = self.playing
+ self.playing = False
+ if previousState != self.playing:
self.playingStateChangedCallback()
def isPlaying(self):
- return self.state == Player.PLAYING
+ return self.playing
def setPlaybackRate(self, rate):
self.rate = rate
@@ -55,7 +45,6 @@ class Player():
return self.volume
def setCurrentSong(self, path):
- self.stop()
self.currentSong = path
def setPlayingStateChangedCallback(self, callback):
diff --git a/solo-tool-project/test/session_manager_unittest.py b/solo-tool-project/test/session_manager_unittest.py
index 8658032..cff3b35 100644
--- a/solo-tool-project/test/session_manager_unittest.py
+++ b/solo-tool-project/test/session_manager_unittest.py
@@ -1,24 +1,34 @@
import pytest
from json import loads
-import pathlib
-import shutil
+import os
from solo_tool.session_manager import loadSession, saveSession
-from solo_tool.solo_tool import SoloTool
+from fixtures import songPool, soloTool, mockPlayer, testSongs
@pytest.fixture
-def prepared_tmp_path(tmp_path):
- testFiles = [
- "test.flac",
- "test.mp3",
- "test_session.json"
- ]
- for f in testFiles:
- shutil.copy(pathlib.Path(f), tmp_path)
- return tmp_path
-
-def test_loadSession(prepared_tmp_path):
- soloTool = loadSession(prepared_tmp_path / "test_session.json")
+def testSessionFile(tmp_path, testSongs):
+ contents = """[
+ {
+ "path" : "test.flac",
+ "key_points" : []
+ },
+ {
+ "path" : "test.mp3",
+ "key_points" : [0.1, 0.3]
+ }
+]"""
+
+ basePath = tmp_path / "sessions"
+ sessionFile = basePath / "test-session.json"
+
+ os.mkdir(basePath)
+ with open(sessionFile, "w") as f:
+ f.write(contents)
+
+ return sessionFile
+
+def test_loadSession(songPool, testSessionFile, mockPlayer):
+ soloTool = loadSession(testSessionFile, songPool, player=mockPlayer)
assert soloTool.songs == ["test.flac", "test.mp3"]
@@ -28,31 +38,28 @@ def test_loadSession(prepared_tmp_path):
soloTool.song = 1
assert soloTool.keyPoints == [0.1, 0.3]
-def test_saveSession(prepared_tmp_path):
- soloTool = SoloTool()
+def test_saveSession(soloTool, testSessionFile, tmp_path):
soloTool.addSong("test.flac")
soloTool.addSong("test.mp3")
soloTool.song = 1
soloTool.keyPoints = [0.1, 0.3]
- testFile = prepared_tmp_path / "test_session_saved.json"
+ testFile = tmp_path / "test_session_saved.json"
saveSession(soloTool, testFile)
with open(testFile, "r") as f:
savedSession = loads(f.read())
- with open(prepared_tmp_path / "test_session.json", "r") as f:
+ with open(testSessionFile, "r") as f:
testSession = loads(f.read())
assert savedSession == testSession
-def test_loadAndSaveEmptySession(prepared_tmp_path):
- emptyFile = prepared_tmp_path / "empty_session.json"
-
- soloTool = SoloTool()
+def test_loadAndSaveEmptySession(songPool, soloTool, tmp_path):
+ emptyFile = tmp_path / "empty_session.json"
saveSession(soloTool, emptyFile)
- reloadedTool = loadSession(emptyFile)
+ reloadedTool = loadSession(emptyFile, songPool)
assert reloadedTool.songs == []
diff --git a/solo-tool-project/test/solo_tool_integrationtest.py b/solo-tool-project/test/solo_tool_integrationtest.py
index 2a818ed..7b274a3 100644
--- a/solo-tool-project/test/solo_tool_integrationtest.py
+++ b/solo-tool-project/test/solo_tool_integrationtest.py
@@ -1,42 +1,14 @@
-import pathlib
-import shutil
-import pytest
-
-from solo_tool.solo_tool import SoloTool
-from player_mock import Player as MockPlayer
-
-@pytest.fixture
-def mockPlayer():
- return MockPlayer()
-
-@pytest.fixture
-def uut(mockPlayer):
- return SoloTool(mockPlayer)
-
-@pytest.fixture
-def prepared_tmp_path(tmp_path):
- testFiles = [
- "test.flac",
- "test.mp3",
- "test_session.json"
- ]
- for f in testFiles:
- shutil.copy(pathlib.Path(f), tmp_path)
-
- return tmp_path
+from fixtures import soloTool as uut, songPool, mockPlayer, testSongs
def test_playerControls(uut, mockPlayer):
- assert mockPlayer.state == MockPlayer.STOPPED
- assert uut.isPlaying() == False
+ assert not mockPlayer.playing
+ assert not uut.playing
uut.play()
- assert mockPlayer.state == MockPlayer.PLAYING
- assert uut.isPlaying() == True
+ assert mockPlayer.playing
+ assert uut.playing
uut.pause()
- assert mockPlayer.state == MockPlayer.PAUSED
- assert uut.isPlaying() == False
- uut.stop()
- assert mockPlayer.state == MockPlayer.STOPPED
- assert uut.isPlaying() == False
+ assert not mockPlayer.playing
+ assert not uut.playing
assert mockPlayer.rate == 1.0
uut.rate = 0.5
@@ -107,145 +79,8 @@ def test_sanitizePlaybackVolume(uut):
uut.volume = 150.0
assert uut.volume == 150.0
-def test_addAndSelectSongs(uut, mockPlayer):
- songs = [
- "test.mp3",
- "test.flac"
- ]
-
- # Songs are added one by one
- for song in songs:
- uut.addSong(song)
-
- # Songs are not selected automatically
- assert mockPlayer.currentSong == None
- assert uut.song == None
-
- # Song order is preserved
- assert uut.songs == songs
-
- # Modifying the song list directly has no effect
- uut.songs.append("something")
- assert uut.songs == songs
-
- # Songs are selected by index
- for i, s in enumerate(uut.songs):
- uut.song = i
- assert mockPlayer.currentSong == uut.songs[i]
- assert uut.song == i
-
- # The current song cannot be de-selected
- uut.song = None
- assert uut.song == len(uut.songs) - 1
-
- # Non-existent songs cannot be selected
- uut.song = -1
- assert uut.song == len(uut.songs) - 1
-
- uut.song = 2
- assert uut.song == len(uut.songs) - 1
-
-def test_addAndJumpToKeyPoints(uut, mockPlayer):
- uut.addSong("test.flac")
- uut.addSong("test.mp3")
-
- def checkJump(before, expectedAfter):
- mockPlayer.position = before
- uut.jump()
- assert mockPlayer.position == expectedAfter
-
- # Key points are None as long as no song is selected
- uut.keyPoints = [0.1, 0.2]
- uut.keyPoint = 0.5
- assert uut.keyPoints is None
- assert uut.keyPoint is None
-
- uut.song = 0
-
- # Once a song is selected, jump to start by default
- assert uut.keyPoint == 0.0
- checkJump(0.5, 0.0)
-
- # By default songs have an empty list of key points
- assert uut.keyPoints == []
-
- uut.keyPoints = [0.2, 0.4, 0.1, 0.2]
-
- # Added key points are not automatically selected
- assert uut.keyPoint == 0.0
- checkJump(0.1, 0.0)
-
- # Any key point can be selected
- uut.keyPoint = uut.keyPoints[0]
- checkJump(0.0, uut.keyPoints[0])
-
- uut.keyPoint = 0.5
- checkJump(0.0, 0.5)
-
-def test_sanitizeKeyPoint(uut):
- song = "test.flac"
- uut.addSong(song)
- uut.song = 0
- uut.keyPoints = [0.2, 0.4, 0.1, 0.2, None, -0.5, 1.0, 1.5]
-
- # Added key points are automatically de-duplicated, sanitized and sorted to ascending order
- assert uut.keyPoints == [0.1, 0.2, 0.4]
-
- # Key point and key point list cannot be none
- uut.keyPoint = 0.5
-
- uut.keyPoint = None
- assert uut.keyPoint == 0.5
-
- uut.keyPoints = None
- assert uut.keyPoints == [0.1, 0.2, 0.4]
-
- # Valid key points are in [0, 1)
- uut.keyPoint = -0.1
- assert uut.keyPoint == 0.5
-
- uut.keyPoint = 1.0
- assert uut.keyPoint == 0.5
-
- uut.keyPoint = 0.999
- assert uut.keyPoint == 0.999
-
-def test_keyPointsPerSong(uut, mockPlayer):
- songs = [
- ("test.flac", [0.0, 0.5]),
- ("test.mp3", [0.1])
- ]
-
- # Key points list is set for the selected song
- for i, (song, keyPoints) in enumerate(songs):
- uut.addSong(song)
- uut.song = i
- uut.keyPoints = keyPoints
-
- # Key points list is automatically loaded when the song selection changes
- # Active key point is always reset to 0 when song selection changes
- for i, (song, keyPoints) in enumerate(songs):
- uut.keyPoint = 0.5
- uut.song = i
- assert uut.keyPoints == keyPoints
- assert uut.keyPoint == 0.0
-
- # Key points are copied, not stored by reference
- for i, (song, keyPoints) in enumerate(songs):
- uut.song = i
- keyPoints.append(1.0)
- assert 1.0 not in uut.keyPoints
-
-def test_addInexistentSong(uut, mockPlayer):
- song = "not/a/real/file"
-
- with pytest.raises(FileNotFoundError):
- uut.addSong(song)
-
-def test_playingStateNotification(uut, mockPlayer):
- song = "test.flac"
- uut.addSong(song)
- uut.song = 0
+def test_playingStateNotification(uut, mockPlayer, testSongs):
+ uut.addSong(testSongs[0])
called = False
receivedValue = None
@@ -256,7 +91,7 @@ def test_playingStateNotification(uut, mockPlayer):
uut.registerPlayingStateCallback(callback)
- assert mockPlayer.state == MockPlayer.STOPPED
+ assert not mockPlayer.playing
assert not called
uut.play()
@@ -273,22 +108,8 @@ def test_playingStateNotification(uut, mockPlayer):
uut.pause()
assert not called
- uut.play()
- assert called
- assert receivedValue == True
- called = False
-
- uut.stop()
- assert called
- assert receivedValue == False
- called = False
- uut.stop()
- assert not called
-
-def test_playbackVolumeNotification(uut, mockPlayer):
- song = "test.flac"
- uut.addSong(song)
- uut.song = 0
+def test_playbackVolumeNotification(uut, mockPlayer, testSongs):
+ uut.addSong(testSongs[0])
called = False
receivedValue = None
@@ -309,10 +130,8 @@ def test_playbackVolumeNotification(uut, mockPlayer):
uut.volume = 0.3
assert not called
-def test_playbackRateNotification(uut, mockPlayer):
- song = "test.flac"
- uut.addSong(song)
- uut.song = 0
+def test_playbackRateNotification(uut, mockPlayer, testSongs):
+ uut.addSong(testSongs[0])
called = False
receivedValue = None
@@ -333,75 +152,3 @@ def test_playbackRateNotification(uut, mockPlayer):
uut.rate = 0.5
assert not called
-def test_currentSongNotification(uut):
- called = False
- receivedValue = None
- def callback(value):
- nonlocal called, receivedValue
- called = True
- receivedValue = value
-
- uut.registerCurrentSongCallback(callback)
- assert not called
-
- songs = [
- "test.flac",
- "test.mp3"
- ]
-
- # Adding a song does not trigger a notification
- uut.addSong(songs[0])
- assert not called
-
- # Selecting a song for the first time triggers
- uut.song = 0
- assert called
- assert receivedValue == 0
- called = False
-
- uut.addSong(songs[1])
- assert not called
-
- # Selecting the same song does not trigger
- uut.song = 0
- assert not called
-
- uut.song = 1
- assert called
- assert receivedValue == 1
- called = False
-
-def test_currentKeyPointNotification(uut):
- called = False
- receivedValue = None
- def callback(value):
- nonlocal called, receivedValue
- called = True
- receivedValue = value
-
- uut.registerCurrentKeyPointCallback(callback)
- assert not called
-
- song = "test.flac"
- uut.addSong(song)
- uut.song = 0
-
- # Selecting a song for the first time sets the key point to 0.0
- assert called
- assert receivedValue == 0.0
- called = False
-
- # Changing the key point triggers a notification
- uut.keyPoint = 0.5
- assert called
- assert receivedValue == 0.5
- called = False
-
- # Adding list of key points does not trigger a notification
- uut.keyPoints = [0.2, 0.4]
- assert not called
-
- # Assigning the same key point again does not trigger a notification
- uut.keyPoint = 0.5
- assert not called
-
diff --git a/solo-tool-project/test/solo_tool_keypoints_integrationtest.py b/solo-tool-project/test/solo_tool_keypoints_integrationtest.py
new file mode 100644
index 0000000..3db86f5
--- /dev/null
+++ b/solo-tool-project/test/solo_tool_keypoints_integrationtest.py
@@ -0,0 +1,194 @@
+import pytest
+
+from fixtures import soloTool as uut, songPool, mockPlayer, testSongs
+
+def test_keyPointAndSongSelection(uut, mockPlayer, testSongs):
+ def checkJump(before, expectedAfter):
+ mockPlayer.position = before
+ uut.jump()
+ assert mockPlayer.position == expectedAfter
+
+ # Key point is initially unset
+ assert uut.keyPoint is None
+
+ # If no song is selected, setting the key point has no effect
+ assert uut.song is None
+ uut.keyPoint = 0.5
+ assert uut.keyPoint is None
+
+ # With a song selected, key point can be set and jumping works
+ uut.addSong(testSongs[0])
+ uut.keyPoints = [0.3, 0.5]
+
+ uut.keyPoint = 0.6
+ assert uut.keyPoint == 0.6
+ checkJump(0.8, 0.6)
+
+ # When another song is selected, the key point is set to 0.0
+ uut.addSong(testSongs[1])
+ uut.song = 1
+ assert uut.keyPoint == 0.0
+ checkJump(0.5, 0.0)
+
+ # If the selected song has stored key points, the key point is set to the first one instead
+ uut.song = 0
+ assert uut.keyPoint == 0.3
+ checkJump(0.5, 0.3)
+
+def test_keyPointListAndSongSelection(uut, testSongs):
+ # Key point list is initially unset, since no song is selected
+ assert uut.keyPoint is None
+
+ # If no song is selected, setting the key point list has no effect
+ assert uut.song is None
+ uut.keyPoints = [0.5]
+ assert uut.keyPoints is None
+
+ # When a song is added, key point list is initialized to empty
+ uut.addSong(testSongs[0])
+ assert uut.keyPoints == []
+
+ # A new list can be assigned to the song, but it does not affect the current key point
+ uut.keyPoints = [0.1, 0.3]
+ assert uut.keyPoints == [0.1, 0.3]
+ assert uut.keyPoint == 0.0
+
+ # Each song has its own list of key points
+ uut.addSong(testSongs[1])
+ uut.song = 1
+ uut.keyPoints = [0.4]
+
+ uut.song = 0
+ assert uut.keyPoints == [0.1, 0.3]
+ uut.song = 1
+ assert uut.keyPoints == [0.4]
+
+def test_keyPointEdgeCases(uut, testSongs):
+ uut.addSong(testSongs[0])
+
+ # Key point cannot be unset
+ uut.keyPoint = None
+ assert uut.keyPoint == 0.0
+
+ # Valid key points are in [0, 1)
+ uut.keyPoint = -0.1
+ assert uut.keyPoint == 0.0
+
+ uut.keyPoint = 1.0
+ assert uut.keyPoint == 0.0
+
+ uut.keyPoint = 0.999
+ assert uut.keyPoint == 0.999
+
+def test_keyPointListEdgeCases(uut, testSongs):
+ uut.addSong(testSongs[0])
+
+ # Key point list cannot be unset
+ uut.keyPoints = None
+ assert uut.keyPoints == []
+
+ # Appending to the list has no effect
+ uut.keyPoints.append(0.5)
+ assert uut.keyPoints == []
+
+ # Added key points are automatically de-duplicated, sanitized and sorted to ascending order
+ uut.keyPoints = [0.2, 0.4, 0.1, 0.2, None, -0.5, 1.0, 1.5]
+ assert uut.keyPoints == [0.1, 0.2, 0.4]
+
+def test_keyPointSelectionNotification(uut, testSongs):
+ called = False
+ receivedValue = None
+ def callback(value):
+ nonlocal called, receivedValue
+ called = True
+ receivedValue = value
+
+ uut.registerKeyPointSelectionCallback(callback)
+ assert not called
+
+ # Selecting a song for the first time sets the key point to 0.0
+ uut.addSong(testSongs[0])
+ assert called
+ assert receivedValue == 0.0
+ called = False
+
+ # Changing the key point triggers a notification
+ uut.keyPoint = 0.5
+ assert called
+ assert receivedValue == 0.5
+ called = False
+
+ # Adding list of key points does not trigger a notification
+ uut.keyPoints = [0.2, 0.4]
+ assert not called
+
+ # Assigning the same key point again does not trigger a notification
+ uut.keyPoint = 0.5
+ assert not called
+
+ # Changing song triggers the notification
+ uut.addSong(testSongs[1])
+ uut.song = 1
+ assert called
+ assert receivedValue == 0.0
+ called = False
+
+ # But only if the key point really changes
+ uut.keyPoint = 0.2
+ assert called
+ assert receivedValue == 0.2
+ called = False
+
+ uut.song = 0
+ assert not called
+
+def test_keyPointListNotification(uut, testSongs):
+ called = False
+ receivedValue = None
+ def callback(value):
+ nonlocal called, receivedValue
+ called = True
+ receivedValue = value
+
+ uut.registerKeyPointListCallback(callback)
+ assert not called
+
+ # Adding the first song triggers since the list is now not None
+ uut.addSong(testSongs[0])
+ assert called
+ assert receivedValue == []
+ called = False
+
+ # Adding list of key points triggers
+ uut.keyPoints = [0.2, 0.4]
+ assert called
+ assert receivedValue == [0.2, 0.4]
+ called = False
+
+ # Same list does not trigger
+ uut.keyPoints = [0.2, 0.4]
+ assert called
+ assert receivedValue == [0.2, 0.4]
+ called = False
+
+ # Incrementing list of key points triggers after sanitization
+ uut.keyPoints += [0.2, None, 0.1]
+ assert called
+ assert receivedValue == [0.1, 0.2, 0.4]
+ called = False
+
+ # Changing song triggers
+ uut.addSong(testSongs[1])
+ uut.song = 1
+ assert called
+ assert receivedValue == []
+ called = False
+
+ # But only if the list really changed
+ uut.keyPoints = [0.1, 0.2, 0.4]
+ assert called
+ assert receivedValue == [0.1, 0.2, 0.4]
+ called = False
+
+ uut.song = 0
+ assert not called
diff --git a/solo-tool-project/test/solo_tool_songs_integrationtest.py b/solo-tool-project/test/solo_tool_songs_integrationtest.py
new file mode 100644
index 0000000..6030d19
--- /dev/null
+++ b/solo-tool-project/test/solo_tool_songs_integrationtest.py
@@ -0,0 +1,141 @@
+import pytest
+
+from fixtures import soloTool as uut, songPool, mockPlayer, testSongs
+
+def test_songSelectionFlow(uut, mockPlayer, testSongs):
+ # Initially, song list is empty and no song is selected
+ assert uut.song is None
+ assert mockPlayer.currentSong == None
+ assert uut.songs == []
+
+ # When the first song is added, it is selected automatically
+ uut.addSong(testSongs[0])
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+ assert uut.songs == testSongs[0:1]
+
+ # Subsequently added songs are not selected automatically
+ # Song list order is addition order
+ for i, song in enumerate(testSongs[1:]):
+ uut.addSong(song)
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+ assert uut.songs == testSongs[0:i + 2]
+
+ # Songs are selected by index
+ for i, s in enumerate(uut.songs):
+ uut.song = i
+ assert uut.song == i
+ assert mockPlayer.currentSong == uut.songs[i]
+
+def test_songSelectionEdgeCases(uut, mockPlayer, testSongs):
+ # When no songs are available, selecting has no effect
+ uut.song = 0
+ assert uut.song == None
+ assert mockPlayer.currentSong == None
+
+ for song in testSongs:
+ uut.addSong(song)
+
+ # The current song cannot be de-selected
+ uut.song = None
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+
+ # Non-existent songs cannot be selected
+ uut.song = -1
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+
+ uut.song = len(testSongs)
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+
+def test_songAdditionEdgeCases(uut, mockPlayer, testSongs):
+ for song in testSongs:
+ uut.addSong(song)
+
+ # Modifying the song list directly has no effect
+ uut.songs.append("something")
+ assert uut.songs == testSongs
+ assert mockPlayer.currentSong == testSongs[0]
+
+ # Same song cannot be added twice
+ uut.addSong(testSongs[0])
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+ assert uut.songs == testSongs
+
+ # Songs must exist in the filesystem
+ with pytest.raises(FileNotFoundError):
+ uut.addSong("/not/a/real/file")
+ assert uut.song == 0
+ assert mockPlayer.currentSong == testSongs[0]
+ assert uut.songs == testSongs
+
+def test_songSelectionNotification(uut, testSongs):
+ selectionCalled = False
+ selectionValue = None
+ def selectionCallback(value):
+ nonlocal selectionCalled, selectionValue
+ selectionCalled = True
+ selectionValue = value
+
+ uut.registerSongSelectionCallback(selectionCallback)
+ assert not selectionCalled
+
+ # Adding the first song triggers because the song is automatically selected
+ uut.addSong(testSongs[0])
+
+ assert selectionCalled
+ assert selectionValue == 0
+ selectionCalled = False
+
+ # Adding more songs does not trigger
+ for i, song in enumerate(testSongs[1:]):
+ uut.addSong(song)
+ assert not selectionCalled
+
+ # Selecting another song triggers
+ uut.song = 1
+ assert selectionCalled
+ assert selectionValue == 1
+ selectionCalled = False
+
+ # Selecting the currently selected song does not trigger
+ uut.song = 1
+ assert not selectionCalled
+
+def test_songListNotification(uut, testSongs):
+ listCalled = False
+ listValue = None
+ def listCallback(value):
+ nonlocal listCalled, listValue
+ listCalled = True
+ listValue = value
+
+ uut.registerSongListCallback(listCallback)
+ assert not listCalled
+
+ # Adding the first song triggers
+ uut.addSong(testSongs[0])
+
+ assert listCalled
+ assert listValue == testSongs[0:1]
+ listCalled = False
+
+ # Adding more songs triggers
+ for i, song in enumerate(testSongs[1:]):
+ uut.addSong(song)
+
+ assert listCalled
+ assert listValue == testSongs[0:i + 2]
+ listCalled = False
+
+ # Modifying the list in place does not trigger
+ uut.songs.append("something")
+ assert not listCalled
+
+ # Adding an existing song does not trigger
+ uut.addSong(testSongs[0])
+ assert not listCalled
diff --git a/solo-tool-project/test/test.flac b/solo-tool-project/test/test.flac
deleted file mode 100644
index 9164735..0000000
--- a/solo-tool-project/test/test.flac
+++ /dev/null
Binary files differ
diff --git a/solo-tool-project/test/test.mp3 b/solo-tool-project/test/test.mp3
deleted file mode 100644
index 3c353b7..0000000
--- a/solo-tool-project/test/test.mp3
+++ /dev/null
Binary files differ
diff --git a/solo-tool-project/test/test_session.json b/solo-tool-project/test/test_session.json
deleted file mode 100644
index 49c2d42..0000000
--- a/solo-tool-project/test/test_session.json
+++ /dev/null
@@ -1,10 +0,0 @@
-[
- {
- "path" : "test.flac",
- "key_points" : []
- },
- {
- "path" : "test.mp3",
- "key_points" : [0.1, 0.3]
- }
-]