Spaces:
Sleeping
Sleeping
File size: 4,649 Bytes
002b4c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #!/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) |