mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 21:50:28 +02:00
- Rename abogen/webui/routes/utils/preview.py → synthesize.py The file contains the core TTS synthesis pipeline (generate_preview_audio, synthesize_preview), not just preview logic. Name now matches responsibility. - Remove dead code from voice.py: get_preview_pipeline(), synthesize_audio_from_normalized(), _preview_pipeline_lock, _preview_pipelines, and unused imports (threading, numpy, create_pipeline, get_new_voice, _select_device, _to_float32, SAMPLE_RATE, SPLIT_PATTERN). These were never called — identical logic lives in synthesize.py. - Update imports in api.py, voices.py, and test_preview_applies_manual_overrides.py - 7 new tests in test_synthesize_module.py enforce file naming and import rules - 7 tests in test_domain_imports.py updated for renamed module
74 lines
2.7 KiB
Python
74 lines
2.7 KiB
Python
"""Tests that voice.py imports from domain modules, not from conversion_runner."""
|
|
import pathlib
|
|
|
|
|
|
_MODULE_SOURCE_CACHE: dict[str, str] = {}
|
|
|
|
|
|
def _read_source(module_file: str) -> str:
|
|
if module_file not in _MODULE_SOURCE_CACHE:
|
|
_MODULE_SOURCE_CACHE[module_file] = pathlib.Path(module_file).read_text(
|
|
encoding="utf-8"
|
|
)
|
|
return _MODULE_SOURCE_CACHE[module_file]
|
|
|
|
|
|
def test_voice_module_does_not_import_conversion_runner():
|
|
"""voice.py must not import from conversion_runner (architecture rule)."""
|
|
import abogen.webui.routes.utils.voice as voice_mod
|
|
|
|
source_text = _read_source(voice_mod.__file__)
|
|
|
|
assert "from abogen.webui.conversion_runner import" not in source_text, (
|
|
"voice.py still imports from conversion_runner — must use domain modules"
|
|
)
|
|
|
|
|
|
def test_synthesize_module_does_not_import_conversion_runner():
|
|
"""synthesize.py must not import from conversion_runner."""
|
|
import abogen.webui.routes.utils.synthesize as synthesize_mod
|
|
|
|
source_text = _read_source(synthesize_mod.__file__)
|
|
|
|
assert "from abogen.webui.conversion_runner import" not in source_text
|
|
|
|
|
|
def test_synthesize_module_imports_select_device_from_domain():
|
|
"""synthesize.py must import select_device from abogen.domain.device."""
|
|
import abogen.webui.routes.utils.synthesize as synthesize_mod
|
|
|
|
source_text = _read_source(synthesize_mod.__file__)
|
|
assert "from abogen.domain.device import" in source_text
|
|
|
|
|
|
def test_voice_module_does_not_define_synthesize_audio_from_normalized():
|
|
"""Dead code: synthesize_audio_from_normalized must be removed from voice.py."""
|
|
import abogen.webui.routes.utils.voice as voice_mod
|
|
|
|
source_text = _read_source(voice_mod.__file__)
|
|
assert "def synthesize_audio_from_normalized(" not in source_text
|
|
|
|
|
|
def test_voice_module_does_not_define_get_preview_pipeline():
|
|
"""Dead code: get_preview_pipeline must be removed from voice.py."""
|
|
import abogen.webui.routes.utils.voice as voice_mod
|
|
|
|
source_text = _read_source(voice_mod.__file__)
|
|
assert "def get_preview_pipeline(" not in source_text
|
|
|
|
|
|
def test_voice_module_does_not_import_domain_audio_helpers():
|
|
"""After removing dead code, voice.py no longer needs audio_helpers imports."""
|
|
import abogen.webui.routes.utils.voice as voice_mod
|
|
|
|
source_text = _read_source(voice_mod.__file__)
|
|
assert "from abogen.domain.audio_helpers import" not in source_text
|
|
|
|
|
|
def test_voice_module_does_not_import_domain_device():
|
|
"""After removing dead code, voice.py no longer needs device imports."""
|
|
import abogen.webui.routes.utils.voice as voice_mod
|
|
|
|
source_text = _read_source(voice_mod.__file__)
|
|
assert "from abogen.domain.device import" not in source_text
|