diff options
| author | historia <historiavg@proton.me> | 2026-08-21 00:15:57 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-21 00:15:57 -0400 |
| commit | fea9222740da007f1d7befcd7dee035265c0e5d1 (patch) | |
| tree | 8ae6a1305940ec94f6f495aa59c5cdc95cd803dd /tests | |
| parent | 0017f6b0421e549e9a2cdfadc104be64433724d3 (diff) | |
| download | tts-audiobook-generator-fea9222740da007f1d7befcd7dee035265c0e5d1.tar.gz | |
feat: exit script if any chunk fails
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_converter.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_converter.py b/tests/test_converter.py index d525c18..e7c0776 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -258,6 +258,20 @@ class DebugDumpTests(unittest.TestCase): results = self.converter._synthesize_chunks(["Hello."], debug_dir=blocker / "book") self.assertEqual(results, {1: audio}) + def test_failed_chunk_stops_remaining_chunks(self): + audio = self._chunk_source("chunk_0001.wav") + self.converter.tts.process_chunk_with_retry.side_effect = [audio, None, audio] + results = self.converter._synthesize_chunks(["One.", "Two.", "Three."]) + self.assertEqual(results, {1: audio, 2: None}) + self.assertEqual(self.converter.tts.process_chunk_with_retry.call_count, 2) + + def test_raising_chunk_stops_remaining_chunks(self): + audio = self._chunk_source("chunk_0001.wav") + self.converter.tts.process_chunk_with_retry.side_effect = [audio, RuntimeError("boom")] + results = self.converter._synthesize_chunks(["One.", "Two.", "Three."]) + self.assertEqual(results, {1: audio, 2: None}) + self.assertEqual(self.converter.tts.process_chunk_with_retry.call_count, 2) + def test_debug_flag_wiring(self): with patch("converter.converter.QwenTTSClient"): self.assertFalse(AudiobookConverter().debug) @@ -411,6 +425,16 @@ class ServerSideChunkingOutputTests(unittest.TestCase): self.assertNotIn("single request", out) self.assertIn("Chapter 2/5 converted (1/1 chunks)", out) + def test_partial_chunks_abort_without_assembling(self): + converter = self._converter(client_chunks=True) + converter.tts.process_chunk_with_retry.side_effect = ["chunk_0001.wav", None] + text = " ".join(f"word{i}" for i in range(8)) + with patch.object(config, "CHUNK_SIZE", 5), \ + patch.object(converter_mod.audio, "combine_chunks") as mock_combine: + ok = converter._convert_text(text, Path("out.mp3"), time.time()) + self.assertFalse(ok) + mock_combine.assert_not_called() + class PromptOverwriteTests(unittest.TestCase): def test_single_file_yes(self): |
