aboutsummaryrefslogtreecommitdiff
path: root/app/tests
diff options
context:
space:
mode:
Diffstat (limited to 'app/tests')
-rw-r--r--app/tests/test_hub.py32
-rw-r--r--app/tests/test_tts.py25
-rw-r--r--app/tests/test_tui.py24
3 files changed, 81 insertions, 0 deletions
diff --git a/app/tests/test_hub.py b/app/tests/test_hub.py
index 439be26..7f16798 100644
--- a/app/tests/test_hub.py
+++ b/app/tests/test_hub.py
@@ -2186,6 +2186,35 @@ class SettingsTests(unittest.TestCase):
self.assertIsNotNone(hub._validate_port("70000"))
self.assertIsNotNone(hub._validate_port("abc"))
+ def test_language_fields_are_pickers_with_edit_hint(self):
+ # Both Language fields (Settings and Generate audiobooks) are
+ # static pickers over the audio.cpp-menu languages, with a dim
+ # hint inside their edit dialog. Common languages lead.
+ expected_choices = ["English", "Spanish", "Chinese", "French",
+ "German", "Italian", "Portuguese", "Japanese",
+ "Korean", "Russian", "Arabic", "Hindi",
+ "Vietnamese", "Auto"]
+ hint = hub._LANGUAGE_EDIT_HINT
+ self.assertEqual(hint,
+ ["Check model documentation for supported "
+ "languages."])
+
+ fields = hub._settings_fields()
+ field = next(f for f in fields if f["key"] == "language")
+ self.assertEqual(field["label"], "Default Language")
+ self.assertEqual(field["kind"], "choice")
+ self.assertEqual(field["choices"], expected_choices)
+ self.assertEqual(field["help"], hint)
+ self.assertEqual(field["value"], hub.config.LANGUAGE)
+
+ for gen_fields in (hub._common_fields(),):
+ field = next(f for f in gen_fields
+ if f["key"] == "language")
+ self.assertEqual(field["label"], "Language")
+ self.assertEqual(field["kind"], "choice")
+ self.assertEqual(field["choices"], expected_choices)
+ self.assertEqual(field["help"], hint)
+
def test_settings_menu_builds_form_and_saves(self):
captured = {}
@@ -2228,6 +2257,9 @@ class SettingsTests(unittest.TestCase):
self.assertEqual(labels["audiocpp_remote_url"],
"audio.cpp remote URL")
self.assertNotIn("(clone)", " ".join(labels.values()))
+ # The language setting is a picker labelled "Default Language".
+ self.assertEqual(labels["language"], "Default Language")
+ self.assertEqual(kinds["language"], "choice")
# The ports section note hangs off the first port field, the remote
# section note off the first remote URL field.
notes = {f["key"]: f.get("note") for f in captured["fields"]}
diff --git a/app/tests/test_tts.py b/app/tests/test_tts.py
index 49eb6f6..cf67c6c 100644
--- a/app/tests/test_tts.py
+++ b/app/tests/test_tts.py
@@ -25,6 +25,7 @@ from converter.clients import (
BACKEND_AUDIOCPP,
BACKEND_FASTER,
BACKEND_QWEN,
+ LANGUAGE_CHOICES,
LANGUAGE_ISO_CODES,
MODEL_SIZE,
SAMPLE_RATE,
@@ -66,6 +67,25 @@ class NormalizeLanguageTests(unittest.TestCase):
self.assertEqual(normalize_language("pt"), "Portuguese")
self.assertEqual(normalize_language("es"), "Spanish")
self.assertEqual(normalize_language("it"), "Italian")
+ self.assertEqual(normalize_language("ar"), "Arabic")
+ self.assertEqual(normalize_language("hi"), "Hindi")
+ self.assertEqual(normalize_language("vi"), "Vietnamese")
+
+ def test_audio_cpp_menu_languages_accepted(self):
+ # audio.cpp's WebUI menus add Arabic, Hindi and Vietnamese; the
+ # MagpieTTS Arabic regional variants collapse to plain Arabic.
+ self.assertEqual(normalize_language("arabic"), "Arabic")
+ self.assertEqual(normalize_language("Hindi"), "Hindi")
+ self.assertEqual(normalize_language("vietnamese"), "Vietnamese")
+ for variant in ("ar-AE", "ar-MSA", "ar-SA"):
+ self.assertEqual(normalize_language(variant), "Arabic")
+
+ def test_language_choices_are_valid_display_names(self):
+ # The TUI's static picker lists a permutation of TTS_LANGUAGES
+ # (common languages first), so every entry normalizes.
+ self.assertEqual(sorted(LANGUAGE_CHOICES), sorted(TTS_LANGUAGES))
+ for name in LANGUAGE_CHOICES:
+ self.assertEqual(normalize_language(name), name)
def test_all_supported_languages_round_trip(self):
for name in TTS_LANGUAGES:
@@ -1105,6 +1125,11 @@ class AudioCppFamilyDetectionTests(unittest.TestCase):
self.assertEqual(LANGUAGE_ISO_CODES["English"], "en")
self.assertIsNone(LANGUAGE_ISO_CODES.get("Auto"))
+ def test_iso_codes_cover_the_audio_cpp_menu_languages(self):
+ self.assertEqual(LANGUAGE_ISO_CODES["Arabic"], "ar")
+ self.assertEqual(LANGUAGE_ISO_CODES["Hindi"], "hi")
+ self.assertEqual(LANGUAGE_ISO_CODES["Vietnamese"], "vi")
+
class AudiocppEntryVoiceCapabilityTests(unittest.TestCase):
"""The per-entry voice capability resolver (speaker/clone/design)."""
diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py
index c836178..eb6872a 100644
--- a/app/tests/test_tui.py
+++ b/app/tests/test_tui.py
@@ -688,6 +688,30 @@ class FormTests(TuiTestCase):
self.assertIn("Value: ''", texts)
self.assert_inside_border(screen)
+ def test_choice_menu_shows_the_fields_help_lines(self):
+ # A choice field's "help" renders as dim lines inside its
+ # selection menu (like the text editor's hints).
+ fields = [
+ {"key": "fmt", "label": "Format", "kind": "choice",
+ "value": "mp3", "choices": ["mp3", "ogg"],
+ "help": ["Check the format docs for supported codecs."]},
+ {"key": "chunk", "label": "Chunk", "kind": "text",
+ "value": "250"},
+ ]
+ # Enter opens the choice menu, Esc backs out; Tab -> Save, Enter.
+ screen = FakeScreen(keys=[10, 27, 9, 10])
+ tui.form(screen, "Settings", fields)
+ texts = [text for _, _, text, _ in screen.strings]
+ self.assertIn("Check the format docs for supported codecs.", texts)
+ self.assert_inside_border(screen)
+
+ # Without the hint nothing renders it.
+ fields[0].pop("help")
+ screen = FakeScreen(keys=[10, 27, 9, 10])
+ tui.form(screen, "Settings", fields)
+ texts = [text for _, _, text, _ in screen.strings]
+ self.assertNotIn("Check the format docs for supported codecs.", texts)
+
def test_field_note_renders_and_save(self):
fields = self._fields()
fields[1]["note"] = "A short section note"