pyLyricFlow/tests/test_core_api_project_state.py
2026-02-24 13:22:10 -06:00

36 lines
1.2 KiB
Python

import os
import tempfile
import unittest
from src.lyricflow_core.api.project_state import ProjectState, project_state_service
class TestProjectStateService(unittest.TestCase):
def test_parse_cursor_positions_defensive(self):
raw = {
"song1": "42",
"song2": -10,
"song3": "bad",
123: 7,
}
expected = {"song1": 42, "song2": 0}
self.assertEqual(expected, project_state_service.parse_cursor_positions(raw))
def test_round_trip_file(self):
with tempfile.TemporaryDirectory() as tmp:
project_file = os.path.join(tmp, ".lyricproject")
original = ProjectState(
version=2,
name="demo",
open_files=[os.path.join(tmp, "a.lmd"), os.path.join(tmp, "b.lmd")],
active_file=os.path.join(tmp, "b.lmd"),
cursor_positions={os.path.join(tmp, "a.lmd"): 3, os.path.join(tmp, "b.lmd"): 8},
)
project_state_service.write_project(project_file, original)
loaded = project_state_service.read_project(project_file)
self.assertEqual(original, loaded)
if __name__ == "__main__":
unittest.main()