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.py11
-rw-r--r--solo-tool-project/test/session_manager_unittest.py39
2 files changed, 29 insertions, 21 deletions
diff --git a/solo-tool-project/test/fixtures.py b/solo-tool-project/test/fixtures.py
index f70901b..e63d363 100644
--- a/solo-tool-project/test/fixtures.py
+++ b/solo-tool-project/test/fixtures.py
@@ -11,7 +11,15 @@ def mockPlayer():
@pytest.fixture
def songPool(tmp_path):
- return tmp_path / "songs"
+ path = tmp_path / "songs"
+ os.mkdir(path)
+ return path
+
+@pytest.fixture
+def sessionPath(tmp_path):
+ path = tmp_path / "sessions"
+ os.mkdir(path)
+ return path
@pytest.fixture
def soloTool(mockPlayer, songPool):
@@ -25,7 +33,6 @@ def testSongs(songPool):
songPool / "test.mp4"
]
- os.mkdir(songPool)
for song in songs:
song.touch()
return songs
diff --git a/solo-tool-project/test/session_manager_unittest.py b/solo-tool-project/test/session_manager_unittest.py
index cff3b35..bd6fbb6 100644
--- a/solo-tool-project/test/session_manager_unittest.py
+++ b/solo-tool-project/test/session_manager_unittest.py
@@ -2,11 +2,11 @@ import pytest
from json import loads
import os
-from solo_tool.session_manager import loadSession, saveSession
-from fixtures import songPool, soloTool, mockPlayer, testSongs
+from solo_tool.session_manager import getSessionManager
+from fixtures import songPool, soloTool, mockPlayer, testSongs, sessionPath
@pytest.fixture
-def testSessionFile(tmp_path, testSongs):
+def testSessionFile(sessionPath, testSongs):
contents = """[
{
"path" : "test.flac",
@@ -17,19 +17,20 @@ def testSessionFile(tmp_path, testSongs):
"key_points" : [0.1, 0.3]
}
]"""
-
- basePath = tmp_path / "sessions"
- sessionFile = basePath / "test-session.json"
-
- os.mkdir(basePath)
+ sessionFile = sessionPath / "test-session.json"
with open(sessionFile, "w") as f:
f.write(contents)
-
return sessionFile
-def test_loadSession(songPool, testSessionFile, mockPlayer):
- soloTool = loadSession(testSessionFile, songPool, player=mockPlayer)
+@pytest.fixture
+def sessionManager(sessionPath, songPool):
+ return getSessionManager(songPool, sessionPath)
+
+def test_loadSession(sessionManager, mockPlayer, testSessionFile):
+ sessions = sessionManager.getSessions()
+ assert sessions == [testSessionFile.stem]
+ soloTool = sessionManager.loadSession(sessions[0], player=mockPlayer)
assert soloTool.songs == ["test.flac", "test.mp3"]
soloTool.song = 0
@@ -38,16 +39,16 @@ def test_loadSession(songPool, testSessionFile, mockPlayer):
soloTool.song = 1
assert soloTool.keyPoints == [0.1, 0.3]
-def test_saveSession(soloTool, testSessionFile, tmp_path):
+def test_saveSession(sessionManager, soloTool, testSessionFile, sessionPath):
soloTool.addSong("test.flac")
soloTool.addSong("test.mp3")
soloTool.song = 1
soloTool.keyPoints = [0.1, 0.3]
- testFile = tmp_path / "test_session_saved.json"
- saveSession(soloTool, testFile)
+ sessionKey = "test_session_saved"
+ sessionManager.saveSession(soloTool, sessionKey)
- with open(testFile, "r") as f:
+ with open(sessionPath / f"{sessionKey}.json", "r") as f:
savedSession = loads(f.read())
with open(testSessionFile, "r") as f:
@@ -55,11 +56,11 @@ def test_saveSession(soloTool, testSessionFile, tmp_path):
assert savedSession == testSession
-def test_loadAndSaveEmptySession(songPool, soloTool, tmp_path):
- emptyFile = tmp_path / "empty_session.json"
+def test_loadAndSaveEmptySession(sessionManager, sessionPath, soloTool, tmp_path):
+ emptySession = "empty_session"
- saveSession(soloTool, emptyFile)
- reloadedTool = loadSession(emptyFile, songPool)
+ sessionManager.saveSession(soloTool, emptySession)
+ reloadedTool = sessionManager.loadSession(emptySession)
assert reloadedTool.songs == []