131 lines
3.8 KiB
Python
131 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test Runner - Ejemplo de uso de los tests organizados
|
|
====================================================
|
|
Este script demuestra cómo ejecutar los tests desde su nueva ubicación
|
|
en el directorio .tests/
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def run_test(test_name: str, description: str):
|
|
"""Ejecuta un test específico y muestra resultados"""
|
|
|
|
test_path = Path(".tests") / test_name
|
|
|
|
print(f"\n{'='*80}")
|
|
print(f"🧪 EJECUTANDO: {test_name}")
|
|
print(f"📋 {description}")
|
|
print(f"📁 Ruta: {test_path}")
|
|
print(f"{'='*80}")
|
|
|
|
try:
|
|
# Verificar que el archivo existe
|
|
if not test_path.exists():
|
|
print(f"❌ Error: Test no encontrado en {test_path}")
|
|
return False
|
|
|
|
# Ejecutar el test
|
|
result = subprocess.run(
|
|
[sys.executable, str(test_path)], capture_output=True, text=True, timeout=60
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
print("✅ Test ejecutado exitosamente")
|
|
print("\n📊 Salida:")
|
|
print(result.stdout)
|
|
else:
|
|
print("❌ Test falló")
|
|
print("\n📊 Error:")
|
|
print(result.stderr)
|
|
print("\n📊 Salida:")
|
|
print(result.stdout)
|
|
|
|
return result.returncode == 0
|
|
|
|
except subprocess.TimeoutExpired:
|
|
print("⏰ Test expiró (timeout 60s)")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Error ejecutando test: {e}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Función principal del test runner"""
|
|
|
|
print("🧪 TEST RUNNER - PLC S7-315 Streamer & Logger")
|
|
print("=" * 80)
|
|
print("📂 Tests organizados en directorio .tests/")
|
|
print("🎯 Ejecutando tests de validación...")
|
|
print("=" * 80)
|
|
|
|
# Lista de tests disponibles
|
|
tests = [
|
|
{
|
|
"file": "test_pe_pa_fixed.py",
|
|
"description": "Validación funcional del fix PE/PA con área 0x81/0x82",
|
|
"critical": True,
|
|
},
|
|
{
|
|
"file": "test_comparison_simple.py",
|
|
"description": "Comparación entre sistema legacy y optimizado",
|
|
"critical": False,
|
|
},
|
|
{
|
|
"file": "test_network_latency_pe_pa.py",
|
|
"description": "Demostración del impacto de latencia de red industrial",
|
|
"critical": True,
|
|
},
|
|
{
|
|
"file": "test_final_validation.py",
|
|
"description": "Validación completa de todas las áreas de memoria",
|
|
"critical": False,
|
|
},
|
|
{
|
|
"file": "test_data_integrity.py",
|
|
"description": "Verificación de integridad de datos entre métodos",
|
|
"critical": False,
|
|
},
|
|
]
|
|
|
|
# Ejecutar solo tests críticos por defecto
|
|
print("🎯 Ejecutando tests CRÍTICOS:")
|
|
|
|
critical_tests = [t for t in tests if t["critical"]]
|
|
success_count = 0
|
|
|
|
for test in critical_tests:
|
|
success = run_test(test["file"], test["description"])
|
|
if success:
|
|
success_count += 1
|
|
|
|
# Resumen
|
|
print(f"\n{'='*80}")
|
|
print("📊 RESUMEN DE EJECUCIÓN")
|
|
print(f"{'='*80}")
|
|
print(f"✅ Tests exitosos: {success_count}/{len(critical_tests)}")
|
|
print(f"🎯 Tests críticos completados")
|
|
|
|
if success_count == len(critical_tests):
|
|
print("🎉 ¡Todos los tests críticos pasaron exitosamente!")
|
|
print("💡 El sistema está listo para producción")
|
|
else:
|
|
print("⚠️ Algunos tests críticos fallaron")
|
|
print("🔧 Revisar configuración antes de usar en producción")
|
|
|
|
print(f"\n📝 NOTA:")
|
|
print(" Para ejecutar tests individuales:")
|
|
for test in tests:
|
|
print(f" python .tests/{test['file']}")
|
|
|
|
print(f"\n✅ Test runner completado!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|