aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-22 10:59:12 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-22 10:59:12 +0100
commit96a574d317ccbbff3af3f1a20755c3b79f873510 (patch)
tree664c38b4963a39d8dc709b5b5477a3a16ce6f766
parent2aba13e9ab112e1aeb80b8f8f946c463ab76348b (diff)
Added load/save integration tests, test assets
-rw-r--r--session.json1
-rw-r--r--solo_tool.py17
-rw-r--r--solo_tool_integrationtest.py131
-rw-r--r--test_session.json13
4 files changed, 147 insertions, 15 deletions
diff --git a/session.json b/session.json
deleted file mode 100644
index d1ed92a..0000000
--- a/session.json
+++ /dev/null
@@ -1 +0,0 @@
-{"/home/eddy/projects/solo-tool/03 Night Is Over.flac": [[41868, 61419], [129947, 131527]], "/home/eddy/projects/solo-tool/Aesir-LostEmpire.mp3": [[73071, 78008]]}
diff --git a/solo_tool.py b/solo_tool.py
index ff0f768..53670fb 100644
--- a/solo_tool.py
+++ b/solo_tool.py
@@ -7,7 +7,7 @@ class SoloTool:
def __init__(self, player=None):
self._player = Player() if player is None else player
self._playlist = Playlist(self._playlistCallback)
- self._abController = ABController(callback=self._abControllerCallback)
+ self._abController = ABController(enabled=False, callback=self._abControllerCallback)
self._sessionManager = SessionManager(self._playlist, self._abController)
def _playlistCallback(self, path):
@@ -17,6 +17,10 @@ class SoloTool:
def _abControllerCallback(self, position):
self._player.setPlaybackPosition(position)
+ def tick(self):
+ position = self._player.getPlaybackPosition()
+ self._abController.positionChanged(position)
+
def addSong(self, path):
self._sessionManager.addSong(path)
@@ -29,14 +33,17 @@ class SoloTool:
def setAbLimit(self, index):
self._abController.setCurrentLimits(0)
- def tick(self):
- position = self._player.getPlaybackPosition()
- self._abController.positionChanged(position)
-
+ def setAbLimitEnable(self, enable):
+ self._abController.setEnable(enable)
+
def loadSession(self, path):
with open(path, "r") as f:
self._sessionManager.loadSession(f)
+ def saveSession(self, path):
+ with open(path, "w") as f:
+ self._sessionManager.saveSession(f)
+
# Playback control
def play(self):
self._player.play()
diff --git a/solo_tool_integrationtest.py b/solo_tool_integrationtest.py
index b3a0978..bbc98a8 100644
--- a/solo_tool_integrationtest.py
+++ b/solo_tool_integrationtest.py
@@ -1,5 +1,6 @@
from solo_tool import SoloTool
-from time import sleep
+import pathlib
+import shutil
class MockPlayer():
STOPPED = 0
@@ -11,7 +12,7 @@ class MockPlayer():
self.rate = 1.0
self.position = 0.0
self.volume = 1.0
- self.currentSong = ""
+ self.currentSong = None
def play(self):
self.state = MockPlayer.PLAYING
@@ -67,16 +68,21 @@ def test_playerControls():
uut.setPlaybackVolume(0.5)
assert mockPlayer.volume == 0.5
-def test_addAndSetSong():
- song = "test.flac"
+def test_addAndSetSongs():
+ songs = [
+ "test.flac",
+ "test.mp3"
+ ]
mockPlayer = MockPlayer()
uut = SoloTool(mockPlayer)
-
- uut.addSong(song)
- assert mockPlayer.currentSong == ""
- uut.setSong(0)
- assert mockPlayer.currentSong == song
+ for s in songs:
+ uut.addSong(s)
+ assert mockPlayer.currentSong == None
+
+ for i, s in enumerate(songs):
+ uut.setSong(i)
+ assert mockPlayer.currentSong == songs[i]
def test_addAndSetAbLimit():
song = "test.flac"
@@ -100,8 +106,115 @@ def test_addAndSetAbLimit():
uut.setAbLimit(0)
uut.tick()
+ assert mockPlayer.position == 0.5
+
+ uut.setAbLimitEnable(True)
+
+ uut.tick()
assert mockPlayer.position == 0.2
uut.tick()
assert mockPlayer.position == 0.2
+def test_multipleSongsAndAbLimits():
+ songs = [
+ "test.flac",
+ "test.mp3"
+ ]
+ abLimits = [
+ [0.2, 0.4],
+ [0.5, 0.7]
+ ]
+ mockPlayer = MockPlayer()
+ uut = SoloTool(mockPlayer)
+
+ for s in songs:
+ uut.addSong(s)
+
+ for i, l in enumerate(abLimits):
+ uut.setSong(i)
+ uut.addAbLimit(l[0], l[1])
+
+ uut.setAbLimitEnable(True)
+
+ for i, l in enumerate(abLimits):
+ uut.setSong(i)
+ uut.setAbLimit(0)
+
+ mockPlayer.position = l[0]
+ uut.tick()
+ assert mockPlayer.position == l[0]
+
+ mockPlayer.position = l[1] + 0.1
+ uut.tick()
+ assert mockPlayer.position == l[0]
+
+def test_addAbLimitWithoutSong():
+ song = "test.flac"
+ abLimit = [0.2, 0.4]
+ overflow = abLimit[1] + 0.1
+ mockPlayer = MockPlayer()
+ uut = SoloTool(mockPlayer)
+ mockPlayer.position = overflow
+ uut.setAbLimitEnable(True)
+
+ uut.addAbLimit(abLimit[0], abLimit[1])
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.setAbLimit(0)
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.addSong(song)
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.setAbLimit(0)
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.setSong(0)
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.setAbLimit(0)
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.addAbLimit(abLimit[0], abLimit[1])
+ uut.tick()
+ assert mockPlayer.position == overflow
+
+ uut.setAbLimit(0)
+ uut.tick()
+ assert mockPlayer.position == abLimit[0]
+
+def copyTestFiles(tmp_path):
+ testFiles = [
+ "test.flac",
+ "test.mp3",
+ "test_session.json"
+ ]
+ for f in testFiles:
+ shutil.copy(pathlib.Path(f), tmp_path)
+
+def test_loadAndSaveSession(tmp_path):
+ copyTestFiles(tmp_path)
+ mockPlayer = MockPlayer()
+ uut = SoloTool(mockPlayer)
+
+ loadedSessionFile = tmp_path / "test_session.json"
+ savedSessionFile = tmp_path / "test_session_save.json"
+
+ uut.loadSession(loadedSessionFile)
+ uut.saveSession(savedSessionFile)
+
+ import json
+ with open(loadedSessionFile, "r") as f:
+ loadedSession = json.loads(f.read())
+
+ with open(savedSessionFile, "r") as f:
+ savedSession = json.loads(f.read())
+
+ assert loadedSession == savedSession
diff --git a/test_session.json b/test_session.json
new file mode 100644
index 0000000..f48b792
--- /dev/null
+++ b/test_session.json
@@ -0,0 +1,13 @@
+[
+ {
+ "path" : "test.flac",
+ "ab_limits" : null
+ },
+ {
+ "path" : "test.mp3",
+ "ab_limits" : [
+ [0.1, 0.2],
+ [0.3, 0.4]
+ ]
+ }
+]