#!/usr/bin/env python3 """ Test presentation mode functionality """ import sys from pathlib import Path import json # Add project root to path sys.path.append(str(Path(__file__).parent)) def test_presentation_mode(): """Test presentation mode functionality.""" print("๐Ÿงช Testing Presentation Mode Functionality...") try: # Test cache imports from presentation_cache import presentation_cache from presentation_mode import presentation_manager, is_presentation_mode_available print("โœ… Imports successful") # Test cache availability available = is_presentation_mode_available() print(f"โœ… Presentation mode available: {available}") if available: # Test cache contents cached_images = presentation_cache.list_cached_images() print(f"โœ… Cached images: {len(cached_images)}") for image_name in cached_images: print(f" โ€ข {image_name}") # Test presentation manager presentation_manager.enable_presentation_mode() print(f"โœ… Presentation manager enabled: {presentation_manager.is_presentation_mode}") # Test demo images info demo_images = presentation_manager.get_available_demo_images() print(f"โœ… Demo images available: {len(demo_images)}") for demo_img in demo_images: print(f" โ€ข {demo_img['name']} - {demo_img['protein']}") # Test cache retrieval if cached_images: test_image = cached_images[0] print(f"\n๐Ÿ” Testing cache retrieval for: {test_image}") cached_results = presentation_cache.get_cached_results(test_image) if cached_results: print("โœ… Cache retrieval successful") # Check result structure stages = ["stage_1_global", "stage_2_objects", "stage_3_features", "stage_4_population"] for stage in stages: if stage in cached_results: print(f" โœ… {stage} - Present") else: print(f" โŒ {stage} - Missing") # Test presentation mode analysis print(f"\n๐ŸŽฏ Testing presentation mode analysis...") try: results, processing_time = presentation_manager.run_presentation_analysis(test_image) print(f"โœ… Analysis successful - simulated time: {processing_time:.1f}s") # Check if results have presentation mode metadata if "_presentation_mode" in results: print("โœ… Presentation mode metadata present") else: print("โŒ Presentation mode metadata missing") except Exception as e: print(f"โŒ Analysis failed: {e}") else: print("โŒ Cache retrieval failed") # Test cache status cache_status = presentation_manager.get_cache_status() print(f"\n๐Ÿ“Š Cache Status:") print(f" โ€ข Total samples: {cache_status['total_samples']}") print(f" โ€ข Cached samples: {cache_status['cached_samples']}") print(f" โ€ข Coverage: {cache_status['cache_coverage']:.1%}") print(f" โ€ข Ready: {cache_status['presentation_mode_ready']}") # Test cache validation validation = presentation_manager.validate_cache_integrity() print(f"\n๐Ÿ” Cache Validation:") print(f" โ€ข Valid caches: {len(validation['valid_caches'])}") print(f" โ€ข Invalid caches: {len(validation['invalid_caches'])}") print(f" โ€ข Overall status: {validation['overall_status']}") else: print("โŒ Presentation mode not available - no cached results") except Exception as e: print(f"โŒ Test failed: {e}") import traceback traceback.print_exc() return False print("\n๐ŸŽ‰ Presentation mode test completed successfully!") return True if __name__ == "__main__": success = test_presentation_mode() sys.exit(0 if success else 1)