Files
abogen/tests/test_preview_applies_manual_overrides.py
T
Artem Akymenko 0dc491e420 refactor: unify Language enum across all layers
- EngineConfig.language: Language (was lang_code: str = 'a')
- Engine owns _KOKORO_LANG_MAP, engine_language(), supported_languages()
- Engine provides language_for_voice_id() for voice catalog
- Plugins/kokoro/__init__.py calls engine_language() internally
- create_pipeline(plugin_id, language=Language) — no kokoro codes
- pipeline_factory.py clean of kokoro-specific code
- Domain functions raise TypeError if non-enum passed
- WebUI api.py: _parse_language() helper at API boundary
- Voice catalog returns ISO codes (lang.value)
- Constants: LANGUAGE_DESCRIPTIONS keyed by Language enum
- All tests updated for Language enum
- 1414 tests pass
2026-07-27 07:36:36 +00:00

62 lines
2.0 KiB
Python

from abogen.domain.enums import Language
from abogen.webui.routes.utils import synthesize
def test_preview_applies_manual_override_before_normalization(monkeypatch):
# Don't run real TTS/normalization; just exercise the override stage by
# forcing provider=kokoro and then stubbing normalize_for_pipeline.
monkeypatch.setattr(synthesize, "get_preview_pipeline", lambda language, device: None)
# Stub normalize_for_pipeline to be identity; we only care that overrides run.
class _Norm:
@staticmethod
def normalize_for_pipeline(text):
return text
monkeypatch.setitem(
__import__("sys").modules, "abogen.kokoro_text_normalization", _Norm
)
# And stub the kokoro pipeline path so generate_preview_audio won't proceed.
# We'll instead validate by calling the override logic through generate_preview_audio
# with provider=supertonic and stub create_backend to capture input.
captured = {}
class DummyPipeline:
def __init__(self, **kwargs):
pass
def __call__(self, text, **kwargs):
captured["text"] = text
return iter(())
from abogen.tts_plugin import utils
original_create_pipeline = utils.create_pipeline
def _mock_create_pipeline(backend_id, **kwargs):
if backend_id == "supertonic":
return DummyPipeline(**kwargs)
return original_create_pipeline(backend_id, **kwargs)
monkeypatch.setattr(utils, "create_pipeline", _mock_create_pipeline)
try:
synthesize.generate_preview_audio(
text="He said Unfu*k loudly.",
voice_spec="M1",
language=Language.EN_US,
speed=1.0,
use_gpu=False,
tts_provider="supertonic",
manual_overrides=[{"token": "Unfu*k", "pronunciation": "Unfuck"}],
)
except Exception:
# generate_preview_audio will raise because no audio chunks; that's fine.
pass
assert "text" in captured
assert "Unfuck" in captured["text"]
assert "Unfu*k" not in captured["text"]