refactor: extract chunk utils to domain/chunk_utils.py

- Extract safe_int, group_chunks_by_chapter, record_override_usage, chunk_text_for_tts
- Add tests/test_chunk_utils.py (15 tests)
- Update test_chunk_helpers.py and test_chunk_text_for_tts_prefers_raw.py imports
- conversion_runner.py: 1574 → 1518 lines
- All tests pass
This commit is contained in:
Artem Akymenko
2026-07-15 11:00:18 +00:00
parent a26e02b017
commit 1d7a2aeed6
5 changed files with 214 additions and 71 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
from abogen.webui.conversion_runner import _chunk_text_for_tts
from abogen.domain.chunk_utils import chunk_text_for_tts
def test_chunk_text_for_tts_prefers_text_over_normalized_text():
@@ -9,7 +9,7 @@ def test_chunk_text_for_tts_prefers_text_over_normalized_text():
"text": "Unfu*k",
}
assert _chunk_text_for_tts(entry) == "Unfu*k"
assert chunk_text_for_tts(entry) == "Unfu*k"
def test_chunk_text_for_tts_falls_back_to_original_text_then_normalized_text():
@@ -17,9 +17,9 @@ def test_chunk_text_for_tts_falls_back_to_original_text_then_normalized_text():
"original_text": "Hello * world",
"normalized_text": "Hello world",
}
assert _chunk_text_for_tts(entry) == "Hello * world"
assert chunk_text_for_tts(entry) == "Hello * world"
entry2 = {
"normalized_text": "Only normalized",
}
assert _chunk_text_for_tts(entry2) == "Only normalized"
assert chunk_text_for_tts(entry2) == "Only normalized"