/
pickling
/
mcp-sourcecontrol-python
Обзор
Документация
Войти
/
pickling
/
mcp-sourcecontrol-python
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/conftest.py
68 строк
2 KB
pickling-21
Python-порт mcp-sourcecontrol: 20 инструментов, stdio и Streamable HTTP
29 июл 2026, 02:18
29 июл 2026, 02:18
bc8bde4
Код
Авторство
О чём код?
"""Общие фикстуры и помощники. Аналог tests/setup.ts + tests/test-helpers.ts.""" from __future__ import annotations import json import httpx import pytest import mcp_sourcecontrol.config as config_module import mcp_sourcecontrol.runtime as runtime from mcp_sourcecontrol.config import ResolvedConfig from mcp_sourcecontrol.log import logger TEST_CONFIG = ResolvedConfig( api_url="https://api.sc-ci.sber.ru/sc/api/v3", tenant_id="test-tenant-id", token="test-token", log_level="error", tls_reject_unauthorized=False, ) @pytest.fixture(autouse=True) def _quiet_logs_and_clean_runtime(): """Подавляет логи и сбрасывает runtime-состояние между тестами.""" logger.set_level("error") yield runtime.set_transport_override(None) runtime._default_config = None @pytest.fixture def no_tenants(monkeypatch, tmp_path): """tenants.json отсутствует.""" monkeypatch.setattr(config_module, "_candidate_paths", lambda: [tmp_path / "missing.json"]) @pytest.fixture def tenants_file(monkeypatch, tmp_path): """Пишет данные во временный tenants.json и подключает его к config.""" def write(data) -> None: path = tmp_path / "tenants.json" path.write_text(data if isinstance(data, str) else json.dumps(data), encoding="utf-8") monkeypatch.setattr(config_module, "_candidate_paths", lambda: [path]) return write def make_mock_transport(*responses: httpx.Response) -> tuple[httpx.MockTransport, list[httpx.Request]]: """MockTransport, отдающий ответы по очереди и записывающий запросы.""" captured: list[httpx.Request] = [] queue = list(responses) def handler(request: httpx.Request) -> httpx.Response: captured.append(request) return queue.pop(0) if len(queue) > 1 else queue[0] return httpx.MockTransport(handler), captured def json_response(status: int, body) -> httpx.Response: return httpx.Response(status, json=body) def text_response(status: int, body: str) -> httpx.Response: return httpx.Response(status, text=body, headers={"Content-Type": "text/plain"})