- introduce `LyricFlow.Core.Backend` with shared DTOs, rhyme/spellcheck engines, and REST endpoints - wire Python GUI/core to run and call the backend via new bridge/client modules - add backend parity/integration tests and update packaging/ignore settings
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
import unittest
|
|
|
|
from src.gui.backend_runner import BackendRunner
|
|
from src.lyricflow_core.api.backend_bridge import BackendBridge
|
|
from src.lyricflow_core.engine.rhyme_engine import RhymeEngine
|
|
from src.lyricflow_core.engine.spellcheck import SpellcheckEngine
|
|
|
|
|
|
class _DeadBridge:
|
|
def is_alive(self) -> bool:
|
|
return False
|
|
|
|
|
|
class TestBackendAnalysisParity(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.runner = BackendRunner()
|
|
cls.runner.start()
|
|
cls.bridge = BackendBridge()
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.runner.stop()
|
|
|
|
def test_rhyme_groups_and_density_match_python(self):
|
|
text = "# Header\n[Verse]\ncat bat\nflow glow"
|
|
local_engine = RhymeEngine()
|
|
local_engine.bridge = _DeadBridge()
|
|
|
|
self.assertEqual(local_engine.get_rhyme_groups(text), self.bridge.get_rhyme_groups(text))
|
|
self.assertEqual(local_engine.get_line_densities(text), self.bridge.get_line_densities(text))
|
|
|
|
def test_rhyme_suggestions_match_python(self):
|
|
local_engine = RhymeEngine()
|
|
local_engine.bridge = _DeadBridge()
|
|
self.assertEqual(local_engine.find_suggestions("cat"), self.bridge.get_rhymes("cat"))
|
|
|
|
def test_transposition_suggestion_exists(self):
|
|
suggestions = self.bridge.get_spelling_suggestions("wrod", 10)
|
|
self.assertIn("word", suggestions)
|
|
|
|
def test_spellcheck_basics_match_python(self):
|
|
local_spellcheck = SpellcheckEngine()
|
|
self.assertEqual(local_spellcheck.is_known_word("combat"), self.bridge.is_known_word("combat"))
|
|
self.assertEqual(local_spellcheck.is_known_word("gumguat"), self.bridge.is_known_word("gumguat"))
|
|
backend_candidate = self.bridge.get_autocorrect_candidate("nothign")
|
|
self.assertIn(backend_candidate, local_spellcheck.spelling_suggestions("nothign", limit=6))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|