/
pickling
/
mcp-sourcecontrol-python
Обзор
Документация
Войти
/
pickling
/
mcp-sourcecontrol-python
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/test_formatting.py
50 строк
2 KB
pickling-21
Python-порт mcp-sourcecontrol: 20 инструментов, stdio и Streamable HTTP
29 июл 2026, 02:18
29 июл 2026, 02:18
bc8bde4
Код
Авторство
О чём код?
"""Порт тестов src/tools/formatting.ts (усечение и пагинация).""" from __future__ import annotations from mcp_sourcecontrol.tools.formatting import format_paginated_response, to_json, truncate_response class TestToJson: def test_compact_like_json_stringify(self): assert to_json({"a": 1, "b": [1, 2]}) == '{"a":1,"b":[1,2]}' def test_keeps_unicode(self): assert to_json({"msg": "привет"}) == '{"msg":"привет"}' class TestTruncateResponse: def test_short_text_unchanged(self): assert truncate_response("short", 100) == "short" def test_truncates_at_line_boundary_with_marker(self): text = "line1\nline2\nline3-very-long-tail" result = truncate_response(text, 14) assert result.startswith("line1\nline2") assert "TRUNCATED" in result assert f"/{len(text)} chars shown" in result def test_truncates_without_newline(self): result = truncate_response("x" * 200, 50) assert result.startswith("x" * 50) assert "[TRUNCATED: 50/200 chars shown]" in result class TestFormatPaginatedResponse: def test_maps_values_shape(self): raw = {"values": [1, 2], "page": 2, "isLastPage": False, "total": 10} result = format_paginated_response(raw, lambda x: x * 10) assert result == {"data": [10, 20], "page": 2, "isLastPage": False, "total": 10} def test_maps_data_shape(self): result = format_paginated_response({"data": [1]}, lambda x: x) assert result == {"data": [1], "page": 1, "isLastPage": True} def test_empty_values_do_not_fall_through_to_data(self): # values ?? data: пустой values не должен подменяться data result = format_paginated_response({"values": [], "data": [1, 2]}, lambda x: x) assert result["data"] == [] def test_defaults_page_to_current_page(self): result = format_paginated_response({}, lambda x: x, current_page=5) assert result == {"data": [], "page": 5, "isLastPage": True}