-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
180 lines (142 loc) Β· 5.19 KB
/
test_setup.py
File metadata and controls
180 lines (142 loc) Β· 5.19 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
#!/usr/bin/env python3
"""
Test script to verify the Memory Assistant setup.
Run this to check if all components are working correctly.
"""
import sys
from pathlib import Path
import logging
# Add the project root to Python path
sys.path.append(str(Path(__file__).parent))
def test_imports():
"""Test if all modules can be imported."""
print("π Testing imports...")
try:
from config.settings import settings
print("β
Settings module imported successfully")
except Exception as e:
print(f"β Failed to import settings: {e}")
return False
try:
from capture.camera import Camera
print("β
Camera module imported successfully")
except Exception as e:
print(f"β Failed to import camera: {e}")
return False
try:
from vision.detector import ObjectDetector
print("β
Object detector module imported successfully")
except Exception as e:
print(f"β Failed to import object detector: {e}")
return False
try:
from memory.database import MemoryDatabase
print("β
Database module imported successfully")
except Exception as e:
print(f"β Failed to import database: {e}")
return False
try:
from api.openai_client import OpenAIClient
print("β
OpenAI client module imported successfully")
except Exception as e:
print(f"β Failed to import OpenAI client: {e}")
return False
return True
def test_settings():
"""Test settings configuration."""
print("\nπ§ Testing settings...")
try:
from config.settings import settings
print(f"β
Base directory: {settings.BASE_DIR}")
print(f"β
Database path: {settings.DATABASE_PATH}")
print(f"β
Images path: {settings.IMAGES_PATH}")
print(f"β
Capture interval: {settings.CAPTURE_INTERVAL} seconds")
# Test directory creation
settings.create_directories()
print("β
Directories created successfully")
return True
except Exception as e:
print(f"β Settings test failed: {e}")
return False
def test_camera():
"""Test camera functionality."""
print("\nπΈ Testing camera...")
try:
from capture.camera import Camera
camera = Camera()
print("β
Camera object created")
# Test initialization
if camera.initialize():
print("β
Camera initialized successfully")
camera.release()
return True
else:
print("β οΈ Camera initialization failed (this is normal if no webcam is available)")
return True # Don't fail the test for camera issues
except Exception as e:
print(f"β Camera test failed: {e}")
return False
def test_database():
"""Test database functionality."""
print("\nποΈ Testing database...")
try:
from memory.database import MemoryDatabase
db = MemoryDatabase()
print("β
Database initialized successfully")
# Test statistics
stats = db.get_statistics()
print(f"β
Database statistics: {stats}")
return True
except Exception as e:
print(f"β Database test failed: {e}")
return False
def test_openai():
"""Test OpenAI API connection."""
print("\nπ€ Testing OpenAI API...")
try:
from api.openai_client import OpenAIClient
client = OpenAIClient()
print("β
OpenAI client created")
# Test connection
if client.validate_api_connection():
print("β
OpenAI API connection successful")
return True
else:
print("β οΈ OpenAI API connection failed (check your API key)")
return False
except Exception as e:
print(f"β OpenAI test failed: {e}")
return False
def main():
"""Run all tests."""
print("π§ Memory Assistant Setup Test")
print("=" * 40)
tests = [
("Imports", test_imports),
("Settings", test_settings),
("Camera", test_camera),
("Database", test_database),
("OpenAI", test_openai)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
try:
if test_func():
passed += 1
except Exception as e:
print(f"β {test_name} test crashed: {e}")
print("\n" + "=" * 40)
print(f"π Test Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! Your Memory Assistant is ready to use.")
print("\nπ To start the application, run:")
print(" streamlit run app.py")
else:
print("β οΈ Some tests failed. Please check the errors above.")
print("\nπ‘ Common issues:")
print(" - Make sure you have a .env file with your OpenAI API key")
print(" - Install all dependencies: pip install -r requirements.txt")
print(" - Ensure you have a webcam available for camera tests")
if __name__ == "__main__":
main()