178 lines
5.8 KiB
Python
178 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test específico para plots interactivos y resultados clickeables
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Agregar directorio actual al path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from hybrid_evaluation_engine import HybridEvaluationEngine
|
|
from interactive_results import PlotResult, InteractiveResultManager
|
|
import sympy
|
|
import tkinter as tk
|
|
|
|
|
|
def test_plot_creation():
|
|
"""Test de creación de objetos PlotResult"""
|
|
print("=== Test Creación de Plots ===")
|
|
|
|
try:
|
|
# Test creación básica de PlotResult
|
|
plot_obj = PlotResult("plot", (sympy.sin(sympy.Symbol('x')), (sympy.Symbol('x'), -10, 10)), {})
|
|
print(f"✅ PlotResult creado: {plot_obj}")
|
|
print(f" Tipo: {type(plot_obj)}")
|
|
print(f" String: {str(plot_obj)}")
|
|
print(f" Plot type: {plot_obj.plot_type}")
|
|
|
|
# Test detección como interactivo
|
|
from hybrid_evaluation_engine import EvaluationResult
|
|
result = EvaluationResult(plot_obj, "expression")
|
|
print(f"✅ is_interactive: {result.is_interactive}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error en creación de plots: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
def test_plot_evaluation():
|
|
"""Test de evaluación de expresiones plot"""
|
|
print("\n=== Test Evaluación de Plots ===")
|
|
|
|
engine = HybridEvaluationEngine()
|
|
|
|
plot_expressions = [
|
|
"plot(sin(x), (x, -2*pi, 2*pi))",
|
|
"plot(x**2, (x, -5, 5))",
|
|
"plot(cos(x), (x, 0, 2*pi))",
|
|
"Matrix([[1, 2], [3, 4]])", # También debería ser interactivo
|
|
]
|
|
|
|
for expr in plot_expressions:
|
|
try:
|
|
print(f"\nEvaluando: '{expr}'")
|
|
result = engine.evaluate_line(expr)
|
|
|
|
if result.is_error:
|
|
print(f" ❌ Error: {result.error}")
|
|
else:
|
|
print(f" ✅ Resultado: {result.result}")
|
|
print(f" Tipo: {type(result.result)}")
|
|
print(f" Es interactivo: {result.is_interactive}")
|
|
|
|
# Verificar si es PlotResult
|
|
if isinstance(result.result, PlotResult):
|
|
print(f" ✅ Es PlotResult!")
|
|
print(f" Plot type: {result.result.plot_type}")
|
|
print(f" Args: {result.result.args}")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Excepción: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
def test_interactive_manager():
|
|
"""Test del manager de resultados interactivos"""
|
|
print("\n=== Test Interactive Manager ===")
|
|
|
|
# Necesitamos una ventana tk para el manager
|
|
try:
|
|
root = tk.Tk()
|
|
root.withdraw() # Ocultar ventana
|
|
|
|
manager = InteractiveResultManager(root)
|
|
|
|
# Crear widget de texto simulado
|
|
text_widget = tk.Text(root)
|
|
|
|
# Test con PlotResult
|
|
plot_obj = PlotResult("plot", (sympy.sin(sympy.Symbol('x')), (sympy.Symbol('x'), -10, 10)), {})
|
|
|
|
interactive_info = manager.create_interactive_tag(plot_obj, text_widget, "1.0")
|
|
|
|
if interactive_info and len(interactive_info) == 2:
|
|
tag, display_text = interactive_info
|
|
print(f"✅ Tag interactivo creado: '{tag}'")
|
|
print(f" Display text: '{display_text}'")
|
|
else:
|
|
print(f"❌ No se creó tag interactivo: {interactive_info}")
|
|
|
|
# Test con Matrix
|
|
matrix = sympy.Matrix([[1, 2], [3, 4]])
|
|
interactive_info2 = manager.create_interactive_tag(matrix, text_widget, "2.0")
|
|
|
|
if interactive_info2 and len(interactive_info2) == 2:
|
|
tag2, display_text2 = interactive_info2
|
|
print(f"✅ Tag para matriz creado: '{tag2}'")
|
|
print(f" Display text: '{display_text2}'")
|
|
else:
|
|
print(f"❌ No se creó tag para matriz: {interactive_info2}")
|
|
|
|
root.destroy()
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error en test de manager: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
def test_full_workflow():
|
|
"""Test del flujo completo: evaluación → resultado interactivo"""
|
|
print("\n=== Test Flujo Completo ===")
|
|
|
|
try:
|
|
root = tk.Tk()
|
|
root.withdraw()
|
|
|
|
# Simular el flujo de la aplicación
|
|
engine = HybridEvaluationEngine()
|
|
manager = InteractiveResultManager(root)
|
|
text_widget = tk.Text(root)
|
|
|
|
# Evaluar plot
|
|
result = engine.evaluate_line("plot(sin(x), (x, -pi, pi))")
|
|
|
|
print(f"Resultado evaluación: {result.result} (tipo: {type(result.result)})")
|
|
print(f"Es interactivo: {result.is_interactive}")
|
|
|
|
if result.is_interactive:
|
|
interactive_info = manager.create_interactive_tag(
|
|
result.result, text_widget, "1.0"
|
|
)
|
|
|
|
if interactive_info and len(interactive_info) == 2:
|
|
tag, display_text = interactive_info
|
|
print(f"✅ ÉXITO: Tag '{tag}' con texto '{display_text}'")
|
|
else:
|
|
print(f"❌ FALLO: No se creó tag interactivo")
|
|
else:
|
|
print("❌ FALLO: Resultado no marcado como interactivo")
|
|
|
|
root.destroy()
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error en flujo completo: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
def main():
|
|
"""Función principal de testing"""
|
|
print("Test de Plots Interactivos - Calculadora MAV")
|
|
print("=" * 50)
|
|
|
|
test_plot_creation()
|
|
test_plot_evaluation()
|
|
test_interactive_manager()
|
|
test_full_workflow()
|
|
|
|
print("\n" + "=" * 50)
|
|
print("Testing completado.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|