1
1
import json
2
2
import subprocess
3
- from pathlib import Path
4
3
from unittest .mock import patch
5
4
6
5
import pytest
@@ -15,42 +14,39 @@ def temp_config_dir(tmp_path):
15
14
config_dir .mkdir ()
16
15
return config_dir
17
16
17
+
18
18
@pytest .fixture
19
19
def mock_config_path (temp_config_dir ):
20
20
"""Mock get_claude_config_path to return our temporary directory."""
21
- with patch (' mcp.cli.claude.get_claude_config_path' , return_value = temp_config_dir ):
21
+ with patch (" mcp.cli.claude.get_claude_config_path" , return_value = temp_config_dir ):
22
22
yield temp_config_dir
23
23
24
+
24
25
def test_command_execution (mock_config_path ):
25
26
"""Test that the generated command can actually be executed."""
26
27
# Setup
27
28
server_name = "test_server"
28
29
file_spec = "test_server.py:app"
29
-
30
+
30
31
# Update config
31
32
success = update_claude_config (
32
33
file_spec = file_spec ,
33
34
server_name = server_name ,
34
35
)
35
36
assert success
36
-
37
+
37
38
# Read the generated config
38
39
config_file = mock_config_path / "claude_desktop_config.json"
39
40
config = json .loads (config_file .read_text ())
40
-
41
+
41
42
# Get the command and args
42
43
server_config = config ["mcpServers" ][server_name ]
43
44
command = server_config ["command" ]
44
45
args = server_config ["args" ]
45
46
46
47
test_args = [command ] + args + ["--help" ]
47
-
48
- result = subprocess .run (
49
- test_args ,
50
- capture_output = True ,
51
- text = True ,
52
- timeout = 5
53
- )
54
-
48
+
49
+ result = subprocess .run (test_args , capture_output = True , text = True , timeout = 5 )
50
+
55
51
assert result .returncode == 0
56
- assert "usage" in result .stdout .lower ()
52
+ assert "usage" in result .stdout .lower ()
0 commit comments