mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 11:40:57 +02:00
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
This commit is contained in:
+21
-25
@@ -1,10 +1,11 @@
|
||||
"""Tests for split pattern logic (3 identical copies in codebase)."""
|
||||
"""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
|
||||
|
||||
|
||||
@@ -12,49 +13,49 @@ from abogen.domain.split_pattern import get_split_pattern
|
||||
|
||||
class TestEnglish:
|
||||
def test_english_sentence(self):
|
||||
assert get_split_pattern("en-US", "Sentence") == "\n"
|
||||
assert get_split_pattern(Language.EN_US, "Sentence") == "\n"
|
||||
|
||||
def test_english_sentence_comma(self):
|
||||
assert get_split_pattern("en-US", "Sentence + Comma") == "\n"
|
||||
assert get_split_pattern(Language.EN_US, "Sentence + Comma") == "\n"
|
||||
|
||||
def test_english_line(self):
|
||||
assert get_split_pattern("en-US", "Line") == "\n"
|
||||
assert get_split_pattern(Language.EN_US, "Line") == "\n"
|
||||
|
||||
def test_english_disabled(self):
|
||||
assert get_split_pattern("en-US", "Disabled") == "\n"
|
||||
assert get_split_pattern(Language.EN_US, "Disabled") == "\n"
|
||||
|
||||
def test_english_gb(self):
|
||||
assert get_split_pattern("en-GB", "Sentence") == "\n"
|
||||
assert get_split_pattern(Language.EN_GB, "Sentence") == "\n"
|
||||
|
||||
|
||||
# --- CJK languages ---
|
||||
|
||||
class TestCJK:
|
||||
def test_chinese_disabled(self):
|
||||
pattern = get_split_pattern("zh", "Disabled")
|
||||
pattern = get_split_pattern(Language.ZH, "Disabled")
|
||||
assert pattern != "\n"
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_chinese_line(self):
|
||||
pattern = get_split_pattern("zh", "Line")
|
||||
pattern = get_split_pattern(Language.ZH, "Line")
|
||||
assert pattern != "\n"
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_chinese_sentence(self):
|
||||
pattern = get_split_pattern("zh", "Sentence")
|
||||
pattern = get_split_pattern(Language.ZH, "Sentence")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_chinese_sentence_comma(self):
|
||||
pattern = get_split_pattern("zh", "Sentence + Comma")
|
||||
pattern = get_split_pattern(Language.ZH, "Sentence + Comma")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_japanese_disabled(self):
|
||||
pattern = get_split_pattern("ja", "Disabled")
|
||||
pattern = get_split_pattern(Language.JA, "Disabled")
|
||||
assert pattern != "\n"
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_japanese_sentence(self):
|
||||
pattern = get_split_pattern("ja", "Sentence")
|
||||
pattern = get_split_pattern(Language.JA, "Sentence")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
|
||||
@@ -62,22 +63,17 @@ class TestCJK:
|
||||
|
||||
class TestOtherLanguages:
|
||||
def test_spanish_sentence(self):
|
||||
pattern = get_split_pattern("es", "Sentence")
|
||||
pattern = get_split_pattern(Language.ES, "Sentence")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_spanish_line(self):
|
||||
assert get_split_pattern("es", "Line") == "\n"
|
||||
assert get_split_pattern(Language.ES, "Line") == "\n"
|
||||
|
||||
def test_spanish_disabled(self):
|
||||
# canonical: \n+ for non-CJK Disabled
|
||||
assert get_split_pattern("es", "Disabled") == r"\n+"
|
||||
assert get_split_pattern(Language.ES, "Disabled") == r"\n+"
|
||||
|
||||
def test_french_sentence_comma(self):
|
||||
pattern = get_split_pattern("fr", "Sentence + Comma")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
def test_unknown_lang(self):
|
||||
pattern = get_split_pattern("x", "Sentence")
|
||||
pattern = get_split_pattern(Language.FR, "Sentence + Comma")
|
||||
assert r"\n+" in pattern
|
||||
|
||||
|
||||
@@ -85,17 +81,17 @@ class TestOtherLanguages:
|
||||
|
||||
class TestPatternStructure:
|
||||
def test_sentence_has_lookbehind(self):
|
||||
pattern = get_split_pattern("es", "Sentence")
|
||||
pattern = get_split_pattern(Language.ES, "Sentence")
|
||||
assert r"(?<=" in pattern
|
||||
|
||||
def test_sentence_comma_has_comma_chars(self):
|
||||
pattern = get_split_pattern("es", "Sentence + Comma")
|
||||
pattern = get_split_pattern(Language.ES, "Sentence + Comma")
|
||||
assert "," in pattern
|
||||
|
||||
def test_cjk_spacing_uses_star(self):
|
||||
pattern = get_split_pattern("zh", "Sentence")
|
||||
pattern = get_split_pattern(Language.ZH, "Sentence")
|
||||
assert r"\s*" in pattern
|
||||
|
||||
def test_non_cjk_spacing_uses_plus(self):
|
||||
pattern = get_split_pattern("es", "Sentence")
|
||||
pattern = get_split_pattern(Language.ES, "Sentence")
|
||||
assert r"\s+" in pattern
|
||||
|
||||
Reference in New Issue
Block a user