from __future__ import annotations import unittest from unittest.mock import patch from src import tts_engine from modal_apps import modal_tts class TtsEngineTests(unittest.TestCase): def test_kokoro_star_voice_maps_to_neutral_voice(self) -> None: self.assertEqual(modal_tts.KOKORO_VOICE_ALIASES["star_neutral"], "zm_yunxi") self.assertEqual(modal_tts.KOKORO_VOICE_ALIASES["default"], "zm_yunxi") def test_synthesize_uses_short_timeout(self) -> None: class Response: content = b"RIFF....WAVE" def raise_for_status(self): return None calls = [] def fake_post(url, json, timeout, trust_env): calls.append({"url": url, "json": json, "timeout": timeout, "trust_env": trust_env}) return Response() with patch.dict("os.environ", {"VC_MODAL_TTS_URL": "https://tts.example.test"}, clear=False): with patch("httpx.post", fake_post): path = tts_engine.synthesize_sentence( "你好。", {"voice": {"voice_id": "star_neutral", "backend": "kokoro"}}, {"voice_id": "star_neutral", "enabled": True}, ) self.assertIsNotNone(path) self.assertEqual(calls[0]["json"]["voice_id"], "star_neutral") self.assertEqual(calls[0]["timeout"].read, tts_engine.DEFAULT_TTS_READ_TIMEOUT_SECONDS) self.assertFalse(calls[0]["trust_env"]) if __name__ == "__main__": unittest.main()