Files
voiceagent/tests/test_text_chunker.py

59 lines
1.2 KiB
Python

from voice_assistant.agent.text_chunker import TextChunker
def test_chunker_emits_sentence():
chunker = TextChunker(min_chars=5)
assert chunker.feed("Olá, tudo bem?") == [
"Olá, tudo bem?"
]
def test_chunker_handles_incremental_deltas():
chunker = TextChunker(min_chars=5)
assert chunker.feed("Olá,") == []
assert chunker.feed(" tudo") == []
assert chunker.feed(" bem?") == [
"Olá, tudo bem?"
]
def test_chunker_preserves_remaining_text():
chunker = TextChunker(min_chars=5)
assert chunker.feed("Olá, tudo bem? Posso ajudar") == [
"Olá, tudo bem?"
]
assert chunker.flush() == "Posso ajudar"
def test_chunker_breaks_long_text():
chunker = TextChunker(
min_chars=5,
max_chars=20,
)
segments = chunker.feed(
"Esta é uma frase bastante longa sem pontuação"
)
assert segments
assert all(
len(segment) <= 20
for segment in segments
)
def test_chunker_rejects_invalid_limits():
try:
TextChunker(min_chars=20, max_chars=10)
except ValueError:
pass
else:
raise AssertionError(
"Expected ValueError for invalid limits."
)