Files
DocsGPT/tests/tts/test_tts_creator.py
Alex 7da46c2bea feat: air-gapped deployment guide, no implicit downloads
- Ship tiktoken's cl100k_base inside the package and build the encoding
  from it, so token counting never downloads anything.
- Default EMBEDDINGS_CACHE_DIR to <data home>/models instead of FastEmbed's
  temp dir, and read tokenizer.json and repo metadata from that cache, so
  a model downloads once and survives reboots.
- TTS_PROVIDER=none and STT_PROVIDER=none switch the speech features off:
  the endpoints return 404, audio files fail to ingest with a clear
  message, /api/config reports tts_available/stt_available, and the UI
  hides the Speak and microphone buttons.
- Drop the Google Fonts Roboto import from the web UI.
- prefetch-models fills the cache the app reads; verify-offline checks the
  packaged encoding.
- Docs: new Air-Gapped Deployment guide, settings and cache notes.
2026-09-15 17:54:24 +01:00

71 lines
2.4 KiB
Python

import pytest
from unittest.mock import patch, MagicMock
from docsgpt.tts.tts_creator import TTSCreator
@pytest.fixture
def tts_creator():
return TTSCreator()
def test_create_google_tts(tts_creator):
# Patch the provider registry so the factory calls our mock class
with patch.dict(TTSCreator.tts_providers, {"google_tts": MagicMock()}):
mock_google_tts = TTSCreator.tts_providers["google_tts"]
instance = MagicMock()
mock_google_tts.return_value = instance
result = tts_creator.create_tts("google_tts", "arg1", key="value")
mock_google_tts.assert_called_once_with("arg1", key="value")
assert result == instance
def test_create_elevenlabs_tts(tts_creator):
# Patch the provider registry so the factory calls our mock class
with patch.dict(TTSCreator.tts_providers, {"elevenlabs": MagicMock()}):
mock_elevenlabs_tts = TTSCreator.tts_providers["elevenlabs"]
instance = MagicMock()
mock_elevenlabs_tts.return_value = instance
result = tts_creator.create_tts("elevenlabs", "voice", lang="en")
mock_elevenlabs_tts.assert_called_once_with("voice", lang="en")
assert result == instance
def test_invalid_tts_type(tts_creator):
with pytest.raises(ValueError) as excinfo:
tts_creator.create_tts("unknown_tts")
assert "No tts class found" in str(excinfo.value)
def test_tts_type_case_insensitivity(tts_creator):
# Patch the provider registry to ensure case-insensitive lookup hits our mock
with patch.dict(TTSCreator.tts_providers, {"google_tts": MagicMock()}):
mock_google_tts = TTSCreator.tts_providers["google_tts"]
instance = MagicMock()
mock_google_tts.return_value = instance
result = tts_creator.create_tts("GoOgLe_TtS")
mock_google_tts.assert_called_once_with()
assert result == instance
@pytest.mark.parametrize("value", ["none", "NONE", " none ", "", None])
def test_is_enabled_false_when_switched_off(value):
assert TTSCreator.is_enabled(value) is False
@pytest.mark.parametrize("value", ["google_tts", "elevenlabs"])
def test_is_enabled_for_a_provider(value):
assert TTSCreator.is_enabled(value) is True
def test_tts_providers_integrity(tts_creator):
providers = tts_creator.tts_providers
assert "google_tts" in providers
assert "elevenlabs" in providers
assert callable(providers["google_tts"])
assert callable(providers["elevenlabs"])