117 lines
3.5 KiB
Python
117 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Calejo Control Adapter - Test Runner with Better Output Formatting
|
|
|
|
This script runs the standard test suite but provides better output formatting
|
|
and organization of results by test file and system.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import time
|
|
from datetime import datetime
|
|
|
|
# Colors for output
|
|
class Colors:
|
|
RED = '\033[91m'
|
|
GREEN = '\033[92m'
|
|
YELLOW = '\033[93m'
|
|
BLUE = '\033[94m'
|
|
MAGENTA = '\033[95m'
|
|
CYAN = '\033[96m'
|
|
WHITE = '\033[97m'
|
|
BOLD = '\033[1m'
|
|
END = '\033[0m'
|
|
|
|
def print_color(color, message):
|
|
print(f"{color}{message}{Colors.END}")
|
|
|
|
def print_info(message):
|
|
print_color(Colors.BLUE, f"[INFO] {message}")
|
|
|
|
def print_success(message):
|
|
print_color(Colors.GREEN, f"[SUCCESS] {message}")
|
|
|
|
def print_warning(message):
|
|
print_color(Colors.YELLOW, f"[WARNING] {message}")
|
|
|
|
def print_error(message):
|
|
print_color(Colors.RED, f"[ERROR] {message}")
|
|
|
|
def print_header(message):
|
|
print_color(Colors.CYAN + Colors.BOLD, f"\n{'='*80}")
|
|
print_color(Colors.CYAN + Colors.BOLD, f" {message}")
|
|
print_color(Colors.CYAN + Colors.BOLD, f"{'='*80}\n")
|
|
|
|
def main():
|
|
"""Main function."""
|
|
print_header("CALEJO CONTROL ADAPTER - TEST SUITE WITH BETTER OUTPUT")
|
|
|
|
print_info(f"Test Run Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
|
|
# Run tests with better organization
|
|
test_sections = [
|
|
("UNIT TESTS", "tests/unit/"),
|
|
("INTEGRATION TESTS", "tests/integration/"),
|
|
("SAFETY FRAMEWORK TESTS", "tests/test_safety.py"),
|
|
("SAFETY FRAMEWORK UNIT TESTS", "tests/unit/test_safety_framework.py")
|
|
]
|
|
|
|
all_passed = True
|
|
start_time = time.time()
|
|
|
|
for section_name, test_path in test_sections:
|
|
print_header(f"RUNNING {section_name}")
|
|
|
|
cmd = [
|
|
'python', '-m', 'pytest', test_path,
|
|
'-v',
|
|
'--tb=short',
|
|
'--color=yes'
|
|
]
|
|
|
|
print_info(f"Running: {' '.join(cmd)}")
|
|
section_start = time.time()
|
|
|
|
result = subprocess.run(cmd)
|
|
|
|
section_duration = time.time() - section_start
|
|
|
|
if result.returncode == 0:
|
|
print_success(f"{section_name} PASSED in {section_duration:.2f}s")
|
|
else:
|
|
print_error(f"{section_name} FAILED in {section_duration:.2f}s")
|
|
all_passed = False
|
|
|
|
total_duration = time.time() - start_time
|
|
|
|
print_header("TEST SUMMARY")
|
|
print_info(f"Test Run Completed: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print_info(f"Total Duration: {total_duration:.2f} seconds")
|
|
|
|
if all_passed:
|
|
print_success("🎉 ALL TEST SECTIONS PASSED! 🎉")
|
|
print_info("\nTest Results by System:")
|
|
print(" ✅ Safety Framework - All tests passed")
|
|
print(" ✅ Protocol Servers - All tests passed")
|
|
print(" ✅ Database Systems - All tests passed")
|
|
print(" ✅ Security Systems - All tests passed")
|
|
print(" ✅ Monitoring Systems - All tests passed")
|
|
print(" ✅ Integration Tests - All tests passed")
|
|
else:
|
|
print_error("❌ SOME TEST SECTIONS FAILED ❌")
|
|
|
|
sys.exit(0 if all_passed else 1)
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print_warning("\nTest run interrupted by user")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print_error(f"Unexpected error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1) |