aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-20 22:39:04 +0000
committerhistoria <historiavg@proton.me>2026-08-20 23:02:09 +0000
commit0c197324f5444b448c285d2a57bd0a5834c2fc84 (patch)
tree494954b098cb3e74bb8c7c2bcc883ee971ebf574 /tests
parente4b42be01fc031810160126013833175413ec84c (diff)
downloadtts-audiobook-generator-0c197324f5444b448c285d2a57bd0a5834c2fc84.tar.gz
feat: warn on empty transcripts and missing whisper backend in server.json tool
Diffstat (limited to 'tests')
-rw-r--r--tests/test_make_audiocpp_server_json.py76
1 files changed, 73 insertions, 3 deletions
diff --git a/tests/test_make_audiocpp_server_json.py b/tests/test_make_audiocpp_server_json.py
index 63260ca..bdc3604 100644
--- a/tests/test_make_audiocpp_server_json.py
+++ b/tests/test_make_audiocpp_server_json.py
@@ -1,9 +1,11 @@
"""Tests for the audio.cpp server.json generator tool."""
+import io
import json
import sys
import tempfile
import unittest
+from contextlib import redirect_stdout
from pathlib import Path
from unittest.mock import MagicMock, patch
@@ -262,14 +264,16 @@ class MainTests(unittest.TestCase):
def tearDown(self):
self._tmp.cleanup()
- def _run(self, argv, inputs=None, transcribe=None):
+ def _run(self, argv, inputs=None, transcribe=None, whisper="faster_whisper"):
argv = ["make_audiocpp_server_json.py"] + argv
input_effect = inputs if inputs is not None else EOFError
transcribe_effect = transcribe if transcribe is not None else MagicMock()
with patch.object(sys, "argv", argv), \
patch("builtins.input", side_effect=input_effect), \
patch.object(make_server, "transcribe_reference_audio",
- side_effect=transcribe_effect):
+ side_effect=transcribe_effect), \
+ patch.object(make_server, "whisper_backend_available",
+ return_value=whisper):
return make_server.main()
def _defaults(self, models="", host="", port="", backend="",
@@ -448,10 +452,76 @@ class MainTests(unittest.TestCase):
def test_missing_positional_wav_dir_errors(self):
with self.assertRaises(SystemExit) as ctx:
self._run([str(self.folder / "nope"),
- "--output", str(self.output)],
+ "--output", str(self.output)],
inputs=self._defaults())
self.assertEqual(ctx.exception.code, 2)
+class TranscriptWarningTests(unittest.TestCase):
+ """Empty transcripts and a missing Whisper backend produce loud warnings."""
+
+ def setUp(self):
+ self._tmp = tempfile.TemporaryDirectory()
+ self.folder = Path(self._tmp.name)
+ self.output = self.folder / "server.json"
+ self.fake_config = self.folder / "config.py"
+ self.fake_config.write_text(FAKE_CONFIG, encoding="utf-8")
+ patcher = patch.object(make_server, "CONFIG_PATH", self.fake_config)
+ patcher.start()
+ self.addCleanup(patcher.stop)
+
+ def tearDown(self):
+ self._tmp.cleanup()
+
+ def _run_capturing(self, argv, inputs, transcribe, whisper):
+ argv = ["make_audiocpp_server_json.py"] + argv
+ buf = io.StringIO()
+ with patch.object(sys, "argv", argv), \
+ patch("builtins.input", side_effect=inputs), \
+ patch.object(make_server, "transcribe_reference_audio",
+ side_effect=transcribe), \
+ patch.object(make_server, "whisper_backend_available",
+ return_value=whisper), \
+ redirect_stdout(buf):
+ code = make_server.main()
+ return code, buf.getvalue()
+
+ def test_empty_transcript_prints_loud_end_warning(self):
+ (self.folder / "narrator.wav").write_bytes(b"x")
+ (self.folder / "alpha.wav").write_bytes(b"x")
+ # Clone-only run (menu choice 3); transcribe returns None (empty).
+ code, out = self._run_capturing(
+ [str(self.folder), "--output", str(self.output)],
+ inputs=["3", "", "", "", "", "", "y"],
+ transcribe=lambda path, model_name="base": None,
+ whisper="faster_whisper")
+ self.assertEqual(code, 0)
+ self.assertIn("MANUAL TRANSCRIPTION REQUIRED", out)
+ self.assertIn("narrator", out)
+ self.assertIn("alpha", out)
+ self.assertIn("will NOT work", out)
+
+ def test_missing_whisper_backend_prints_conda_warning(self):
+ (self.folder / "narrator.wav").write_bytes(b"x")
+ code, out = self._run_capturing(
+ [str(self.folder), "--output", str(self.output)],
+ inputs=["3", "", "", "", "", "", "y"],
+ transcribe=lambda path, model_name="base": "a transcript",
+ whisper=None)
+ self.assertEqual(code, 0)
+ self.assertIn("conda activate qwen3-tts", out)
+ self.assertIn("faster_whisper", out)
+
+ def test_all_transcripts_present_prints_no_end_warning(self):
+ (self.folder / "narrator.wav").write_bytes(b"x")
+ code, out = self._run_capturing(
+ [str(self.folder), "--output", str(self.output)],
+ inputs=["3", "", "", "", "", "", "y"],
+ transcribe=lambda path, model_name="base": "a real transcript",
+ whisper="faster_whisper")
+ self.assertEqual(code, 0)
+ self.assertNotIn("MANUAL TRANSCRIPTION REQUIRED", out)
+
+
if __name__ == "__main__":
unittest.main()