-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
334 lines (266 loc) · 8.94 KB
/
validate.py
File metadata and controls
334 lines (266 loc) · 8.94 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
#!/usr/bin/env python3
"""
TestBuddy v2 - Deployment & Build Validation
Comprehensive validation that the application is ready for deployment.
"""
import sys
from pathlib import Path
import json
from datetime import datetime
# Add project to path
sys.path.insert(0, str(Path(__file__).parent))
def validate_files():
"""Check all required files exist."""
print("\n" + "="*60)
print("FILE VALIDATION")
print("="*60)
required_files = [
("Python Code", [
"app.py",
"config.py",
"history.py",
"run.py",
"test_suite.py",
]),
("Configuration", [
"testbuddy.ini",
"requirements.txt",
]),
("Documentation", [
"README_V2.md",
"QUICKSTART_V2.md",
"PHASE2_INTEGRATION.md",
"INTEGRATION_SUMMARY.md",
"COMPLETE_SUMMARY.md",
]),
]
all_ok = True
for category, files in required_files:
print(f"\n{category}:")
for filename in files:
filepath = Path(filename)
if filepath.exists():
size = filepath.stat().st_size
print(f" [OK] {filename:30} ({size:,} bytes)")
else:
print(f" [MISSING] {filename:30}")
all_ok = False
return all_ok
def validate_syntax():
"""Check Python syntax of all modules."""
print("\n" + "="*60)
print("SYNTAX VALIDATION")
print("="*60)
import py_compile
python_files = ["app.py", "config.py", "history.py", "run.py", "test_suite.py"]
all_ok = True
for filename in python_files:
try:
py_compile.compile(filename, doraise=True)
print(f" [OK] {filename}")
except Exception as e:
print(f" [ERROR] {filename}: {e}")
all_ok = False
return all_ok
def validate_imports():
"""Test that all imports work."""
print("\n" + "="*60)
print("IMPORT VALIDATION")
print("="*60)
modules = {
"PyQt6": "PyQt6.QtCore",
"PIL": "PIL.Image",
"pytesseract": "pytesseract",
"config": "config",
"history": "history",
}
all_ok = True
for name, module_path in modules.items():
try:
__import__(module_path)
print(f" [OK] {name:15} ({module_path})")
except Exception as e:
print(f" [ERROR] {name:15} ({module_path}): {e}")
all_ok = False
return all_ok
def validate_config():
"""Check configuration system."""
print("\n" + "="*60)
print("CONFIGURATION VALIDATION")
print("="*60)
try:
from config import ConfigManager
cm = ConfigManager()
config = cm.config
checks = [
("Tesseract path", lambda: isinstance(config.tesseract_path, str)),
("OCR language", lambda: isinstance(config.ocr_language, str)),
("History file", lambda: isinstance(config.history_file, str)),
("Export directory", lambda: isinstance(config.export_directory, str)),
("Debug mode", lambda: isinstance(config.debug_mode, bool)),
("History enabled", lambda: isinstance(config.enable_history, bool)),
]
all_ok = True
for check_name, check_func in checks:
result = check_func()
status = "[OK]" if result else "[ERROR]"
print(f" {status} {check_name}")
all_ok = all_ok and result
return all_ok
except Exception as e:
print(f" [ERROR] Config system: {e}")
return False
def validate_history():
"""Check history system."""
print("\n" + "="*60)
print("HISTORY SYSTEM VALIDATION")
print("="*60)
try:
from config import ConfigManager
from history import HistoryManager
cm = ConfigManager()
hm = HistoryManager(cm.config.history_file, cm.config.history_max_entries)
# Test add
hm.add_entry("Test entry", "eng", tags=["test"])
print(f" [OK] add_entry() works")
# Test get_all
all_entries = hm.get_all()
print(f" [OK] get_all() works ({len(all_entries)} entries)")
# Test search
search_results = hm.search("Test")
print(f" [OK] search() works ({len(search_results)} results)")
# Test persistence
hm.save()
history_file = Path(cm.config.history_file)
if history_file.exists():
print(f" [OK] Persistence works ({history_file.stat().st_size} bytes)")
else:
print(f" [WARNING] History file not saved")
return True
except Exception as e:
print(f" [ERROR] History system: {e}")
return False
def validate_app_structure():
"""Check app.py structure."""
print("\n" + "="*60)
print("APPLICATION STRUCTURE VALIDATION")
print("="*60)
try:
with open("app.py", "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
required_classes = [
"Session",
"ImageViewer",
"OCRWorker",
"SplashScreen",
"NewSessionDialog",
"HomePage",
"Workbench",
"MainWindow",
]
required_functions = [
"safe_write_log",
"fmt_log",
]
all_ok = True
for class_name in required_classes:
if f"class {class_name}" in content:
print(f" [OK] Class: {class_name}")
else:
print(f" [MISSING] Class: {class_name}")
all_ok = False
for func_name in required_functions:
if f"def {func_name}" in content:
print(f" [OK] Function: {func_name}")
else:
print(f" [MISSING] Function: {func_name}")
all_ok = False
# Check line count
lines = len(content.split('\n'))
print(f" [OK] Code size: {lines} lines")
return all_ok
except Exception as e:
print(f" [ERROR] App structure: {e}")
return False
def validate_dependencies():
"""List all dependencies."""
print("\n" + "="*60)
print("DEPENDENCY CHECK")
print("="*60)
try:
with open("requirements.txt", "r") as f:
reqs = f.read().strip().split('\n')
print("\nRequired packages (from requirements.txt):")
for req in reqs:
if req.strip() and not req.startswith('#'):
print(f" - {req}")
# Check installed versions
print("\nInstalled versions:")
versions = {}
try:
import PyQt6
versions['PyQt6'] = "installed"
except:
pass
try:
import PIL
versions['Pillow'] = PIL.__version__
except:
pass
try:
import pytesseract
versions['pytesseract'] = "installed"
except:
pass
for name, version in versions.items():
print(f" [OK] {name:15} {version}")
return True
except Exception as e:
print(f" [ERROR] Dependencies: {e}")
return False
def generate_report():
"""Generate deployment report."""
print("\n" + "="*60)
print("DEPLOYMENT READINESS REPORT")
print("="*60)
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
checks = {
"Files Present": validate_files(),
"Syntax Valid": validate_syntax(),
"Imports OK": validate_imports(),
"Config System": validate_config(),
"History System": validate_history(),
"App Structure": validate_app_structure(),
"Dependencies": validate_dependencies(),
}
print("\n" + "="*60)
print("FINAL STATUS")
print("="*60)
passed = sum(1 for v in checks.values() if v)
total = len(checks)
for name, result in checks.items():
status = "[PASS]" if result else "[FAIL]"
print(f" {status} {name}")
print("-"*60)
print(f"Overall: {passed}/{total} checks passed")
print(f"Generated: {timestamp}")
if passed == total:
print("\n✓ APPLICATION IS READY FOR DEPLOYMENT")
print("\nTo run the app:")
print(" python run.py")
print("\nTo run tests:")
print(" python test_suite.py")
return 0
else:
print(f"\n✗ APPLICATION HAS {total - passed} ISSUE(S)")
print("\nReview errors above and fix before deployment")
return 1
def main():
"""Run all validations."""
print("\n")
print("╔" + "="*58 + "╗")
print("║" + " TestBuddy v2 - Deployment Validation".center(58) + "║")
print("╚" + "="*58 + "╝")
return generate_report()
if __name__ == "__main__":
sys.exit(main())