-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_notification.py
More file actions
executable file
·131 lines (102 loc) · 3.31 KB
/
Copy pathtest_notification.py
File metadata and controls
executable file
·131 lines (102 loc) · 3.31 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
#!/usr/bin/env python3
"""Simple test script for notification system."""
import sys
import time
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from openadapt_tray.notifications import NotificationManager
def test_basic_notification():
"""Test basic notification."""
print("Testing basic notification...")
nm = NotificationManager()
result = nm.show(
title="OpenAdapt Test",
body="This is a basic test notification from desktop-notifier!"
)
print(f"Basic notification result: {result}")
return result
def test_notification_with_callback():
"""Test notification with callback."""
print("\nTesting notification with callback...")
clicked = [False] # Use list to allow modification in closure
def on_click():
print("Notification was clicked!")
clicked[0] = True
nm = NotificationManager()
result = nm.show(
title="OpenAdapt Test",
body="Click this notification to test callbacks!",
on_clicked=on_click
)
print(f"Callback notification result: {result}")
# Wait a bit to see if user clicks
print("Waiting 10 seconds for click...")
time.sleep(10)
if clicked[0]:
print("Callback was triggered!")
else:
print("No click detected (this is normal if you didn't click)")
return result
def test_critical_notification():
"""Test critical urgency notification."""
print("\nTesting critical notification...")
nm = NotificationManager()
result = nm.show(
title="OpenAdapt Critical",
body="This is a critical notification!",
urgency="critical"
)
print(f"Critical notification result: {result}")
return result
def test_notification_with_buttons():
"""Test notification with action buttons."""
print("\nTesting notification with buttons...")
def on_click():
print("Notification with buttons was clicked!")
nm = NotificationManager()
result = nm.show(
title="OpenAdapt Actions",
body="This notification has action buttons (if supported on your platform)",
buttons=["Yes", "No", "Maybe"],
on_clicked=on_click
)
print(f"Button notification result: {result}")
# Wait a bit to see if user interacts
print("Waiting 10 seconds for interaction...")
time.sleep(10)
return result
def main():
"""Run all tests."""
print("=" * 60)
print("OpenAdapt Notification System Test")
print("=" * 60)
tests = [
test_basic_notification,
test_notification_with_callback,
test_critical_notification,
test_notification_with_buttons,
]
results = []
for test in tests:
try:
result = test()
results.append((test.__name__, result))
time.sleep(2) # Brief pause between tests
except Exception as e:
print(f"Error in {test.__name__}: {e}")
results.append((test.__name__, False))
# Summary
print("\n" + "=" * 60)
print("Test Summary")
print("=" * 60)
for name, result in results:
status = "PASS" if result else "FAIL"
print(f"{name}: {status}")
# Cleanup
print("\nCleaning up...")
nm = NotificationManager()
nm.cleanup()
print("Done!")
if __name__ == "__main__":
main()