Files
fckbot/core/tests/conftest.py
Markov Andrey 73bca26e7c Add new file
2026-06-30 09:20:57 +00:00

69 lines
2.3 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 -*-
"""
Фикстуры для тестов: моки для 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}
РАСШИРЕННЫЙ ЗАПРОС:
"""