aboutsummaryrefslogtreecommitdiff
path: root/app/tests
diff options
context:
space:
mode:
Diffstat (limited to 'app/tests')
-rw-r--r--app/tests/test_tts.py58
1 files changed, 32 insertions, 26 deletions
diff --git a/app/tests/test_tts.py b/app/tests/test_tts.py
index c17609b..02b7dc4 100644
--- a/app/tests/test_tts.py
+++ b/app/tests/test_tts.py
@@ -339,18 +339,20 @@ class FasterTTSClientGenerateTests(unittest.TestCase):
remaining = sorted(path.name for path in Path(self._tmp.name).glob("chunk_0001.*"))
self.assertEqual(remaining, ["chunk_0001.wav"])
- def test_transient_failure_is_retried(self):
+ def test_transient_failure_fails_the_chunk_attempt(self):
+ # Retrying is the chunk-level policy's job
+ # (process_chunk_with_retry); one generate_chunk call makes one
+ # request attempt per sub-chunk.
client = self._make_client()
pcm = b"\x01\x00" * 10
with patch.object(client, "_request_pcm",
side_effect=[RuntimeError("boom"), pcm]) as mock_pcm:
result = client.generate_chunk("Hello.", 1)
- self.assertIsNotNone(result)
- self.assertEqual(mock_pcm.call_count, 2)
+ self.assertIsNone(result)
+ self.assertEqual(mock_pcm.call_count, 1)
- def test_empty_pcm_response_is_treated_as_failure(self):
+ def test_empty_pcm_response_fails_the_chunk(self):
client = self._make_client()
- pcm = b"\x01\x00" * 10
def _response(body):
response = MagicMock()
@@ -359,20 +361,18 @@ class FasterTTSClientGenerateTests(unittest.TestCase):
return response
with patch("converter.tts.urllib.request.urlopen",
- side_effect=[_response(b""), _response(pcm)]) as mock_urlopen:
+ side_effect=[_response(b"")]) as mock_urlopen:
result = client.generate_chunk("Hello.", 1)
- self.assertIsNotNone(result)
- self.assertEqual(mock_urlopen.call_count, 2)
- _, _, _, frames = self._read_wav(Path(result))
- self.assertEqual(frames, pcm)
+ self.assertIsNone(result)
+ self.assertEqual(mock_urlopen.call_count, 1)
- def test_exhausted_subchunk_retries_fail_the_chunk(self):
+ def test_subchunk_request_failure_fails_the_chunk(self):
client = self._make_client()
with patch.object(client, "_request_pcm",
side_effect=RuntimeError("down")) as mock_pcm:
result = client.generate_chunk("Hello.", 1)
self.assertIsNone(result)
- self.assertEqual(mock_pcm.call_count, config.MAX_RETRIES)
+ self.assertEqual(mock_pcm.call_count, 1)
def test_empty_text_fails_the_chunk(self):
client = self._make_client()
@@ -1289,22 +1289,25 @@ class AudioCppTTSClientRequestTests(unittest.TestCase):
self.assertIn("500", str(ctx.exception))
self.assertIn("bad voice", str(ctx.exception))
- def test_transient_failure_is_retried(self):
+ def test_transient_failure_fails_the_chunk_attempt(self):
+ # Retrying is the chunk-level policy's job
+ # (process_chunk_with_retry); one generate_chunk call makes one
+ # request attempt per sub-chunk.
client = self._make_client()
wav = self._wav_bytes()
with patch.object(client, "_request_wav",
side_effect=[RuntimeError("boom"), wav]) as mock_request:
result = client.generate_chunk("Hello.", 1)
- self.assertIsNotNone(result)
- self.assertEqual(mock_request.call_count, 2)
+ self.assertIsNone(result)
+ self.assertEqual(mock_request.call_count, 1)
- def test_exhausted_retries_fail_the_chunk(self):
+ def test_request_failure_fails_the_chunk(self):
client = self._make_client()
with patch.object(client, "_request_wav",
side_effect=RuntimeError("down")) as mock_request:
result = client.generate_chunk("Hello.", 1)
self.assertIsNone(result)
- self.assertEqual(mock_request.call_count, config.MAX_RETRIES)
+ self.assertEqual(mock_request.call_count, 1)
def test_empty_text_fails_the_chunk(self):
client = self._make_client()
@@ -1396,7 +1399,7 @@ class AudioCppHeartbeatTests(unittest.TestCase):
buf = io.StringIO()
with patch.object(config, "HEARTBEAT_INTERVAL_SECONDS", 0.03), \
- patch.object(client, "_request_wav_with_retry",
+ patch.object(client, "_request_wav",
side_effect=slow_request), \
redirect_stdout(buf):
result = client.generate_chunk("Hello.", 1)
@@ -1591,7 +1594,8 @@ class BackendWiringTests(unittest.TestCase):
patch("converter.converter.AudioCppTTSClient") as mock_audiocpp:
AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE,
backend=tts.BACKEND_FASTER, voice="narrator")
- mock_faster.assert_called_once_with(voice="narrator", api_url=None)
+ mock_faster.assert_called_once_with(voice="narrator", api_url=None,
+ quiet=False)
mock_qwen.assert_not_called()
mock_audiocpp.assert_not_called()
@@ -1606,7 +1610,7 @@ class BackendWiringTests(unittest.TestCase):
model_id=None,
instructions=None,
request_options={},
- api_url=None)
+ api_url=None, quiet=False)
mock_faster.assert_not_called()
mock_qwen.assert_not_called()
@@ -1618,7 +1622,7 @@ class BackendWiringTests(unittest.TestCase):
model_id=None,
instructions=None,
request_options={},
- api_url=None)
+ api_url=None, quiet=False)
def test_audiocpp_backend_model_id_is_wired_through(self):
with patch("converter.converter.AudioCppTTSClient") as mock_audiocpp:
@@ -1628,7 +1632,7 @@ class BackendWiringTests(unittest.TestCase):
mock_audiocpp.assert_called_once_with(
voice="narrator", language=config.LANGUAGE,
model_id="higgs", instructions=None,
- request_options={}, api_url=None)
+ request_options={}, api_url=None, quiet=False)
def test_audiocpp_backend_instructions_and_options_are_wired_through(self):
with patch("converter.converter.AudioCppTTSClient") as mock_audiocpp:
@@ -1642,7 +1646,7 @@ class BackendWiringTests(unittest.TestCase):
model_id=None,
instructions="A warm adult narrator",
request_options={"emotion": "neutral", "speed": "1.1"},
- api_url=None)
+ api_url=None, quiet=False)
def test_qwen_backend_uses_qwen_client(self):
with patch("converter.converter.FasterTTSClient") as mock_faster, \
@@ -1669,13 +1673,14 @@ class BackendWiringTests(unittest.TestCase):
mock_audiocpp.assert_called_once_with(
voice="narrator", language=config.LANGUAGE, model_id=None,
instructions=None, request_options={},
- api_url="http://10.0.0.5:8080")
+ api_url="http://10.0.0.5:8080", quiet=False)
with patch("converter.converter.FasterTTSClient") as mock_faster:
AudiobookConverter(voice_mode=tts.VOICE_MODE_CLONE,
backend=tts.BACKEND_FASTER, voice="narrator",
api_url="http://10.0.0.5:8000")
mock_faster.assert_called_once_with(voice="narrator",
- api_url="http://10.0.0.5:8000")
+ api_url="http://10.0.0.5:8000",
+ quiet=False)
with patch("converter.converter.QwenTTSClient") as mock_qwen:
AudiobookConverter(voice_mode=tts.VOICE_MODE_CUSTOM,
backend=tts.BACKEND_QWEN,
@@ -1683,7 +1688,8 @@ class BackendWiringTests(unittest.TestCase):
mock_qwen.assert_called_once_with(
voice_mode=tts.VOICE_MODE_CUSTOM, voice_clone_ref_audio=None,
voice_clone_ref_text=None, skip_transcription=False,
- language=config.LANGUAGE, api_url="http://10.0.0.5:7860")
+ language=config.LANGUAGE, api_url="http://10.0.0.5:7860",
+ quiet=False)
def test_audiocpp_clone_mode_does_not_require_reference(self):
# Cloning is server-side for the audiocpp backend, so the