diff options
Diffstat (limited to 'solo-tool-project/test/session_manager_unittest.py')
-rw-r--r-- | solo-tool-project/test/session_manager_unittest.py | 55 |
1 files changed, 31 insertions, 24 deletions
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 == [] |