aboutsummaryrefslogtreecommitdiffstats
path: root/solo_tool_integrationtest.py
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 /solo_tool_integrationtest.py
parent2aba13e9ab112e1aeb80b8f8f946c463ab76348b (diff)
Added load/save integration tests, test assets
Diffstat (limited to 'solo_tool_integrationtest.py')
-rw-r--r--solo_tool_integrationtest.py131
1 files changed, 122 insertions, 9 deletions
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