""" Test 5: Modular Application Structure (Simplified) Purpose: Test multi-file imports in Container Runtime """ import streamlit as st import sys import os # Page configuration st.set_page_config( page_title="Spark POC - Modular Test", page_icon="🏗️", layout="wide" ) st.title("🏗️ Spark POC - Modular Structure Test") st.write("Testing multi-file application architecture in Container Runtime") # Test 5.1: Environment Check st.header("Test 5.1: Environment Analysis") col1, col2 = st.columns(2) with col1: st.subheader("Current Directory") current_dir = os.getcwd() st.write(f"**Working Directory**: {current_dir}") # List Python files in current directory try: python_files = [f for f in os.listdir('.') if f.endswith('.py')] st.write("**Python files found:**") for file in python_files: st.write(f"- {file}") except Exception as e: st.error(f"Error listing files: {e}") with col2: st.subheader("Python Path") st.write("**Python path (first 5 entries):**") for i, path in enumerate(sys.path[:5]): st.write(f"{i+1}. {path}") # Test 5.2: Module Import Test st.header("Test 5.2: Module Import Testing") import_results = {} # Test importing database module st.subheader("Database Module Import") try: import database import_results['database'] = "✅ Success" st.success("✅ Database module imported successfully") # Test a function from database module try: config = database.get_config() st.write("**Database config loaded:**") st.json(config) except Exception as e: st.warning(f"Database function test failed: {e}") except ImportError as e: import_results['database'] = f"❌ Failed: {str(e)}" st.error(f"❌ Database module import failed: {str(e)}") except Exception as e: import_results['database'] = f"❌ Error: {str(e)}" st.error(f"❌ Database module error: {str(e)}") # Test importing data_processor module st.subheader("Data Processor Module Import") try: import data_processor import_results['data_processor'] = "✅ Success" st.success("✅ Data processor module imported successfully") # Test a function from data_processor module try: # Test with simple mock data mock_videos = [ {'video_id': 'test1', 'creator': 'user1', 'views': 1000, 'likes': 50, 'shares': 5, 'hearts': 45} ] processed_df = data_processor.process_video_data(mock_videos) st.write(f"**Data processing test**: Processed {len(processed_df)} records") st.dataframe(processed_df) except Exception as e: st.warning(f"Data processor function test failed: {e}") except ImportError as e: import_results['data_processor'] = f"❌ Failed: {str(e)}" st.error(f"❌ Data processor module import failed: {str(e)}") except Exception as e: import_results['data_processor'] = f"❌ Error: {str(e)}" st.error(f"❌ Data processor module error: {str(e)}") # Test 5.3: Cross-Module Integration st.header("Test 5.3: Integration Test") if all('Success' in result for result in import_results.values()): if st.button("Run Integration Test"): try: # Get sample songs from database module songs_df = database.get_sample_songs() st.write(f"✅ Step 1: Loaded {len(songs_df)} songs from database") # Process mock video data with data_processor module mock_videos = [ {'video_id': f'vid_{i}', 'creator': f'creator_{i}', 'views': 1000 + i*100, 'likes': 50 + i*5, 'shares': 5 + i, 'hearts': 40 + i*4} for i in range(3) ] processed_videos = data_processor.process_video_data(mock_videos) analytics = data_processor.calculate_analytics(processed_videos) st.write(f"✅ Step 2: Processed {len(processed_videos)} videos") st.write(f"✅ Step 3: Analytics - {analytics['total_videos']} videos, {analytics['total_views']} total views") st.success("🎉 Integration test successful!") except Exception as e: st.error(f"Integration test failed: {str(e)}") st.write("**Error details:**") st.exception(e) else: st.warning("Integration test requires all modules to import successfully") # Test Results Summary st.header("🔍 Test Results Summary") test_results = { "Environment Check": "✅ Working", "Database Module": import_results.get('database', 'Not tested'), "Data Processor Module": import_results.get('data_processor', 'Not tested'), "Module Integration": "✅ Ready" if all('Success' in result for result in import_results.values()) else "⚠️ Blocked by imports" } for test, status in test_results.items(): if "Success" in status: st.write(f"**{test}**: ✅ Success") elif "Failed" in status or "Error" in status: st.write(f"**{test}**: ❌ Failed") else: st.write(f"**{test}**: {status}") # Diagnostic Information st.header("🔍 Diagnostic Information") st.subheader("Import Results Details") for module, result in import_results.items(): st.write(f"**{module}**: {result}") st.subheader("File System Debug") try: # Check what files are actually available all_files = os.listdir('.') st.write(f"**Total files in directory**: {len(all_files)}") # Show first 20 files st.write("**Files (first 20):**") for file in all_files[:20]: file_size = os.path.getsize(file) if os.path.isfile(file) else 0 st.write(f"- {file} ({file_size} bytes)") if len(all_files) > 20: st.write(f"... and {len(all_files) - 20} more files") except Exception as e: st.error(f"File system debug failed: {e}") # Container Runtime Notes st.header("📝 Container Runtime Notes") if all('Success' in result for result in import_results.values()): st.success(""" ✅ **Modular Structure Validated!** Container Runtime successfully supports: - Multi-file Python applications - Cross-module imports and function calls - Shared data processing between modules This confirms the POC can use a modular architecture with separate modules for database access, data processing, and API integration. """) else: st.warning(""" ⚠️ **Modular Structure Needs Attention** Some modules failed to import. This could be due to: - Missing files in the stage - Import path issues in Container Runtime - Module dependency problems Check the diagnostic information above for details. """) st.text_area( "Additional observations:", placeholder="Record any observations about module loading, performance, or behavior...", height=100 )