-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_backend.py
More file actions
155 lines (134 loc) · 4.27 KB
/
test_backend.py
File metadata and controls
155 lines (134 loc) · 4.27 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
#!/usr/bin/env python3
"""
Test script to verify Guard AI backend code is syntactically correct
and all imports work properly.
"""
import sys
import os
def test_imports():
"""Test that all required modules can be imported"""
print("Testing imports...")
try:
import cv2
print("✅ opencv-python imported successfully")
except ImportError as e:
print(f"❌ opencv-python import failed: {e}")
return False
try:
import mediapipe as mp
print("✅ mediapipe imported successfully")
except ImportError as e:
print(f"❌ mediapipe import failed: {e}")
return False
try:
import numpy as np
print("✅ numpy imported successfully")
except ImportError as e:
print(f"❌ numpy import failed: {e}")
return False
try:
import sounddevice as sd
print("✅ sounddevice imported successfully")
except ImportError as e:
print(f"❌ sounddevice import failed: {e}")
return False
try:
import psutil
print("✅ psutil imported successfully")
except ImportError as e:
print(f"❌ psutil import failed: {e}")
return False
try:
from fpdf import FPDF
print("✅ fpdf imported successfully")
except ImportError as e:
print(f"❌ fpdf import failed: {e}")
return False
try:
from flask import Flask
print("✅ flask imported successfully")
except ImportError as e:
print(f"❌ flask import failed: {e}")
return False
return True
def test_main_syntax():
"""Test that main.py has no syntax errors"""
print("\nTesting main.py syntax...")
try:
with open("main.py", "r") as f:
code = f.read()
compile(code, "main.py", "exec")
print("✅ main.py has no syntax errors")
return True
except SyntaxError as e:
print(f"❌ main.py has syntax error: {e}")
return False
def test_app_syntax():
"""Test that app.py has no syntax errors"""
print("\nTesting app.py syntax...")
try:
with open("app.py", "r") as f:
code = f.read()
compile(code, "app.py", "exec")
print("✅ app.py has no syntax errors")
return True
except SyntaxError as e:
print(f"❌ app.py has syntax error: {e}")
return False
def test_pdf_generation():
"""Test PDF generation functionality"""
print("\nTesting PDF generation...")
try:
from fpdf import FPDF
import textwrap
# Create a simple test PDF
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", 'B', size=16)
pdf.cell(0, 10, "Test Report", ln=True, align='C')
test_pdf_path = "logs/test_report.pdf"
os.makedirs("logs", exist_ok=True)
pdf.output(test_pdf_path)
if os.path.exists(test_pdf_path):
print(f"✅ PDF generation works - created {test_pdf_path}")
os.remove(test_pdf_path)
return True
else:
print("❌ PDF generation failed - file not created")
return False
except Exception as e:
print(f"❌ PDF generation error: {e}")
return False
def main():
print("=" * 60)
print("Guard AI Backend Verification Test")
print("=" * 60)
tests = [
("Import Test", test_imports),
("main.py Syntax Test", test_main_syntax),
("app.py Syntax Test", test_app_syntax),
("PDF Generation Test", test_pdf_generation),
]
results = []
for test_name, test_func in tests:
print(f"\n{'=' * 60}")
result = test_func()
results.append((test_name, result))
print(f"\n{'=' * 60}")
print("Test Summary:")
print("=" * 60)
all_passed = True
for test_name, result in results:
status = "✅ PASSED" if result else "❌ FAILED"
print(f"{test_name}: {status}")
if not result:
all_passed = False
print("=" * 60)
if all_passed:
print("🎉 All tests passed! Backend is ready to use.")
return 0
else:
print("⚠️ Some tests failed. Please review the errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())