Spaces:
Sleeping
Sleeping
| #!/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) |