-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_system.py
More file actions
305 lines (261 loc) · 10 KB
/
test_system.py
File metadata and controls
305 lines (261 loc) · 10 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/usr/bin/env python3
"""
Test script for macOS AI Assistant
Tests one function from each category to verify system integration
"""
import json
from macos_functions import *
def test_individual_functions():
"""Test one function from each category to verify system works"""
print("🧪 Testing macOS functions (one per category)...\n")
# 1. System Information
print("1. Testing get_system_info() [System Information]...")
try:
result = get_system_info()
data = json.loads(result)
if data.get('success'):
print("✅ System info retrieved successfully")
print(f" CPU cores: {data['system']['cpu']['core_count']}")
print(f" Memory: {data['system']['memory']['total_gb']} GB")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 2. Battery Info
print("2. Testing get_battery_info() [Power]...")
try:
result = get_battery_info()
data = json.loads(result)
if data.get('success'):
print("✅ Battery info retrieved successfully")
if 'error' not in data['battery']:
print(f" Battery: {data['battery']['percentage']}%")
print(f" Charging: {data['battery']['charging']}")
else:
print(f" {data['battery']['error']}")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 3. Theme & Appearance
print("3. Testing get_current_theme() [Theme & Appearance]...")
try:
result = get_current_theme()
data = json.loads(result)
if data.get('success'):
print("✅ Theme retrieved successfully")
print(f" Current theme: {data['theme']}")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 4. Audio Control
print("4. Testing get_volume() [Audio Control]...")
try:
result = get_volume()
data = json.loads(result)
if data.get('success'):
print("✅ Volume retrieved successfully")
print(f" Current volume: {data['volume']}%")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 5. Display Control
print("5. Testing get_brightness() [Display Control]...")
try:
result = get_brightness()
data = json.loads(result)
if data.get('success'):
print("✅ Brightness retrieved successfully")
print(f" Current brightness: {data['brightness']}%")
else:
print(f"⚠️ Note: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 6. Clipboard
print("6. Testing clipboard functions [Clipboard]...")
try:
test_text = "Hello from macOS AI Assistant!"
copy_result = copy_to_clipboard(test_text)
copy_data = json.loads(copy_result)
if copy_data.get('success'):
print("✅ Copy to clipboard successful")
get_result = get_clipboard_content()
get_data = json.loads(get_result)
if get_data.get('success'):
print("✅ Get clipboard content successful")
print(f" Content: '{get_data['content']}'")
else:
print(f"❌ Get clipboard failed: {get_data.get('error')}")
else:
print(f"❌ Copy to clipboard failed: {copy_data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 7. File Operations
print("7. Testing find_files() [File Operations]...")
try:
result = find_files("~/Desktop", file_extension="txt")
data = json.loads(result)
if data.get('success'):
print(f"✅ File search successful - found {data['count']} files")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 8. Applications
print("8. Testing list_running_applications() [Applications]...")
try:
result = list_running_applications()
data = json.loads(result)
if data.get('success'):
print("✅ Running applications retrieved successfully")
print(f" Count: {data['count']} apps running")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 9. GUI Automation
print("9. Testing get_screen_info() [GUI Automation]...")
try:
result = get_screen_info()
data = json.loads(result)
if data.get('success'):
print("✅ Screen info retrieved successfully")
print(f" Resolution: {data['screen']['resolution']}")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
print("9b. Testing get_mouse_position() [GUI Automation]...")
try:
result = get_mouse_position()
data = json.loads(result)
if data.get('success'):
print("✅ Mouse position retrieved successfully")
print(f" Position: ({data['position']['x']}, {data['position']['y']})")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 10. Productivity
print("10. Testing get_current_datetime() [Productivity]...")
try:
result = get_current_datetime()
data = json.loads(result)
if data.get('success'):
print("✅ Date/time retrieved successfully")
print(f" {data['formatted']}")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 11. Data & Analysis
print("11. Testing calculate_expression() [Data & Analysis]...")
try:
result = calculate_expression("2 + 2 * 3")
data = json.loads(result)
if data.get('success'):
print("✅ Mathematical expression calculated successfully")
print(f" Result: {data['message']}")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
print("11b. Testing analyze_data() [Data & Analysis]...")
try:
test_numbers = [10, 20, 30, 40, 50]
result = analyze_data("general", test_numbers)
data = json.loads(result)
if data.get('success'):
print("✅ Data analysis completed successfully")
print(f" Mean: {data['analysis']['mean']}, Count: {data['analysis']['count']}")
else:
print(f"❌ Failed: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
# 12. Network
print("12. Testing get_wifi_networks() [Network]...")
try:
result = get_wifi_networks()
data = json.loads(result)
if data.get('success'):
print("✅ Wi-Fi networks scanned successfully")
print(f" Networks found: {data['count']}")
else:
print(f"⚠️ Note: {data.get('error')}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
print()
def test_ollama_connection():
"""Test connection to Ollama"""
print("🔗 Testing Ollama connection...\n")
try:
from ollama import chat
print("Testing basic Ollama chat...")
response = chat(
model='functiongemma:270m',
messages=[{'role': 'user', 'content': 'Hello, can you hear me?'}]
)
if response and response.message and response.message.content:
print("✅ Ollama connection successful")
print(f" Response: {response.message.content[:100]}...")
else:
print("❌ No response from Ollama")
except Exception as e:
print(f"❌ Ollama connection failed: {str(e)}")
print("Make sure Ollama is running and functiongemma model is installed:")
print(" 1. Start Ollama: brew services start ollama")
print(" 2. Install model: ollama pull functiongemma:270m")
print()
def test_ai_assistant():
"""Test the AI Assistant with a simple query"""
print("🤖 Testing AI Assistant integration...\n")
try:
from macos_ai_assistant import MacOSAIAssistant
assistant = MacOSAIAssistant()
test_query = "Show me my system information"
print(f"Testing query: '{test_query}'")
result = assistant.process_query(test_query)
if result['success']:
print("✅ AI Assistant test successful")
print(f" Final response: {result['final_response'][:150]}...")
if result['function_calls']:
print(f" Functions called: {[fc['function'] for fc in result['function_calls']]}")
else:
print(f"❌ AI Assistant test failed: {result.get('error')}")
except Exception as e:
print(f"❌ AI Assistant test failed: {str(e)}")
print()
def main():
"""Run all tests"""
print("🚀 Starting macOS AI Assistant System Tests\n")
print("=" * 50)
# Test individual functions (one per category)
test_individual_functions()
print("=" * 50)
# Test Ollama connection
test_ollama_connection()
print("=" * 50)
# Test AI assistant integration
test_ai_assistant()
print("=" * 50)
print("✅ Testing complete!")
print("\nIf all tests passed, you can now run:")
print(" python macos_ai_assistant.py")
print("\nTo start the interactive AI assistant.")
if __name__ == "__main__":
main()