diff --git a/core/tests/test_critique.py b/core/tests/test_critique.py new file mode 100644 index 0000000..a77dd37 --- /dev/null +++ b/core/tests/test_critique.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +""" +Тесты для модуля самокритики. +""" + +import pytest +from core.functions.critique_answer import critique_answer + + +@pytest.mark.asyncio +async def test_critique_ok(mock_giga, mock_bot_config): + """ + Тест: если ответ хороший, возвращается True. + """ + mock_giga.chat.return_value = "[OK]" + + result = await critique_answer( + giga=mock_giga, + query="Какой OEE?", + context="OEE 85%", + answer="OEE 85%", + prompt_text="Ты — контролёр качества...", + bot_config=mock_bot_config + ) + assert result is True + + +@pytest.mark.asyncio +async def test_critique_fail(mock_giga, mock_bot_config): + """ + Тест: если есть замечания, возвращается False. + """ + mock_giga.chat.return_value = "[ISSUES]\n- Галлюцинация\n[/ISSUES]" + + result = await critique_answer( + giga=mock_giga, + query="Какой OEE?", + context="OEE 85%", + answer="OEE 90%", + prompt_text="Ты — контролёр качества...", + bot_config=mock_bot_config + ) + assert result is False + + +@pytest.mark.asyncio +async def test_critique_empty_prompt(mock_giga, mock_bot_config): + """ + Тест: если промпт пуст, пропускаем критику (возвращаем True). + """ + result = await critique_answer( + giga=mock_giga, + query="Вопрос", + context="Контекст", + answer="Ответ", + prompt_text="", + bot_config=mock_bot_config + ) + assert result is True + mock_giga.chat.assert_not_called() \ No newline at end of file