#!/usr/bin/env python3 """ Test script for UI fixes: connection counting, canvas cleanup, and global status bar. Tests the latest improvements to the dashboard interface. """ import sys import os # Add parent directory to path current_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.dirname(current_dir) sys.path.insert(0, parent_dir) def test_connection_counting(): """Test improved connection counting logic.""" print("šŸ” Testing connection counting improvements...") try: from cluster4npu_ui.ui.windows.dashboard import IntegratedPipelineDashboard # Check if the updated analyze_pipeline method exists if hasattr(IntegratedPipelineDashboard, 'analyze_pipeline'): print("āœ… analyze_pipeline method exists") # Read the source to verify improved connection counting import inspect source = inspect.getsource(IntegratedPipelineDashboard.analyze_pipeline) # Check for improved connection counting logic if 'output_ports' in source and 'connected_ports' in source: print("āœ… Improved connection counting logic found") else: print("āš ļø Connection counting logic may need verification") # Check for error handling in connection counting if 'try:' in source and 'except Exception:' in source: print("āœ… Error handling in connection counting") else: print("āŒ analyze_pipeline method missing") return False return True except Exception as e: print(f"āŒ Connection counting test failed: {e}") return False def test_canvas_cleanup(): """Test canvas cleanup (logo removal).""" print("\nšŸ” Testing canvas cleanup...") try: from cluster4npu_ui.ui.windows.dashboard import IntegratedPipelineDashboard # Check if the setup_node_graph method has logo removal code if hasattr(IntegratedPipelineDashboard, 'setup_node_graph'): print("āœ… setup_node_graph method exists") # Check source for logo removal logic import inspect source = inspect.getsource(IntegratedPipelineDashboard.setup_node_graph) if 'set_logo_visible' in source or 'show_logo' in source: print("āœ… Logo removal logic found") else: print("āš ļø Logo removal logic may need verification") if 'set_grid_mode' in source or 'grid_mode' in source: print("āœ… Grid mode configuration found") else: print("āŒ setup_node_graph method missing") return False return True except Exception as e: print(f"āŒ Canvas cleanup test failed: {e}") return False def test_global_status_bar(): """Test global status bar spanning full width.""" print("\nšŸ” Testing global status bar...") try: from cluster4npu_ui.ui.windows.dashboard import IntegratedPipelineDashboard # Check if setup_integrated_ui has global status bar if hasattr(IntegratedPipelineDashboard, 'setup_integrated_ui'): print("āœ… setup_integrated_ui method exists") # Check source for global status bar import inspect source = inspect.getsource(IntegratedPipelineDashboard.setup_integrated_ui) if 'global_status_bar' in source: print("āœ… Global status bar found") else: print("āš ļø Global status bar may need verification") if 'main_layout.addWidget' in source: print("āœ… Status bar added to main layout") else: print("āŒ setup_integrated_ui method missing") return False # Check if create_status_bar_widget exists if hasattr(IntegratedPipelineDashboard, 'create_status_bar_widget'): print("āœ… create_status_bar_widget method exists") # Check source for full-width styling import inspect source = inspect.getsource(IntegratedPipelineDashboard.create_status_bar_widget) if 'border-top' in source and 'background-color' in source: print("āœ… Full-width status bar styling found") else: print("āŒ create_status_bar_widget method missing") return False return True except Exception as e: print(f"āŒ Global status bar test failed: {e}") return False def test_stage_count_widget_updates(): """Test StageCountWidget updates for global status bar.""" print("\nšŸ” Testing StageCountWidget updates...") try: from cluster4npu_ui.ui.windows.dashboard import StageCountWidget from PyQt5.QtWidgets import QApplication app = QApplication.instance() if app is None: app = QApplication([]) # Create widget widget = StageCountWidget() print("āœ… StageCountWidget created successfully") # Test size for global status bar size = widget.size() if size.width() == 120 and size.height() == 22: print(f"āœ… Correct size for global status bar: {size.width()}x{size.height()}") else: print(f"āš ļø Size may need adjustment: {size.width()}x{size.height()}") # Test status updates widget.update_stage_count(0, True, "") print("āœ… Zero stages update test") widget.update_stage_count(2, True, "") print("āœ… Valid stages update test") widget.update_stage_count(1, False, "Test error") print("āœ… Error state update test") return True except Exception as e: print(f"āŒ StageCountWidget test failed: {e}") return False def test_layout_structure(): """Test that the layout structure is correct.""" print("\nšŸ” Testing layout structure...") try: from cluster4npu_ui.ui.windows.dashboard import IntegratedPipelineDashboard # Check if create_pipeline_editor_panel no longer has status bar if hasattr(IntegratedPipelineDashboard, 'create_pipeline_editor_panel'): print("āœ… create_pipeline_editor_panel method exists") # Check that it doesn't create its own status bar import inspect source = inspect.getsource(IntegratedPipelineDashboard.create_pipeline_editor_panel) if 'create_status_bar_widget' not in source: print("āœ… Pipeline editor panel no longer creates its own status bar") else: print("āš ļø Pipeline editor panel may still create status bar") else: print("āŒ create_pipeline_editor_panel method missing") return False return True except Exception as e: print(f"āŒ Layout structure test failed: {e}") return False def run_all_tests(): """Run all UI fix tests.""" print("šŸš€ Starting UI fixes tests...\n") tests = [ test_connection_counting, test_canvas_cleanup, test_global_status_bar, test_stage_count_widget_updates, test_layout_structure ] passed = 0 total = len(tests) for test_func in tests: try: if test_func(): passed += 1 else: print(f"āŒ Test {test_func.__name__} failed") except Exception as e: print(f"āŒ Test {test_func.__name__} raised exception: {e}") print(f"\nšŸ“Š Test Results: {passed}/{total} tests passed") if passed == total: print("šŸŽ‰ All UI fixes tests passed!") print("\nšŸ“‹ Summary of fixes:") print(" āœ… Connection counting improved to handle different port types") print(" āœ… Canvas logo/icon in bottom-left corner removed") print(" āœ… Status bar now spans full width across all panels") print(" āœ… StageCountWidget optimized for global status bar") print(" āœ… Layout structure cleaned up") return True else: print("āŒ Some UI fixes tests failed.") return False if __name__ == "__main__": success = run_all_tests() sys.exit(0 if success else 1)