212 lines
6.9 KiB
Python
212 lines
6.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script de prueba para la versión PySide6 de Calculadora MAV
|
|
"""
|
|
import sys
|
|
import traceback
|
|
from pathlib import Path
|
|
|
|
def test_imports():
|
|
"""Prueba todas las importaciones necesarias"""
|
|
print("🧪 Probando importaciones...")
|
|
|
|
tests = [
|
|
("PySide6.QtWidgets", "QApplication"),
|
|
("PySide6.QtCore", "QThread"),
|
|
("PySide6.QtGui", "QFont"),
|
|
("PySide6.QtWebEngineWidgets", "QWebEngineView"),
|
|
("sympy", None),
|
|
("numpy", None),
|
|
("matplotlib", None),
|
|
]
|
|
|
|
success_count = 0
|
|
for module, attr in tests:
|
|
try:
|
|
if attr:
|
|
mod = __import__(module, fromlist=[attr])
|
|
getattr(mod, attr)
|
|
else:
|
|
__import__(module)
|
|
print(f" ✅ {module}" + (f".{attr}" if attr else ""))
|
|
success_count += 1
|
|
except ImportError as e:
|
|
print(f" ❌ {module}" + (f".{attr}" if attr else "") + f" - {e}")
|
|
except Exception as e:
|
|
print(f" ⚠️ {module}" + (f".{attr}" if attr else "") + f" - {e}")
|
|
|
|
print(f"\n📊 Resultado: {success_count}/{len(tests)} módulos disponibles")
|
|
return success_count == len(tests)
|
|
|
|
def test_application_creation():
|
|
"""Prueba la creación básica de la aplicación"""
|
|
print("\n🏗️ Probando creación de aplicación...")
|
|
|
|
try:
|
|
from PySide6.QtWidgets import QApplication
|
|
from PySide6.QtCore import QCoreApplication
|
|
|
|
# Crear aplicación mínima
|
|
if not QCoreApplication.instance():
|
|
app = QApplication([])
|
|
else:
|
|
app = QCoreApplication.instance()
|
|
|
|
print(" ✅ QApplication creada correctamente")
|
|
|
|
# Probar importación de nuestra aplicación
|
|
from main_calc_app_pyside6 import HybridCalculatorPySide6
|
|
print(" ✅ Clase HybridCalculatorPySide6 importada")
|
|
|
|
# Probar creación de ventana (sin mostrar)
|
|
window = HybridCalculatorPySide6()
|
|
print(" ✅ Ventana principal creada")
|
|
|
|
# Verificar componentes principales
|
|
assert hasattr(window, 'input_text'), "input_text no encontrado"
|
|
assert hasattr(window, 'output_text'), "output_text no encontrado"
|
|
assert hasattr(window, 'latex_panel'), "latex_panel no encontrado"
|
|
assert hasattr(window, 'engine'), "engine no encontrado"
|
|
print(" ✅ Componentes principales verificados")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_engine_functionality():
|
|
"""Prueba la funcionalidad del motor de cálculo"""
|
|
print("\n⚙️ Probando motor de cálculo...")
|
|
|
|
try:
|
|
from main_evaluation_puro import PureAlgebraicEngine
|
|
|
|
engine = PureAlgebraicEngine()
|
|
print(" ✅ Motor PureAlgebraicEngine creado")
|
|
|
|
# Prueba básica
|
|
result = engine.evaluate_line("2 + 2")
|
|
print(f" ✅ Evaluación básica: 2 + 2 = {result.output if result.success else result.error_message}")
|
|
|
|
# Prueba simbólica
|
|
result = engine.evaluate_line("x**2 + y**2")
|
|
print(f" ✅ Evaluación simbólica: x**2 + y**2 = {result.output if result.success else result.error_message}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_mathjax_html():
|
|
"""Prueba la generación de HTML MathJax"""
|
|
print("\n📐 Probando generación MathJax...")
|
|
|
|
try:
|
|
from main_calc_app_pyside6 import MathJaxPanel
|
|
from PySide6.QtWidgets import QApplication
|
|
from PySide6.QtCore import QCoreApplication
|
|
|
|
if not QCoreApplication.instance():
|
|
app = QApplication([])
|
|
|
|
panel = MathJaxPanel()
|
|
print(" ✅ Panel MathJax creado")
|
|
|
|
# Verificar HTML base
|
|
html = panel.generate_base_html()
|
|
assert "MathJax" in html, "MathJax no encontrado en HTML"
|
|
assert "equation" in html, "Estilos de ecuación no encontrados"
|
|
print(" ✅ HTML base generado correctamente")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def run_minimal_app():
|
|
"""Ejecuta una versión mínima de la aplicación para prueba visual"""
|
|
print("\n🖥️ Iniciando prueba visual (cierra la ventana para continuar)...")
|
|
|
|
try:
|
|
from PySide6.QtWidgets import QApplication
|
|
from main_calc_app_pyside6 import HybridCalculatorPySide6
|
|
|
|
app = QApplication(sys.argv)
|
|
window = HybridCalculatorPySide6()
|
|
|
|
# Precargar algunos datos de prueba
|
|
window.input_text.setPlainText("# Prueba PySide6\nx**2 + y**2 = r**2\nsolve(x**2 - 4, x)")
|
|
|
|
window.show()
|
|
print(" ✅ Aplicación mostrada - cierra la ventana para continuar")
|
|
|
|
# No ejecutar el loop principal, solo mostrar
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def main():
|
|
"""Función principal de pruebas"""
|
|
print("🚀 Iniciando pruebas de Calculadora MAV PySide6")
|
|
print("=" * 60)
|
|
|
|
tests = [
|
|
("Importaciones", test_imports),
|
|
("Creación de aplicación", test_application_creation),
|
|
("Motor de cálculo", test_engine_functionality),
|
|
("HTML MathJax", test_mathjax_html),
|
|
]
|
|
|
|
results = []
|
|
for test_name, test_func in tests:
|
|
try:
|
|
result = test_func()
|
|
results.append((test_name, result))
|
|
except Exception as e:
|
|
print(f"💥 Error inesperado en {test_name}: {e}")
|
|
results.append((test_name, False))
|
|
|
|
# Resumen de resultados
|
|
print("\n" + "=" * 60)
|
|
print("📋 RESUMEN DE PRUEBAS")
|
|
print("=" * 60)
|
|
|
|
passed = 0
|
|
total = len(results)
|
|
|
|
for test_name, success in results:
|
|
status = "✅ PASÓ" if success else "❌ FALLÓ"
|
|
print(f" {status:<10} {test_name}")
|
|
if success:
|
|
passed += 1
|
|
|
|
print(f"\n📊 Resultado final: {passed}/{total} pruebas pasaron")
|
|
|
|
if passed == total:
|
|
print("🎉 ¡Todas las pruebas pasaron! La aplicación está lista.")
|
|
|
|
# Ofrecer ejecutar prueba visual
|
|
try:
|
|
response = input("\n¿Quieres ejecutar una prueba visual? (s/N): ").strip().lower()
|
|
if response in ['s', 'sí', 'si', 'y', 'yes']:
|
|
run_minimal_app()
|
|
except KeyboardInterrupt:
|
|
print("\n🚪 Prueba cancelada por el usuario")
|
|
|
|
else:
|
|
print("⚠️ Algunas pruebas fallaron. Revisa los errores antes de ejecutar la aplicación.")
|
|
return 1
|
|
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |