aboutsummaryrefslogtreecommitdiff
path: root/tests/test_chunking.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_chunking.py')
-rw-r--r--tests/test_chunking.py48
1 files changed, 23 insertions, 25 deletions
diff --git a/tests/test_chunking.py b/tests/test_chunking.py
index 7f37f80..3cd926b 100644
--- a/tests/test_chunking.py
+++ b/tests/test_chunking.py
@@ -4,42 +4,41 @@ import unittest
from unittest.mock import patch
from converter import config
-from converter.chunking import MAX_REQUEST_WORDS, split_into_chunks
+from converter.chunking import split_into_chunks
class ChunkSizeDefaultTests(unittest.TestCase):
- """Guard the request-size settings: each API call is one model
- generation, and the servers silently truncate audio past their caps
- (~2.5 min faster backend, ~11 min Gradio demo), so both the default
- chunk size and the hard ceiling must stay well inside that budget."""
+ """Guard the request-size setting: each API call is one model
+ generation, and the servers silently truncate audio when a single
+ generation runs too long (~2.5 min faster backend, ~11 min Gradio
+ demo), so the default chunk size must stay well inside that budget.
+ There is no hard ceiling beyond CHUNK_SIZE; users raising it accept
+ the truncation risk themselves."""
- def test_default_chunk_size_within_request_ceiling(self):
- self.assertLessEqual(config.CHUNK_SIZE, MAX_REQUEST_WORDS)
+ def test_default_chunk_size_within_single_generation_budget(self):
+ self.assertLessEqual(config.CHUNK_SIZE, 300)
- def test_request_ceiling_within_single_generation_budget(self):
- self.assertLessEqual(MAX_REQUEST_WORDS, 300)
-
- def test_sizes_are_positive(self):
+ def test_default_chunk_size_is_positive(self):
self.assertGreaterEqual(config.CHUNK_SIZE, 1)
- self.assertGreaterEqual(MAX_REQUEST_WORDS, 1)
-class RequestCeilingClampTests(unittest.TestCase):
- def test_oversized_chunk_size_is_clamped_with_warning(self):
+class RequestSizeTests(unittest.TestCase):
+ def test_oversized_chunk_size_is_honored(self):
+ # No clamping: whatever size is configured (or requested) is used.
text = " ".join(f"word{i}" for i in range(30)) + "."
- with patch("converter.chunking.MAX_REQUEST_WORDS", 10), \
- self.assertLogs("converter.chunking", level="WARNING") as logs:
- chunks = split_into_chunks(text, max_words=5000)
- self.assertTrue(all(len(chunk.split()) <= 10 for chunk in chunks))
- self.assertIn("clamped", " ".join(logs.output))
+ chunks = split_into_chunks(text, max_words=5000)
+ self.assertEqual(len(chunks), 1)
+ self.assertEqual(len(chunks[0].split()), 30)
- def test_default_ceiling_clamps_realistic_configuration(self):
+ def test_default_uses_runtime_config_chunk_size(self):
+ # The default resolves config.CHUNK_SIZE at call time, so
+ # patching the config changes the default split size.
sentences = " ".join(
f"S{i} " + " ".join(["word"] * 8) + "." for i in range(60))
- chunks = split_into_chunks(sentences, max_words=5000)
+ with patch.object(config, "CHUNK_SIZE", 120):
+ chunks = split_into_chunks(sentences)
self.assertGreater(len(chunks), 1)
- self.assertTrue(all(len(chunk.split()) <= MAX_REQUEST_WORDS
- for chunk in chunks))
+ self.assertTrue(all(len(chunk.split()) <= 120 for chunk in chunks))
class SplitIntoChunksTests(unittest.TestCase):
@@ -94,8 +93,7 @@ class SplitIntoChunksTests(unittest.TestCase):
def test_single_oversized_sentence_is_word_split(self):
# A punctuation-free sentence longer than the limit is split at word
- # boundaries: the request-size ceiling is a hard limit because the
- # TTS servers silently truncate oversized generations.
+ # boundaries so no single request exceeds the configured size.
sentence = " ".join(["word"] * 30) + "."
chunks = split_into_chunks(sentence, max_words=10)
self.assertGreater(len(chunks), 1)