diff options
Diffstat (limited to 'app/tests')
| -rw-r--r-- | app/tests/test_hub.py | 50 | ||||
| -rw-r--r-- | app/tests/test_tui.py | 35 |
2 files changed, 85 insertions, 0 deletions
diff --git a/app/tests/test_hub.py b/app/tests/test_hub.py index 6657540..73ef075 100644 --- a/app/tests/test_hub.py +++ b/app/tests/test_hub.py @@ -856,6 +856,56 @@ class ConvertFlowTests(unittest.TestCase): instr = self._field("instructions") self.assertFalse(instr["visible"](fields)) + def test_audiocpp_remote_without_voices_refuses_generate_with_hint(self): + # A clone-capable entry (e.g. Qwen Base) whose server lists no + # voices at all: the Voice picker stays visible but is empty — + # opening it flashes where to configure voices instead of + # crashing — and Generate! refuses with the same hint. + self._patch_remote( + [{"id": "Qwen3-TTS-12Hz-1.7B-Base-GGUF", + "family": "qwen3_tts", "task": "tts"}], + voices=[]) + with patch.object(hub.config, "AUDIOCPP_INSTRUCTIONS", ""): + self._answer_form( + backend="audiocpp-remote", + model_id="Qwen3-TTS-12Hz-1.7B-Base-GGUF", + audiocpp_voice="", instructions="") + self._convert(None, [self._remote("audiocpp", "audio.cpp")]) + fields = self.tui.forms_seen[0][1] + voice_field = self._field("audiocpp_voice") + self.assertTrue(voice_field["visible"](fields)) + self.assertEqual(voice_field["choices"](fields), []) + error = voice_field["validate"]("") + self.assertIsNotNone(error) + self.assertIn(".wav", error) + self.assertIn("server", error) + + def test_audiocpp_local_without_voice_dir_points_at_configure(self): + # The managed entry's server.json has no voice_dir: clone-capable + # models get an empty Voice picker whose hint sends the user to + # Configure backends instead of crashing on menu(). + with tempfile.TemporaryDirectory() as td: + root = Path(td) + (root / "server.json").write_text(json.dumps({ + "models": [{"id": "qwen", "family": "qwen3_tts", + "task": "tts"}], + }), encoding="utf-8") + with patch.object(hub.audiocpp_backend, "find_local_checkout", + return_value=root), \ + patch.object(hub.config, "AUDIOCPP_INSTRUCTIONS", ""): + self._answer_form(backend="audiocpp", model_id="qwen", + audiocpp_voice="", instructions="") + self._convert(None, + [self._ready("audiocpp", "audio.cpp")]) + fields = self.tui.forms_seen[0][1] + voice_field = self._field("audiocpp_voice") + self.assertTrue(voice_field["visible"](fields)) + self.assertEqual(voice_field["choices"](fields), []) + error = voice_field["validate"]("") + self.assertIsNotNone(error) + self.assertIn(".wav", error) + self.assertIn("Configure backends", error) + def test_audiocpp_remote_missing_family_is_clone_capable(self): # A missing family is unknown — not guessed as qwen3_tts — so the # entry is clone-only: it needs a --voice rather than offering a diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py index 7821ebb..4ff70fb 100644 --- a/app/tests/test_tui.py +++ b/app/tests/test_tui.py @@ -781,6 +781,41 @@ class FormTests(TuiTestCase): result = tui.form(screen, "Settings", fields) self.assertEqual(result, {"fmt": "b"}) + def test_empty_static_choices_flash_hint_and_keep_form_open(self): + # A choice field with no options at all cannot be opened (menu() + # would raise): the on_empty_choices hint flashes instead and the + # form stays usable. + fields = [{"key": "fmt", "label": "Format", "kind": "choice", + "value": "", "choices": [], + "on_empty_choices": "nothing to pick — add some"}, + {"key": "chunk", "label": "Chunk", "kind": "text", + "value": "1"}] + # Enter flashes (the next key dismisses it), Tab -> Save, Enter. + screen = FakeScreen(keys=[10, ord("x"), 9, 10]) + result = tui.form(screen, "Settings", fields) + self.assertEqual(result, {"fmt": "", "chunk": "1"}) + texts = [text for _, _, text, _ in screen.strings] + self.assertTrue(any("nothing to pick" in text for text in texts)) + + def test_empty_callable_choices_flash_without_opening_menu(self): + # The regression this guards: a dynamic list that resolved empty + # used to crash form() with ValueError from menu(). A message may + # itself be a callable of the field list. + fields = [{"key": "voice", "label": "Voice", "kind": "choice", + "value": None, + "choices": lambda fs: [], + "on_empty_choices": + lambda fs: f"{len(fs)} fields but no voices"}] + # Enter opens nothing (the flash consumes the next key), then + # Tab -> Save, Enter. + screen = FakeScreen(keys=[10, ord("x"), 9, 10]) + with patch.object(tui, "menu", + side_effect=AssertionError("menu() was opened")): + result = tui.form(screen, "Convert", fields) + self.assertEqual(result, {"voice": None}) + texts = [text for _, _, text, _ in screen.strings] + self.assertTrue(any("no voices" in text for text in texts)) + def test_on_change_fires_after_value_change(self): calls = [] fields = [{"key": "fmt", "label": "Format", "kind": "choice", |
