Files
fckbot/tests/test_summarize.py
2026-06-30 10:36:00 +00:00

58 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
Тесты для модуля суммаризации документа.
"""
import pytest
from core.functions.summarize_document import summarize_document
@pytest.mark.asyncio
async def test_summarize_success(mock_giga, mock_bot_config):
"""
Тест: успешная суммаризация.
"""
mock_giga.chat.return_value = "Краткое содержание документа: ... [Суммаризация документа: test.docx]"
result = await summarize_document(
giga=mock_giga,
text="Длинный текст документа...",
title="test.docx",
prompt_text="Ты — эксперт по суммаризации...",
bot_config=mock_bot_config
)
assert "Краткое содержание" in result
@pytest.mark.asyncio
async def test_summarize_empty_prompt(mock_giga, mock_bot_config):
"""
Тест: при пустом промпте возвращается сообщение об ошибке.
"""
result = await summarize_document(
giga=mock_giga,
text="Текст",
title="doc.docx",
prompt_text="",
bot_config=mock_bot_config
)
assert "Не удалось загрузить промпт" in result
@pytest.mark.asyncio
async def test_summarize_long_text(mock_giga, mock_bot_config):
"""
Тест: текст обрезается до max_chars.
"""
mock_giga.chat.return_value = "Суммаризация..."
long_text = "a" * 10000 # 10 000 символов
result = await summarize_document(
giga=mock_giga,
text=long_text,
title="test.docx",
prompt_text="Ты — эксперт...",
bot_config=mock_bot_config
)
# Проверяем, что chat был вызван (значит, обрезка прошла без ошибок)
mock_giga.chat.assert_called_once()