aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_backends_audiocpp.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-26 18:39:33 -0400
committerhistoria <historiavg@proton.me>2026-08-26 18:39:33 -0400
commitdf95e7034df683c38fde67890430ab4c2abfa4ba (patch)
treef46d3eb393e605e82a4d058a2290061b77403649 /app/tests/test_backends_audiocpp.py
parent544486a374cd5cae7acce1302648d8dad079db48 (diff)
downloadtts-audiobook-generator-df95e7034df683c38fde67890430ab4c2abfa4ba.tar.gz
feat: in-place toggle field, updated transcription tui to use new field
Diffstat (limited to 'app/tests/test_backends_audiocpp.py')
-rw-r--r--app/tests/test_backends_audiocpp.py128
1 files changed, 103 insertions, 25 deletions
diff --git a/app/tests/test_backends_audiocpp.py b/app/tests/test_backends_audiocpp.py
index 37745f3..d364c06 100644
--- a/app/tests/test_backends_audiocpp.py
+++ b/app/tests/test_backends_audiocpp.py
@@ -792,31 +792,109 @@ class InstallModelsTests(unittest.TestCase):
self.checkout, [{"path": "models/higgs"}]))
-class TranscriptionChoicesTests(unittest.TestCase):
- """_transcription_choices: the renamed voice-transcripts options."""
-
- def test_fresh_directory_offers_the_renamed_all(self):
- choices, default = make_server.wizard._transcription_choices(
- [], {}, prompt_exists=False)
- self.assertEqual(default, "all")
- self.assertEqual(choices, [("Re-transcribe all", "all")])
-
- def test_existing_transcripts_offer_new_only_and_all(self):
- wavs = [Path("/x/narrator.wav"), Path("/x/new.wav")]
- choices, default = make_server.wizard._transcription_choices(
- wavs, {"narrator": "old transcript"}, prompt_exists=True)
- self.assertEqual(default, "missing")
- self.assertEqual([label for label, _mode in choices],
- ["Only transcribe new voices", "Re-transcribe all"])
-
- def test_complete_transcripts_offer_keep_and_all(self):
- wavs = [Path("/x/narrator.wav")]
- choices, default = make_server.wizard._transcription_choices(
- wavs, {"narrator": "old transcript"}, prompt_exists=True)
- self.assertEqual(default, "keep")
- self.assertEqual([label for label, _mode in choices],
- ["Keep the existing transcripts",
- "Re-transcribe all"])
+class ConfigFormTranscriptionToggleTests(unittest.TestCase):
+ """The combined form's Voice transcripts row: one fixed two-way toggle.
+
+ The row is always visible whenever a clone-capable family is hosted
+ (it must not hide itself just because the picked wav directory has no
+ .wavs yet), and the plan it produces follows the toggled mode.
+ """
+
+ def _checkout(self):
+ tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(tmp.cleanup)
+ return _make_checkout(Path(tmp.name))
+
+ def _empty_dir(self):
+ tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(tmp.cleanup)
+ return Path(tmp.name)
+
+ def _run(self, checkout, voices_dir, picked_family=None, override=None):
+ """Drive _wizard on CHECKOUT; return (form call capture, settings)."""
+ catalog = make_server.catalog.load_model_catalog(checkout)
+ family = picked_family or "qwen3_tts"
+ index = next(i for i, entry in enumerate(catalog)
+ if entry["family"] == family)
+ target = catalog[index]["packages"][0]["target_directory"]
+ captured = {}
+
+ def fake_form(stdscr, title, fields, **kwargs):
+ captured.update(kwargs)
+ captured["fields"] = fields
+ result = {f["key"]: f["value"] for f in fields}
+ if override:
+ result.update(override)
+ return result
+
+ with patch.object(make_server.build, "find_local_checkout",
+ return_value=checkout), \
+ patch.object(tui, "checkbox_tree",
+ return_value=[(index, target)]), \
+ patch.object(tui, "form", side_effect=fake_form), \
+ patch.object(make_server.wizard, "VOICES_DIR", voices_dir):
+ settings = make_server.wizard._wizard(
+ None, make_server.wizard.build_parser().parse_args([]),
+ make_server.wizard.build_parser())
+ return captured, settings
+
+ def test_row_is_a_fixed_toggle_defaulting_to_new_voices(self):
+ checkout = self._checkout()
+ captured, _settings = self._run(checkout, self._empty_dir())
+ by_key = {f["key"]: f for f in captured["fields"]}
+ row = by_key["transcription"]
+ self.assertEqual(row["kind"], "toggle")
+ self.assertEqual(row["value"], "missing")
+ self.assertEqual(
+ row["choices"],
+ [("Transcribe new voices", "missing"),
+ ("Re-transcribe all voices", "all")])
+
+ def test_row_always_visible_when_clone_capable(self):
+ # Regression: the row used to hide itself until the wav directory
+ # contained .wavs; a clone-capable pick must always offer it.
+ checkout = self._checkout()
+ voices = self._empty_dir()
+ captured, _settings = self._run(checkout, voices)
+ by_key = {f["key"]: f for f in captured["fields"]}
+ self.assertTrue(by_key["transcription"]["visible"](captured["fields"]))
+ self.assertEqual(_settings["plan"]["mode"], "missing")
+ self.assertEqual(_settings["plan"]["missing"], [])
+
+ def test_row_hidden_without_a_clone_capable_pick(self):
+ checkout = self._checkout()
+ captured, _settings = self._run(checkout, self._empty_dir(),
+ picked_family="supertonic")
+ by_key = {f["key"]: f for f in captured["fields"]}
+ self.assertFalse(by_key["transcription"]["visible"](captured["fields"]))
+ self.assertIsNone(_settings["plan"])
+
+ def test_form_opens_on_the_continue_button(self):
+ checkout = self._checkout()
+ captured, _settings = self._run(checkout, self._empty_dir())
+ self.assertTrue(captured.get("start_on_buttons"))
+
+ def test_new_voices_plan_carries_only_untranscribed_wavs(self):
+ checkout = self._checkout()
+ voices = self._empty_dir()
+ (voices / "extra.wav").write_bytes(b"x")
+ (voices / "narrator.wav").write_bytes(b"x")
+ common.write_prompt_text(voices, {"narrator": "Old words."})
+ _captured, settings = self._run(checkout, voices)
+ self.assertEqual(settings["plan"]["mode"], "missing")
+ self.assertEqual([w.name for w in settings["plan"]["missing"]],
+ ["extra.wav"])
+ self.assertEqual(settings["plan"]["existing"],
+ {"narrator": "Old words."})
+
+ def test_toggled_all_retranscribes_everything(self):
+ checkout = self._checkout()
+ voices = self._empty_dir()
+ (voices / "narrator.wav").write_bytes(b"x")
+ common.write_prompt_text(voices, {"narrator": "Old words."})
+ _captured, settings = self._run(checkout, voices,
+ override={"transcription": "all"})
+ self.assertEqual(settings["plan"]["mode"], "all")
class TranscribeWavDirTests(unittest.TestCase):