-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathconftest.py
More file actions
91 lines (71 loc) · 3.03 KB
/
Copy pathconftest.py
File metadata and controls
91 lines (71 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Pytest configuration for MCPM tests
"""
import json
import os
import sys
import tempfile
from pathlib import Path
from unittest.mock import Mock
import pytest
# Add the src directory to the path for all tests
sys.path.insert(0, str(Path(__file__).parent.parent))
from mcpm.clients.client_registry import ClientRegistry
from mcpm.clients.managers.claude_desktop import ClaudeDesktopManager
from mcpm.clients.managers.windsurf import WindsurfManager
from mcpm.utils.config import ConfigManager
@pytest.fixture
def temp_config_file():
"""Create a temporary Windsurf config file for testing"""
with tempfile.NamedTemporaryFile(delete=False, suffix=".json") as f:
# Create a basic config with a test server
config = {
"mcpServers": {
"test-server": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-test"],
"version": "1.0.0",
"path": "/path/to/server",
"display_name": "Test Server",
}
}
}
f.write(json.dumps(config).encode("utf-8"))
temp_path = f.name
yield temp_path
# Clean up
os.unlink(temp_path)
@pytest.fixture
def config_manager(monkeypatch):
"""Create a ClientConfigManager with a temp config for testing"""
with tempfile.TemporaryDirectory() as temp_dir:
tmp_config_path = os.path.join(temp_dir, "config.json")
# Create ConfigManager with the temp path
_original_init = ConfigManager.__init__
def _mock_init(self, config_path=tmp_config_path):
_original_init(self, config_path)
self.config_path = tmp_config_path
monkeypatch.setattr(ConfigManager, "__init__", _mock_init)
config_mgr = ConfigManager()
# Create ClientConfigManager that will use this ConfigManager internally
from mcpm.clients.client_config import ClientConfigManager
client_mgr = ClientConfigManager()
# Override its internal config_manager with our temp one
client_mgr.config_manager = config_mgr
yield client_mgr
@pytest.fixture
def windsurf_manager(temp_config_file, monkeypatch, config_manager):
"""Create a WindsurfManager instance using the temp config file"""
windsurf_manager = WindsurfManager(config_path=temp_config_file)
monkeypatch.setattr(ClientRegistry, "get_active_client_manager", Mock(return_value=windsurf_manager))
monkeypatch.setattr(ClientRegistry, "get_client_manager", Mock(return_value=windsurf_manager))
monkeypatch.setattr(ClientRegistry, "get_active_target", Mock(return_value="@windsurf"))
return windsurf_manager
@pytest.fixture
def empty_windsurf_manager(empty_config_file):
"""Create a WindsurfManager instance with an empty config"""
return WindsurfManager(config_path=empty_config_file)
@pytest.fixture
def claude_desktop_manager(temp_config_file):
"""Create a ClaudeDesktopManager instance with the temp config"""
return ClaudeDesktopManager(config_path=temp_config_file)