First Commit
This commit is contained in:
Executable
+85
@@ -0,0 +1,85 @@
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, "/home/marco/MonicaAgentIA/app")
|
||||
|
||||
os.environ["TELEGRAM_BOT_TOKEN"] = "test"
|
||||
os.environ["TELEGRAM_CHAT_ID"] = "123"
|
||||
|
||||
from monica_agent import _force_min_lines, _split_message_for_telegram, MAX_TELEGRAM_MESSAGE_LENGTH
|
||||
|
||||
def test_force_min_lines_no_truncation():
|
||||
print("=== Testando _force_min_lines nao trunca ===")
|
||||
text = "A. B. C. D. E. F. G. H. I. J."
|
||||
result = _force_min_lines(text, 5)
|
||||
assert "F." in result, f"Conteudo foi truncado! Resultado: {result}"
|
||||
assert "G." in result, f"Conteudo foi truncado! Resultado: {result}"
|
||||
assert "H." in result, f"Conteudo foi truncado! Resultado: {result}"
|
||||
assert "I." in result, f"Conteudo foi truncado! Resultado: {result}"
|
||||
assert "J." in result, f"Conteudo foi truncado! Resultado: {result}"
|
||||
print(f"✅ _force_min_lines preservou todo o conteudo")
|
||||
print(f" Resultado: {result}")
|
||||
|
||||
def test_force_min_lines_preserves_long_text():
|
||||
print("\n=== Testando _force_min_lines com texto longo ===")
|
||||
sentences = " ".join([f"Sentenca{i}." for i in range(1, 26)])
|
||||
result = _force_min_lines(sentences, 10)
|
||||
assert "Sentenca20." in result
|
||||
assert "Sentenca25." in result
|
||||
print("✅ _force_min_lines nao truncou texto longo")
|
||||
|
||||
def test_split_message_short():
|
||||
print("\n=== Testando _split_message_for_telegram mensagem curta ===")
|
||||
text = "Ola, tudo bem?"
|
||||
parts = _split_message_for_telegram(text)
|
||||
assert len(parts) == 1
|
||||
assert parts[0] == text
|
||||
print("✅ Mensagem curta nao foi dividida")
|
||||
|
||||
def test_split_message_exactly_at_limit():
|
||||
print("\n=== Testando _split_message_for_telegram no limite ===")
|
||||
text = "A" * MAX_TELEGRAM_MESSAGE_LENGTH
|
||||
parts = _split_message_for_telegram(text)
|
||||
assert len(parts) == 1
|
||||
assert len(parts[0]) == MAX_TELEGRAM_MESSAGE_LENGTH
|
||||
print(f"✅ Mensagem com {MAX_TELEGRAM_MESSAGE_LENGTH} chars nao foi dividida")
|
||||
|
||||
def test_split_message_long():
|
||||
print("\n=== Testando _split_message_for_telegram mensagem longa ===")
|
||||
paragraph = "Esta é uma fraselonga. " * 500
|
||||
text = paragraph + "\n\n" + paragraph
|
||||
parts = _split_message_for_telegram(text)
|
||||
assert len(parts) > 1
|
||||
for part in parts:
|
||||
assert len(part) <= MAX_TELEGRAM_MESSAGE_LENGTH, f"Parte muito longa: {len(part)}"
|
||||
print(f"✅ Mensagem longa dividida em {len(parts)} partes, todas <= {MAX_TELEGRAM_MESSAGE_LENGTH} chars")
|
||||
|
||||
def test_split_message_preserves_content():
|
||||
print("\n=== Testando _split_message_for_telegram preserva conteudo ===")
|
||||
text = "Paragrafo um.\n\nParagrafo dois.\n\nParagrafo tres."
|
||||
parts = _split_message_for_telegram(text)
|
||||
joined = "\n\n".join(parts)
|
||||
assert joined == text
|
||||
print("✅ Conteudo preservado apos split")
|
||||
|
||||
def test_split_message_very_long_single_paragraph():
|
||||
print("\n=== Testando _split_message_for_telegram paragrafo muito longo ===")
|
||||
text = "A. " * 5000
|
||||
parts = _split_message_for_telegram(text)
|
||||
assert len(parts) > 1
|
||||
for part in parts:
|
||||
assert len(part) <= MAX_TELEGRAM_MESSAGE_LENGTH
|
||||
print(f"✅ Paragrafo longo dividido em {len(parts)} partes")
|
||||
|
||||
def main():
|
||||
test_force_min_lines_no_truncation()
|
||||
test_force_min_lines_preserves_long_text()
|
||||
test_split_message_short()
|
||||
test_split_message_exactly_at_limit()
|
||||
test_split_message_long()
|
||||
test_split_message_preserves_content()
|
||||
test_split_message_very_long_single_paragraph()
|
||||
print("\n=== Todos os testes de correcao de resposta concluidos ===")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user