-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomprehensive_function_test.py
More file actions
411 lines (340 loc) · 12.1 KB
/
comprehensive_function_test.py
File metadata and controls
411 lines (340 loc) · 12.1 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#!/usr/bin/env python3
"""
Comprehensive Function Test Script
Tests all macOS functions individually, organized by functionality category
"""
import json
import os
import tempfile
from macos_functions import *
def test_function(func_name, func, *args, **kwargs):
"""Test a single function and return result with detailed output"""
print(f"Testing {func_name}...")
try:
result = func(*args, **kwargs)
data = json.loads(result) if isinstance(result, str) else result
if data.get('success') == True:
print(f"✅ {func_name}: SUCCESS")
# Show return data for verification (truncate if too long)
data_str = str(data)
if len(data_str) > 150:
print(f" 📋 Return: {data_str[:150]}...")
else:
print(f" 📋 Return: {data_str}")
return True
elif data.get('success') == False:
print(f"❌ {func_name}: FAILED - {data.get('error', 'Unknown error')}")
print(f" 📋 Return: {data}")
return False
else:
print(f"✅ {func_name}: SUCCESS (no error field)")
# Show return data for verification (truncate if too long)
data_str = str(data)
if len(data_str) > 150:
print(f" 📋 Return: {data_str[:150]}...")
else:
print(f" 📋 Return: {data_str}")
return True
except Exception as e:
print(f"❌ {func_name}: EXCEPTION - {str(e)}")
return False
def main():
"""Test all functions systematically, organized by functionality"""
print("🧪 COMPREHENSIVE FUNCTION TESTING")
print("=" * 60)
passed = 0
failed = 0
# ============================================================
# 1. SYSTEM INFORMATION (Read-only, Safe)
# ============================================================
print("\n📊 1. SYSTEM INFORMATION")
print("-" * 40)
if test_function("get_current_datetime", get_current_datetime):
passed += 1
else:
failed += 1
if test_function("get_battery_info", get_battery_info):
passed += 1
else:
failed += 1
if test_function("get_system_info", get_system_info):
passed += 1
else:
failed += 1
if test_function("get_cpu_usage", get_cpu_usage):
passed += 1
else:
failed += 1
if test_function("get_memory_usage", get_memory_usage):
passed += 1
else:
failed += 1
if test_function("get_disk_usage", get_disk_usage):
passed += 1
else:
failed += 1
if test_function("get_screen_info", get_screen_info):
passed += 1
else:
failed += 1
# ============================================================
# 2. CLIPBOARD OPERATIONS
# ============================================================
print("\n📋 2. CLIPBOARD OPERATIONS")
print("-" * 40)
if test_function("copy_to_clipboard", copy_to_clipboard, "Test clipboard text"):
passed += 1
else:
failed += 1
if test_function("get_clipboard_content", get_clipboard_content):
passed += 1
else:
failed += 1
if test_function("paste_from_clipboard", paste_from_clipboard):
passed += 1
else:
failed += 1
# ============================================================
# 3. AUDIO/VOLUME CONTROL
# ============================================================
print("\n🔊 3. AUDIO/VOLUME CONTROL")
print("-" * 40)
if test_function("get_volume", get_volume):
passed += 1
else:
failed += 1
if test_function("set_volume", set_volume, 50):
passed += 1
else:
failed += 1
if test_function("mute_volume", mute_volume):
passed += 1
else:
failed += 1
if test_function("unmute_volume", unmute_volume):
passed += 1
else:
failed += 1
# ============================================================
# 4. DISPLAY/BRIGHTNESS CONTROL
# ============================================================
print("\n💡 4. DISPLAY/BRIGHTNESS CONTROL")
print("-" * 40)
if test_function("get_brightness", get_brightness):
passed += 1
else:
failed += 1
if test_function("set_brightness", set_brightness, 70):
passed += 1
else:
failed += 1
# ============================================================
# 5. THEME/APPEARANCE CONTROL
# ============================================================
print("\n🎨 5. THEME/APPEARANCE CONTROL")
print("-" * 40)
if test_function("get_current_theme", get_current_theme):
passed += 1
else:
failed += 1
if test_function("change_theme", change_theme, "dark"):
passed += 1
else:
failed += 1
# ============================================================
# 6. DO NOT DISTURB / FOCUS MODE
# ============================================================
print("\n🔕 6. DO NOT DISTURB / FOCUS MODE")
print("-" * 40)
if test_function("enable_do_not_disturb", enable_do_not_disturb):
passed += 1
else:
failed += 1
if test_function("disable_do_not_disturb", disable_do_not_disturb):
passed += 1
else:
failed += 1
# ============================================================
# 7. FILE OPERATIONS
# ============================================================
print("\n📁 7. FILE OPERATIONS")
print("-" * 40)
# Screenshot
temp_screenshot = tempfile.mktemp(suffix=".png")
if test_function("take_screenshot", take_screenshot, temp_screenshot):
passed += 1
try:
os.remove(temp_screenshot)
except:
pass
else:
failed += 1
# Find files
if test_function("find_files", find_files, "~/Desktop", "", "txt"):
passed += 1
else:
failed += 1
# Open file (testing with non-existent file to check error handling)
if test_function("open_file", open_file, "~/Desktop/nonexistent.txt"):
passed += 1
else:
failed += 1
# Open folder
if test_function("open_folder", open_folder, "~/Desktop"):
passed += 1
else:
failed += 1
# Process text file
temp_file = tempfile.mktemp(suffix=".txt")
try:
with open(temp_file, 'w') as f:
f.write("This is a test file.\nWith multiple lines.\nFor testing purposes.")
if test_function("process_text_file", process_text_file, temp_file, "count"):
passed += 1
else:
failed += 1
os.remove(temp_file)
except Exception as e:
print(f"❌ process_text_file: EXCEPTION - {str(e)}")
failed += 1
# ============================================================
# 8. APPLICATION MANAGEMENT
# ============================================================
print("\n📱 8. APPLICATION MANAGEMENT")
print("-" * 40)
if test_function("list_running_applications", list_running_applications):
passed += 1
else:
failed += 1
if test_function("open_application", open_application, "Calculator"):
passed += 1
else:
failed += 1
if test_function("quit_application", quit_application, "Calculator"):
passed += 1
else:
failed += 1
# ============================================================
# 9. GUI AUTOMATION (Mouse & Keyboard)
# ============================================================
print("\n🖱️ 9. GUI AUTOMATION (Mouse & Keyboard)")
print("-" * 40)
# Mouse position (read-only, safe)
if test_function("get_mouse_position", get_mouse_position):
passed += 1
else:
failed += 1
# Click at coordinates (safe coordinates)
if test_function("click_at_coordinates", click_at_coordinates, 100, 100):
passed += 1
else:
failed += 1
# Drag mouse (safe coordinates, short duration)
if test_function("drag_mouse", drag_mouse, 100, 100, 110, 110, 0.1):
passed += 1
else:
failed += 1
# Scroll screen
if test_function("scroll_screen", scroll_screen, "up", 1):
passed += 1
else:
failed += 1
# Type text (minimal text to avoid disruption)
if test_function("type_text", type_text, "test", 0.01):
passed += 1
else:
failed += 1
# Send keyboard shortcut (safe shortcut)
if test_function("send_keyboard_shortcut", send_keyboard_shortcut, "cmd+tab"):
passed += 1
else:
failed += 1
# ============================================================
# 10. macOS APP INTEGRATION
# ============================================================
print("\n🍎 10. macOS APP INTEGRATION")
print("-" * 40)
# Create reminder (may require permissions)
if test_function("create_reminder", create_reminder, "Test reminder", "Test body"):
passed += 1
else:
failed += 1
# Get calendar events (may require permissions)
if test_function("get_calendar_events", get_calendar_events, 7):
passed += 1
else:
failed += 1
# Control music (may require Music app to be open)
if test_function("control_music", control_music, "pause"):
passed += 1
else:
failed += 1
# Send message (will likely fail without proper contact setup)
if test_function("send_message", send_message, "test@example.com", "Test message"):
passed += 1
else:
failed += 1
# ============================================================
# 11. DATA PROCESSING & CALCULATIONS
# ============================================================
print("\n🔢 11. DATA PROCESSING & CALCULATIONS")
print("-" * 40)
if test_function("calculate_expression", calculate_expression, "2 + 2 * 3"):
passed += 1
else:
failed += 1
if test_function("analyze_data", analyze_data, "general", [10, 20, 30, 40, 50]):
passed += 1
else:
failed += 1
# ============================================================
# 12. NETWORK UTILITIES
# ============================================================
print("\n🌐 12. NETWORK UTILITIES")
print("-" * 40)
if test_function("get_wifi_networks", get_wifi_networks):
passed += 1
else:
failed += 1
# ============================================================
# 13. QR CODE GENERATION
# ============================================================
print("\n📷 13. QR CODE GENERATION")
print("-" * 40)
temp_qr = tempfile.mktemp(suffix=".png")
if test_function("generate_qr_code", generate_qr_code, "https://example.com", temp_qr):
passed += 1
try:
os.remove(temp_qr)
except:
pass
else:
failed += 1
# ============================================================
# 14. META/HELPER FUNCTIONS
# ============================================================
print("\n⚙️ 14. META/HELPER FUNCTIONS")
print("-" * 40)
# Test execute_function with a safe function
if test_function("execute_function", execute_function, "get_current_datetime", {}):
passed += 1
else:
failed += 1
# ============================================================
# SUMMARY
# ============================================================
print("\n" + "=" * 60)
print("📊 TESTING SUMMARY")
print("=" * 60)
print(f"✅ Passed: {passed}")
print(f"❌ Failed: {failed}")
print(f"📈 Total Tests: {passed + failed}")
print(f"📈 Success Rate: {(passed/(passed+failed)*100):.1f}%")
print()
if failed == 0:
print("🎉 ALL FUNCTIONS WORKING CORRECTLY!")
else:
print(f"⚠️ {failed} FUNCTION(S) NEED ATTENTION")
return failed == 0
if __name__ == "__main__":
main()