aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_backends_faster.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/tests/test_backends_faster.py')
-rw-r--r--app/tests/test_backends_faster.py94
1 files changed, 40 insertions, 54 deletions
diff --git a/app/tests/test_backends_faster.py b/app/tests/test_backends_faster.py
index c03f031..a093fbe 100644
--- a/app/tests/test_backends_faster.py
+++ b/app/tests/test_backends_faster.py
@@ -110,8 +110,8 @@ class LoadVoicesTests(unittest.TestCase):
self.assertEqual(make_voices.load_voices(self.path), {})
-class DecideFasterTranscriptionTests(unittest.TestCase):
- """_decide_faster_transcription: the re-transcribe plan questions."""
+class PlanForTests(unittest.TestCase):
+ """_plan_for: execution plans for the wizard's transcription toggle."""
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
@@ -124,59 +124,18 @@ class DecideFasterTranscriptionTests(unittest.TestCase):
def tearDown(self):
self._tmp.cleanup()
- def test_new_voices_default_to_missing_mode(self):
- choices, default = make_voices._decide_faster_transcription(
- [self.narrator, self.new_voice],
- {"narrator": {"ref_text": "old"}})
- self.assertEqual(default, "missing")
- modes = [mode for _label, mode in choices]
- self.assertIn("missing", modes)
- self.assertIn("all", modes)
- missing = [w for w in (self.narrator, self.new_voice)
- if w.stem not in {"narrator"}]
+ def test_missing_plan_carries_only_unlisted_wavs(self):
plan = make_voices._plan_for("missing", self.folder,
{"narrator": {"ref_text": "old"}})
self.assertEqual(plan["mode"], "missing")
- self.assertEqual([w.name for w in plan["missing"]],
- [w.name for w in missing])
-
- def test_declining_new_voices_transcribes_all(self):
- choices, default = make_voices._decide_faster_transcription(
- [self.narrator, self.new_voice],
- {"narrator": {"ref_text": "old"}})
- # Re-transcribing everything stays available alongside new-only.
- modes = [mode for _label, mode in choices]
- self.assertIn("all", modes)
- plan = make_voices._plan_for("all", self.folder,
- {"narrator": {"ref_text": "old"}})
- self.assertEqual(plan["mode"], "all")
-
- def test_no_new_voices_offers_retranscribe_default_keep(self):
- choices, default = make_voices._decide_faster_transcription(
- [self.narrator], {"narrator": {"ref_text": "old"}})
- self.assertEqual(default, "keep")
- modes = [mode for _label, mode in choices]
- self.assertEqual(modes, ["keep", "all"])
+ self.assertEqual([w.name for w in plan["missing"]], ["new.wav"])
+ self.assertEqual(plan["existing"], {"narrator": {"ref_text": "old"}})
- def test_no_new_voices_can_retranscribe_all(self):
- _choices, _default = make_voices._decide_faster_transcription(
- [self.narrator], {"narrator": {"ref_text": "old"}})
+ def test_all_plan_names_the_mode(self):
plan = make_voices._plan_for("all", self.folder,
{"narrator": {"ref_text": "old"}})
self.assertEqual(plan["mode"], "all")
-
- def test_choice_labels_are_the_renamed_ones(self):
- # The option names shown for the Voice-transcripts choice.
- with_new, _ = make_voices._decide_faster_transcription(
- [self.narrator, self.new_voice],
- {"narrator": {"ref_text": "old"}})
- self.assertEqual([label for label, _mode in with_new],
- ["Only transcribe new voices", "Re-transcribe all"])
- without_new, _ = make_voices._decide_faster_transcription(
- [self.narrator], {"narrator": {"ref_text": "old"}})
- self.assertEqual([label for label, _mode in without_new],
- ["Keep the existing voices.json",
- "Re-transcribe all"])
+ self.assertEqual(plan["missing"], [])
class MainTests(unittest.TestCase):
@@ -333,7 +292,7 @@ class WizardFormTests(unittest.TestCase):
# no keep/new-only choice exists.
self.assertEqual(settings["plan"]["mode"], "all")
- def test_modify_run_offers_transcription_modes(self):
+ def test_modify_run_offers_transcription_toggle(self):
folder = self._wavs()
(folder / "new.wav").write_bytes(b"x") # a voice not in voices.json
output = folder / "voices.json"
@@ -347,11 +306,14 @@ class WizardFormTests(unittest.TestCase):
captured["keys"] = [f["key"] for f in fields]
by_key = {f["key"]: f for f in fields}
self.assertIn("transcription", by_key)
- modes = [mode for _label, mode in by_key[
- "transcription"]["choices"](fields)]
- # New .wavs exist, so both transcribing only those and
- # re-transcribing everything are offered.
- self.assertEqual(modes, ["missing", "all"])
+ # A plain in-place toggle (no popup): fixed choices, new-only.
+ 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")])
result = {f["key"]: f["value"] for f in fields}
result["transcription"] = "missing"
return result
@@ -372,6 +334,30 @@ class WizardFormTests(unittest.TestCase):
["new.wav"])
self.assertEqual(settings["wav_dir"], folder)
+ def test_modify_run_toggled_all_retranscribes_everything(self):
+ folder = self._wavs()
+ (folder / "new.wav").write_bytes(b"x")
+ output = folder / "voices.json"
+ existing = {"narrator": {
+ "ref_audio": str(folder / "narrator.wav"),
+ "ref_text": "old transcript", "language": "English"}}
+ output.write_text(json.dumps(existing), encoding="utf-8")
+
+ def fake_form(stdscr, title, fields, **kwargs):
+ result = {f["key"]: f["value"] for f in fields}
+ result["transcription"] = "all"
+ return result
+
+ with patch.object(make_voices, "_is_installed", return_value=True), \
+ patch.object(make_voices, "_is_cloned", return_value=True), \
+ patch.object(make_voices.tui, "form",
+ side_effect=fake_form):
+ settings = make_voices._wizard(
+ None, self._args("--output", str(output),
+ "--skip-install", "--skip-clone"))
+ self.assertIsNotNone(settings)
+ self.assertEqual(settings["plan"]["mode"], "all")
+
def test_cancel_aborts(self):
with patch.object(make_voices, "_is_installed", return_value=True), \
patch.object(make_voices, "_is_cloned", return_value=True), \