mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 19:50:59 +02:00
- 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
98 lines
2.9 KiB
Python
98 lines
2.9 KiB
Python
"""Tests for split pattern logic."""
|
|
import os
|
|
import sys
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
import pytest
|
|
|
|
from abogen.domain.enums import Language
|
|
from abogen.domain.split_pattern import get_split_pattern
|
|
|
|
|
|
# --- English always returns \n ---
|
|
|
|
class TestEnglish:
|
|
def test_english_sentence(self):
|
|
assert get_split_pattern(Language.EN_US, "Sentence") == "\n"
|
|
|
|
def test_english_sentence_comma(self):
|
|
assert get_split_pattern(Language.EN_US, "Sentence + Comma") == "\n"
|
|
|
|
def test_english_line(self):
|
|
assert get_split_pattern(Language.EN_US, "Line") == "\n"
|
|
|
|
def test_english_disabled(self):
|
|
assert get_split_pattern(Language.EN_US, "Disabled") == "\n"
|
|
|
|
def test_english_gb(self):
|
|
assert get_split_pattern(Language.EN_GB, "Sentence") == "\n"
|
|
|
|
|
|
# --- CJK languages ---
|
|
|
|
class TestCJK:
|
|
def test_chinese_disabled(self):
|
|
pattern = get_split_pattern(Language.ZH, "Disabled")
|
|
assert pattern != "\n"
|
|
assert r"\n+" in pattern
|
|
|
|
def test_chinese_line(self):
|
|
pattern = get_split_pattern(Language.ZH, "Line")
|
|
assert pattern != "\n"
|
|
assert r"\n+" in pattern
|
|
|
|
def test_chinese_sentence(self):
|
|
pattern = get_split_pattern(Language.ZH, "Sentence")
|
|
assert r"\n+" in pattern
|
|
|
|
def test_chinese_sentence_comma(self):
|
|
pattern = get_split_pattern(Language.ZH, "Sentence + Comma")
|
|
assert r"\n+" in pattern
|
|
|
|
def test_japanese_disabled(self):
|
|
pattern = get_split_pattern(Language.JA, "Disabled")
|
|
assert pattern != "\n"
|
|
assert r"\n+" in pattern
|
|
|
|
def test_japanese_sentence(self):
|
|
pattern = get_split_pattern(Language.JA, "Sentence")
|
|
assert r"\n+" in pattern
|
|
|
|
|
|
# --- Other languages ---
|
|
|
|
class TestOtherLanguages:
|
|
def test_spanish_sentence(self):
|
|
pattern = get_split_pattern(Language.ES, "Sentence")
|
|
assert r"\n+" in pattern
|
|
|
|
def test_spanish_line(self):
|
|
assert get_split_pattern(Language.ES, "Line") == "\n"
|
|
|
|
def test_spanish_disabled(self):
|
|
assert get_split_pattern(Language.ES, "Disabled") == r"\n+"
|
|
|
|
def test_french_sentence_comma(self):
|
|
pattern = get_split_pattern(Language.FR, "Sentence + Comma")
|
|
assert r"\n+" in pattern
|
|
|
|
|
|
# --- Pattern structure ---
|
|
|
|
class TestPatternStructure:
|
|
def test_sentence_has_lookbehind(self):
|
|
pattern = get_split_pattern(Language.ES, "Sentence")
|
|
assert r"(?<=" in pattern
|
|
|
|
def test_sentence_comma_has_comma_chars(self):
|
|
pattern = get_split_pattern(Language.ES, "Sentence + Comma")
|
|
assert "," in pattern
|
|
|
|
def test_cjk_spacing_uses_star(self):
|
|
pattern = get_split_pattern(Language.ZH, "Sentence")
|
|
assert r"\s*" in pattern
|
|
|
|
def test_non_cjk_spacing_uses_plus(self):
|
|
pattern = get_split_pattern(Language.ES, "Sentence")
|
|
assert r"\s+" in pattern
|