From 4b420d18ed8290354ffce18784cc655d4497b289 Mon Sep 17 00:00:00 2001 From: Markov Andrey Date: Tue, 30 Jun 2026 09:22:14 +0000 Subject: [PATCH] Add new file --- core/tests/test_critique.py | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core/tests/test_critique.py 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