""" Validation script for Streamlit dashboard setup. Checks that all components can be imported and basic functionality works. """ import sys from pathlib import Path # Add project root to path project_root = Path(__file__).parent.parent sys.path.insert(0, str(project_root)) def test_imports(): """Test that all Streamlit components can be imported.""" print("๐Ÿ” Testing component imports...") try: from streamlit_app.components.file_upload import FileUploadComponent print("โœ… FileUploadComponent imported successfully") except ImportError as e: print(f"โŒ Failed to import FileUploadComponent: {e}") return False try: from streamlit_app.components.business_context import BusinessContextForm print("โœ… BusinessContextForm imported successfully") except ImportError as e: print(f"โŒ Failed to import BusinessContextForm: {e}") return False try: from streamlit_app.components.progress_monitor import ProgressMonitor print("โœ… ProgressMonitor imported successfully") except ImportError as e: print(f"โŒ Failed to import ProgressMonitor: {e}") return False try: from streamlit_app.components.results_viewer import ResultsViewer print("โœ… ResultsViewer imported successfully") except ImportError as e: print(f"โŒ Failed to import ResultsViewer: {e}") return False try: from streamlit_app.components.session_manager import SessionManagerComponent print("โœ… SessionManagerComponent imported successfully") except ImportError as e: print(f"โŒ Failed to import SessionManagerComponent: {e}") return False try: from streamlit_app.components.auth import AuthManager print("โœ… AuthManager imported successfully") except ImportError as e: print(f"โŒ Failed to import AuthManager: {e}") return False try: from streamlit_app.utils.api_client import APIClient print("โœ… APIClient imported successfully") except ImportError as e: print(f"โŒ Failed to import APIClient: {e}") return False try: from streamlit_app.utils.sse_client import SSEClient print("โœ… SSEClient imported successfully") except ImportError as e: print(f"โŒ Failed to import SSEClient: {e}") return False return True def test_component_initialization(): """Test that components can be initialized.""" print("\n๐Ÿ”ง Testing component initialization...") try: from streamlit_app.components.file_upload import FileUploadComponent component = FileUploadComponent() assert hasattr(component, 'supported_formats') assert hasattr(component, 'max_size_mb') print("โœ… FileUploadComponent initializes correctly") except Exception as e: print(f"โŒ FileUploadComponent initialization failed: {e}") return False try: from streamlit_app.components.business_context import BusinessContextForm component = BusinessContextForm() assert hasattr(component, 'context_templates') assert len(component.context_templates) > 0 print("โœ… BusinessContextForm initializes correctly") except Exception as e: print(f"โŒ BusinessContextForm initialization failed: {e}") return False try: from streamlit_app.components.results_viewer import ResultsViewer component = ResultsViewer() assert hasattr(component, 'chart_colors') print("โœ… ResultsViewer initializes correctly") except Exception as e: print(f"โŒ ResultsViewer initialization failed: {e}") return False try: from streamlit_app.utils.api_client import APIClient client = APIClient("http://test.com") assert client.base_url == "http://test.com" assert hasattr(client, 'session') print("โœ… APIClient initializes correctly") except Exception as e: print(f"โŒ APIClient initialization failed: {e}") return False return True def test_component_methods(): """Test that key component methods work.""" print("\nโš™๏ธ Testing component methods...") try: from streamlit_app.components.file_upload import FileUploadComponent from unittest.mock import Mock component = FileUploadComponent() # Test file validation with mock file mock_file = Mock() mock_file.name = "test.txt" # Unsupported format mock_file.getvalue.return_value = b"small file" result = component._validate_file(mock_file) assert not result["valid"] assert "Unsupported file format" in result["error"] print("โœ… FileUploadComponent validation works") except Exception as e: print(f"โŒ FileUploadComponent method test failed: {e}") return False try: from streamlit_app.components.business_context import BusinessContextForm component = BusinessContextForm() # Test response validation insufficient_responses = {"question_1": "short", "question_2": ""} result = component._validate_responses(insufficient_responses) assert not result sufficient_responses = { "question_1": "This is a long enough response for validation", "question_2": "Another sufficiently long response for testing" } result = component._validate_responses(sufficient_responses) assert result print("โœ… BusinessContextForm validation works") except Exception as e: print(f"โŒ BusinessContextForm method test failed: {e}") return False try: from streamlit_app.utils.api_client import APIClient from unittest.mock import patch client = APIClient("http://test.com") # Test header generation (without Streamlit context) headers = client._get_headers() assert "Content-Type" in headers assert headers["Content-Type"] == "application/json" print("โœ… APIClient methods work") except Exception as e: print(f"โŒ APIClient method test failed: {e}") return False return True def test_requirements_compliance(): """Test that implementation meets the specified requirements.""" print("\n๐Ÿ“‹ Testing requirements compliance...") # Requirement 10.1: Intuitive Streamlit-based dashboard try: from streamlit_app.main import main, render_main_dashboard print("โœ… Main dashboard functions exist") except ImportError: print("โŒ Main dashboard functions missing") return False # Requirement 10.2: Upload progress and validation in real-time try: from streamlit_app.components.file_upload import FileUploadComponent component = FileUploadComponent() assert hasattr(component, '_validate_file') assert hasattr(component, '_display_file_info') print("โœ… File upload with validation implemented") except Exception as e: print(f"โŒ File upload validation missing: {e}") return False # Requirement 10.3: Progress indicators and intermediate results try: from streamlit_app.components.progress_monitor import ProgressMonitor from unittest.mock import Mock monitor = ProgressMonitor(Mock(), Mock()) assert hasattr(monitor, 'stages') assert len(monitor.stages) > 0 print("โœ… Progress monitoring implemented") except Exception as e: print(f"โŒ Progress monitoring missing: {e}") return False # Requirement 10.4: Clear visualization of insights and recommendations try: from streamlit_app.components.results_viewer import ResultsViewer viewer = ResultsViewer() assert hasattr(viewer, '_render_business_insights') assert hasattr(viewer, '_render_model_performance') print("โœ… Results visualization implemented") except Exception as e: print(f"โŒ Results visualization missing: {e}") return False # Requirement 10.5: Interactive controls for customization try: # Check that enhanced parameter controls exist in main.py with open(project_root / "streamlit_app" / "main.py", "r", encoding="utf-8") as f: content = f.read() interactive_controls = [ "st.slider", "st.selectbox", "st.multiselect", "st.checkbox", "st.number_input" ] controls_found = sum(1 for control in interactive_controls if control in content) assert controls_found >= 3, f"Only {controls_found} interactive controls found" print("โœ… Interactive parameter controls implemented") except Exception as e: print(f"โŒ Interactive controls missing: {e}") return False return True def main(): """Run all validation tests.""" print("๐Ÿงช Streamlit Dashboard Validation") print("=" * 50) tests = [ ("Component Imports", test_imports), ("Component Initialization", test_component_initialization), ("Component Methods", test_component_methods), ("Requirements Compliance", test_requirements_compliance) ] results = [] for test_name, test_func in tests: print(f"\n๐Ÿ” Running {test_name}...") try: success = test_func() results.append((test_name, success)) except Exception as e: print(f"โŒ {test_name} failed with exception: {e}") results.append((test_name, False)) # Summary print("\n" + "=" * 50) print("๐Ÿ“Š Validation Results:") all_passed = True for test_name, success in results: status = "โœ… PASSED" if success else "โŒ FAILED" print(f" {test_name}: {status}") if not success: all_passed = False print(f"\n๐ŸŽฏ Overall Result: {'โœ… ALL TESTS PASSED' if all_passed else 'โŒ SOME TESTS FAILED'}") if all_passed: print("\n๐ŸŽ‰ Streamlit dashboard is ready for use!") print("๐Ÿ“ To run the dashboard: streamlit run streamlit_app/main.py") else: print("\nโš ๏ธ Please fix the failing tests before using the dashboard.") return all_passed if __name__ == "__main__": success = main() sys.exit(0 if success else 1)