conftest.py•2.8 kB
"""Pytest configuration and fixtures."""
import pytest
import asyncio
from unittest.mock import AsyncMock, MagicMock, patch
@pytest.fixture
def mock_copyq_client():
"""Create a mock CopyQ client for testing without real CopyQ."""
with patch("mcp_copyq.copyq_client.client") as mock_client:
# Setup default return values
mock_client.list_tabs = AsyncMock(return_value=[
"mcp/info",
"mcp/заметки",
"mcp/workspace",
"mcp/workspace/project1",
])
mock_client.tab_exists = AsyncMock(return_value=True)
mock_client.get_count = AsyncMock(return_value=5)
mock_client.create_tab = AsyncMock()
mock_client.remove_tab = AsyncMock()
mock_client.read_text = AsyncMock(return_value="Sample text content")
mock_client.read_tags = AsyncMock(return_value=["tag1", "tag2"])
mock_client.read_note = AsyncMock(return_value="Sample note")
mock_client.has_note = AsyncMock(return_value=True)
mock_client.read_item_full = AsyncMock(return_value={
"index": 0,
"text": "Sample text content",
"tags": ["tag1", "tag2"],
"note": "Sample note",
})
mock_client.read_item_preview = AsyncMock(return_value={
"index": 0,
"text_preview": "Sample text content",
"tags": ["tag1", "tag2"],
"has_note": True,
})
mock_client.write_item = AsyncMock()
mock_client.add_item = AsyncMock(return_value=0)
mock_client.remove_item = AsyncMock()
mock_client.update_text = AsyncMock()
mock_client.update_tags = AsyncMock()
mock_client.update_note = AsyncMock()
mock_client.move_item = AsyncMock(return_value=0)
mock_client.search = AsyncMock(return_value=[
{
"tab": "info",
"index": 0,
"text_preview": "Found item",
"tags": ["tag1"],
"match_in": "text",
}
])
mock_client._full_tab = lambda tab: f"mcp/{tab}" if not tab.startswith("mcp/") else tab
yield mock_client
@pytest.fixture
def sample_items():
"""Sample items for testing."""
return [
{
"index": 0,
"text": "First item with some text",
"tags": ["important", "todo"],
"note": "This is a note",
},
{
"index": 1,
"text": "Second item",
"tags": ["archive"],
"note": "",
},
{
"index": 2,
"text": "Third item with a longer text that should be truncated in preview mode",
"tags": [],
"note": "Another note",
},
]