diff --git a/core/tests/conftest.py b/core/tests/conftest.py new file mode 100644 index 0000000..727e44f --- /dev/null +++ b/core/tests/conftest.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +""" +Фикстуры для тестов: моки для GigaClient, BotConfig, и других зависимостей. +Автоматически очищает глобальные кэши (intent, expand) перед каждым тестом. +""" + +import pytest +from unittest.mock import AsyncMock, MagicMock + +from core.services.giga_client import GigaClient +from core.utils.config_loader import BotConfig + + +@pytest.fixture(autouse=True) +def clear_caches(): + """ + Автоматически очищает глобальные кэши перед каждым тестом, + чтобы избежать влияния между тестами. + """ + from core.functions.intent_classify import _intent_cache + from core.functions.expand_query import _expand_cache + _intent_cache.clear() + _expand_cache.clear() + + +@pytest.fixture +def mock_giga(): + """Создаёт мок GigaClient с подменой метода chat().""" + giga = AsyncMock(spec=GigaClient) + # По умолчанию chat возвращает строку + giga.chat = AsyncMock(return_value="GENERAL") + return giga + + +@pytest.fixture +def mock_bot_config(): + """Создаёт мок BotConfig с минимальными настройками.""" + config = MagicMock(spec=BotConfig) + # Подсекции + config.intent = {"temperature": 0.1} + config.expand = {"temperature": 0.1} + config.metrics = {"temperature": 0.1} + config.summary = {"temperature": 0.1, "max_chars": 8000} + config.consistency = {"temperature": 0.1, "max_fragments": 5} + config.critique = {"temperature": 0.1} + config.rerank = {"temperature": 0.1, "min_length": 5000} + config.spellcheck = {"temperature": 0.1} + return config + + +@pytest.fixture +def sample_prompt_intent(): + """Возвращает содержимое intent_classify.txt для тестов.""" + return """ + Ты — классификатор намерений... + КОДЫ НАМЕРЕНИЙ: + - `FACT` ... + ВОПРОС: {query} + """ + + +@pytest.fixture +def sample_prompt_expand(): + """Возвращает содержимое expand.txt для тестов.""" + return """ + Ты — эксперт по информационному поиску... + ВОПРОС: {query} + РАСШИРЕННЫЙ ЗАПРОС: + """ \ No newline at end of file