-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
413 lines (329 loc) · 16.1 KB
/
validate.py
File metadata and controls
413 lines (329 loc) · 16.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
412
413
#!/usr/bin/env python3
"""
Voodoo Box Validation Script
This script validates that all voodoo-box modules can be imported and used
independently without the source projects (extendo and NadeStacked).
Run this script to ensure the voodoo-box is properly structured and functional.
"""
import sys
import traceback
import importlib
from typing import Dict, Any
from pathlib import Path
class VoodooBoxValidator:
"""Validates voodoo-box module integrity and functionality."""
def __init__(self):
self.results: Dict[str, Dict[str, Any]] = {}
self.voodoo_box_path = Path(__file__).parent
def validate_all(self) -> Dict[str, Dict[str, Any]]:
"""Run all validation checks."""
print("[VB] Voodoo Box Validation Starting...")
print("=" * 50)
# Core structure validation
self.validate_structure()
# Module import validation
self.validate_imports()
# Basic functionality validation
self.validate_functionality()
# Integration validation
self.validate_integration()
return self.results
def validate_structure(self):
"""Validate directory structure and required files."""
print("\nValidating structure...")
required_dirs = [
"api", "data", "files", "web", "gaming", "utils", "testing"
]
required_files = [
"__init__.py", "README.md", "REQUIREMENTS.md"
]
structure_results = {
"directories": {},
"files": {},
"status": "success"
}
# Check directories
for dir_name in required_dirs:
dir_path = self.voodoo_box_path / dir_name
if dir_path.exists() and dir_path.is_dir():
structure_results["directories"][dir_name] = "[+] Found"
# Check for __init__.py or README.md in each directory
has_init = (dir_path / "__init__.py").exists()
has_readme = (dir_path / "README.md").exists()
if has_init or has_readme:
structure_results["directories"][dir_name] += " (documented)"
else:
structure_results["directories"][dir_name] += " (minimal docs)"
else:
structure_results["directories"][dir_name] = "[-] Missing"
structure_results["status"] = "warning"
# Check files
for file_name in required_files:
file_path = self.voodoo_box_path / file_name
if file_path.exists():
structure_results["files"][file_name] = "[+] Found"
else:
structure_results["files"][file_name] = "[-] Missing"
structure_results["status"] = "warning"
self.results["structure"] = structure_results
self._print_results("Structure", structure_results)
def validate_imports(self):
"""Validate that modules can be imported without errors."""
print("\nValidating imports...")
import_tests = [
# Utils module
("utils.logging", "LoggerSetup"),
("utils.caching", "TimedLRUCache"),
("utils.error_handling", "ErrorHandler"),
# API module
("api.base_client", "BaseAPIClient"),
("api.faceit_client", "FaceitClient"),
# Data module
("data.stats_aggregators", "StatsAggregator"),
("data.transformers", "DataCleaner"),
# Files module
("files.file_manager", "FileManager"),
# Gaming module
("gaming.demo_analyzer", "DemoPositionAnalyzer"),
]
import_results = {
"modules": {},
"status": "success"
}
for module_path, class_name in import_tests:
try:
# Try to import directly from the module
module = importlib.import_module(module_path)
# Check if the expected class exists
if hasattr(module, class_name):
import_results["modules"][module_path] = f"[+] {class_name} available"
else:
import_results["modules"][module_path] = f"[!] Module imported but {class_name} not found"
import_results["status"] = "warning"
except ImportError as e:
import_results["modules"][module_path] = f"[-] Import failed: {str(e)}"
import_results["status"] = "error"
except Exception as e:
import_results["modules"][module_path] = f"[-] Error: {str(e)}"
import_results["status"] = "error"
self.results["imports"] = import_results
self._print_results("Imports", import_results)
def validate_functionality(self):
"""Test basic functionality of key components."""
print("\nValidating functionality...")
functionality_results = {
"tests": {},
"status": "success"
}
# Test logging setup
try:
from utils.logging import LoggerSetup
logger = LoggerSetup.setup_logger("validation_test", level="INFO", log_to_file=False)
logger.info("Test log message")
functionality_results["tests"]["logging"] = "[+] Logger created and used successfully"
except Exception as e:
functionality_results["tests"]["logging"] = f"[-] Logging test failed: {str(e)}"
functionality_results["status"] = "error"
# Test caching
try:
from utils.caching import simple_cache
@simple_cache(maxsize=10)
def test_cache_function(x):
return x * 2
result1 = test_cache_function(5)
result2 = test_cache_function(5) # Should be cached
if result1 == result2 == 10:
functionality_results["tests"]["caching"] = "[+] Cache function works correctly"
else:
functionality_results["tests"]["caching"] = "[-] Cache function returned incorrect results"
functionality_results["status"] = "error"
except Exception as e:
functionality_results["tests"]["caching"] = f"[-] Caching test failed: {str(e)}"
functionality_results["status"] = "error"
# Test error handling
try:
from utils.error_handling import ErrorHandler
error_handler = ErrorHandler()
try:
raise ValueError("Test error")
except ValueError as e:
error_handler.handle_error(e, reraise=False)
stats = error_handler.get_error_stats()
if "ValueError" in stats and stats["ValueError"] == 1:
functionality_results["tests"]["error_handling"] = "[+] Error handler tracks errors correctly"
else:
functionality_results["tests"]["error_handling"] = "[-] Error handler stats incorrect"
functionality_results["status"] = "error"
except Exception as e:
functionality_results["tests"]["error_handling"] = f"[-] Error handling test failed: {str(e)}"
functionality_results["status"] = "error"
# Test file operations
try:
import tempfile
from files.file_manager import FileManager, JSONHandler
with tempfile.TemporaryDirectory() as temp_dir:
test_data = {"test": "data"}
test_file = Path(temp_dir) / "test.json"
# Save and load JSON using static methods
JSONHandler.save_json(test_data, test_file)
loaded_data = JSONHandler.load_json(test_file)
if loaded_data == test_data:
functionality_results["tests"]["file_operations"] = "[+] JSON save/load works correctly"
else:
functionality_results["tests"]["file_operations"] = "[-] JSON data mismatch"
functionality_results["status"] = "error"
except Exception as e:
functionality_results["tests"]["file_operations"] = f"[-] File operations test failed: {str(e)}"
functionality_results["status"] = "error"
self.results["functionality"] = functionality_results
self._print_results("Functionality", functionality_results)
def validate_integration(self):
"""Test integration between modules."""
print("\nValidating integration...")
integration_results = {
"tests": {},
"status": "success"
}
# Test quick_setup function
try:
# Try to use the functions directly from their modules
from utils.logging import setup_project_logging
from utils.error_handling import ErrorHandler, retry_with_backoff
from utils.caching import TimedLRUCache
# Manually recreate quick_setup functionality
project_name = "validation_test"
loggers = setup_project_logging(project_name, debug=False)
error_handler = ErrorHandler(loggers['main'])
utils = {
'loggers': loggers,
'logger': loggers['main'],
'error_handler': error_handler,
'cache': TimedLRUCache,
'retry': retry_with_backoff,
}
required_keys = ["loggers", "logger", "error_handler", "cache", "retry"]
missing_keys = [key for key in required_keys if key not in utils]
if not missing_keys:
integration_results["tests"]["quick_setup"] = "[+] Quick setup components available and working"
else:
integration_results["tests"]["quick_setup"] = f"[-] Missing keys: {missing_keys}"
integration_results["status"] = "error"
except Exception as e:
integration_results["tests"]["quick_setup"] = f"[-] Quick setup failed: {str(e)}"
integration_results["status"] = "error"
# Test module status function
try:
# Test the module discovery functionality directly
modules = {
'api': 'Faceit API client and generic HTTP utilities',
'data': 'Data processing, aggregation, and transformation utilities',
'files': 'File management, JSON handling, and output organization',
'web': 'Browser extension utilities and DOM manipulation',
'gaming': 'CS2 demo analysis and gaming-specific utilities',
'utils': 'Cross-cutting utilities (logging, caching, error handling)'
}
available_modules = {}
for module_name, description in modules.items():
try:
importlib.import_module(module_name)
available_modules[module_name] = {
'description': description,
'status': 'available'
}
except ImportError as e:
available_modules[module_name] = {
'description': description,
'status': f'unavailable ({str(e)})'
}
if isinstance(available_modules, dict) and len(available_modules) > 0:
available_count = sum(1 for mod in available_modules.values() if mod['status'] == 'available')
integration_results["tests"]["module_info"] = f"[+] Module discovery works correctly ({available_count}/{len(available_modules)} modules available)"
else:
integration_results["tests"]["module_info"] = "[-] Module info returned invalid data"
integration_results["status"] = "error"
except Exception as e:
integration_results["tests"]["module_info"] = f"[-] Module info test failed: {str(e)}"
integration_results["status"] = "error"
self.results["integration"] = integration_results
self._print_results("Integration", integration_results)
def _print_results(self, category: str, results: Dict[str, Any]):
"""Print results for a validation category."""
status = results.get("status", "unknown")
status_icon = {"success": "[+]", "warning": "[!]", "error": "[-]"}.get(status, "[?]")
print(f"{status_icon} {category}: {status}")
# Print details
for section_name, section_data in results.items():
if section_name == "status":
continue
if isinstance(section_data, dict):
for key, value in section_data.items():
print(f" {key}: {value}")
else:
print(f" {section_name}: {section_data}")
def generate_report(self) -> str:
"""Generate a summary report of validation results."""
report_lines = [
"[VB] Voodoo Box Validation Report",
"=" * 40,
""
]
overall_status = "success"
total_tests = 0
passed_tests = 0
for category, results in self.results.items():
status = results.get("status", "unknown")
if status == "error":
overall_status = "error"
elif status == "warning" and overall_status != "error":
overall_status = "warning"
# Count tests
for section_name, section_data in results.items():
if isinstance(section_data, dict) and section_name != "status":
for key, value in section_data.items():
total_tests += 1
if "[+]" in str(value):
passed_tests += 1
report_lines.extend([
f"Overall Status: {overall_status.upper()}",
f"Tests Passed: {passed_tests}/{total_tests}",
f"Success Rate: {(passed_tests/total_tests*100):.1f}%" if total_tests > 0 else "No tests run",
""
])
# Detailed results
for category, results in self.results.items():
status_icon = {"success": "[+]", "warning": "[!]", "error": "[-]"}.get(results.get("status"), "[?]")
report_lines.append(f"{status_icon} {category.title()}: {results.get('status', 'unknown')}")
return "\n".join(report_lines)
def main():
"""Run validation and print results."""
try:
# Add voodoo-box to Python path for imports
voodoo_box_path = Path(__file__).parent
sys.path.insert(0, str(voodoo_box_path.parent))
validator = VoodooBoxValidator()
results = validator.validate_all()
print("\n" + "=" * 50)
print(validator.generate_report())
# Return appropriate exit code
overall_status = "success"
for category_results in results.values():
if category_results.get("status") == "error":
overall_status = "error"
break
elif category_results.get("status") == "warning":
overall_status = "warning"
if overall_status == "error":
print("\n[-] Validation completed with errors!")
sys.exit(1)
elif overall_status == "warning":
print("\n[!] Validation completed with warnings!")
sys.exit(0)
else:
print("\n[+] Validation completed successfully!")
sys.exit(0)
except Exception as e:
print(f"\n[!] Validation script failed: {e}")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()