1+ """
2+ Test for Qwen CLI manager
3+ """
4+
5+ import os
6+ import tempfile
7+ from unittest .mock import patch
8+
9+ from mcpm .clients .managers .qwen_cli import QwenCliManager
10+
11+
12+ def test_qwen_cli_manager_initialization ():
13+ """Test QwenCliManager initialization"""
14+ # Test with default config path
15+ manager = QwenCliManager ()
16+ assert manager .client_key == "qwen-cli"
17+ assert manager .display_name == "Qwen CLI"
18+ assert manager .download_url == "https://github.com/QwenLM/qwen-code"
19+ assert manager .config_path == os .path .expanduser ("~/.qwen/settings.json" )
20+
21+ # Test with custom config path
22+ custom_path = "/tmp/custom_settings.json"
23+ manager = QwenCliManager (config_path_override = custom_path )
24+ assert manager .config_path == custom_path
25+
26+
27+ def test_qwen_cli_manager_get_empty_config ():
28+ """Test QwenCliManager _get_empty_config method"""
29+ manager = QwenCliManager ()
30+ config = manager ._get_empty_config ()
31+ assert "mcpServers" in config
32+ assert "theme" in config
33+ assert "selectedAuthType" in config
34+ assert config ["mcpServers" ] == {}
35+
36+
37+ def test_qwen_cli_manager_is_client_installed ():
38+ """Test QwenCliManager is_client_installed method"""
39+ manager = QwenCliManager ()
40+
41+ # Mock shutil.which to return a path (simulating installed client)
42+ with patch ("shutil.which" , return_value = "/usr/local/bin/qwen" ) as mock_which :
43+ assert manager .is_client_installed () is True
44+ mock_which .assert_called_with ("qwen" )
45+
46+ # Mock shutil.which to return None (simulating uninstalled client)
47+ with patch ("shutil.which" , return_value = None ) as mock_which :
48+ assert manager .is_client_installed () is False
49+ mock_which .assert_called_with ("qwen" )
50+
51+
52+ def test_qwen_cli_manager_is_client_installed_windows ():
53+ """Test QwenCliManager is_client_installed method on Windows"""
54+ manager = QwenCliManager ()
55+
56+ with patch .object (manager , "_system" , "Windows" ):
57+ # Mock shutil.which to return a path (simulating installed client)
58+ with patch ("shutil.which" , return_value = "C:\\ Program Files\\ qwen\\ qwen.exe" ) as mock_which :
59+ assert manager .is_client_installed () is True
60+ mock_which .assert_called_with ("qwen.exe" )
61+
62+ # Mock shutil.which to return None (simulating uninstalled client)
63+ with patch ("shutil.which" , return_value = None ) as mock_which :
64+ assert manager .is_client_installed () is False
65+ mock_which .assert_called_with ("qwen.exe" )
66+
67+
68+ def test_qwen_cli_manager_get_empty_config_structure ():
69+ """Test QwenCliManager _get_empty_config method returns expected structure"""
70+ manager = QwenCliManager ()
71+ config = manager ._get_empty_config ()
72+
73+ # Check that required keys are present
74+ assert "mcpServers" in config
75+ assert "theme" in config
76+ assert "selectedAuthType" in config
77+
78+ # Check default values
79+ assert config ["mcpServers" ] == {}
80+ assert config ["theme" ] == "Qwen Dark"
81+ assert config ["selectedAuthType" ] == "openai"
82+
83+
84+ def test_qwen_cli_manager_get_client_info ():
85+ """Test QwenCliManager get_client_info method"""
86+ manager = QwenCliManager ()
87+ info = manager .get_client_info ()
88+ assert info ["name" ] == "Qwen CLI"
89+ assert info ["download_url" ] == "https://github.com/QwenLM/qwen-code"
90+ assert info ["config_file" ] == os .path .expanduser ("~/.qwen/settings.json" )
91+ assert info ["description" ] == "Alibaba's Qwen CLI tool"
0 commit comments