anton-microscopy / test_cache_simple.py
pskeshu's picture
πŸš€ Implement progressive results display for real-time UI updates
002b4c1
#!/usr/bin/env python3
"""
Simple test for presentation mode cache
"""
import sys
from pathlib import Path
import json
# Add project root to path
sys.path.append(str(Path(__file__).parent))
def test_cache_simple():
"""Test presentation mode cache functionality."""
print("πŸ§ͺ Testing Presentation Mode Cache...")
try:
# Test cache imports
from presentation_cache import presentation_cache
print("βœ… Cache imports successful")
# Test cache availability
cached_images = presentation_cache.list_cached_images()
print(f"βœ… Cached images: {len(cached_images)}")
if cached_images:
for image_name in cached_images:
print(f" β€’ {image_name}")
# Test cache retrieval
cached_results = presentation_cache.get_cached_results(image_name)
if cached_results:
print(f" βœ… Cache retrieval successful")
# Check basic structure
stages = ["stage_1_global", "stage_2_objects", "stage_3_features", "stage_4_population"]
stage_count = sum(1 for stage in stages if stage in cached_results)
print(f" βœ… Contains {stage_count}/4 required stages")
# Check sample content
stage1 = cached_results.get("stage_1_global", {})
if stage1:
description = stage1.get("description", "")
print(f" βœ… Stage 1 description: {len(description)} chars")
stage2 = cached_results.get("stage_2_objects", {})
if stage2:
cellpose_regions = stage2.get("cellpose_regions", [])
print(f" βœ… CellPose regions: {len(cellpose_regions)}")
print()
else:
print(f" ❌ Cache retrieval failed")
else:
print("❌ No cached images found")
# Test cache status
cache_file = Path("presentation_cache/cached_results.json")
if cache_file.exists():
print(f"βœ… Cache file exists: {cache_file}")
print(f" Size: {cache_file.stat().st_size} bytes")
# Load and check cache file
with open(cache_file, 'r') as f:
cache_data = json.load(f)
print(f" Images in cache: {len(cache_data)}")
for image_name, data in cache_data.items():
print(f" β€’ {image_name}: {len(str(data))} chars")
else:
print("❌ Cache file not found")
except Exception as e:
print(f"❌ Test failed: {e}")
import traceback
traceback.print_exc()
return False
print("\nπŸŽ‰ Cache test completed successfully!")
return True
if __name__ == "__main__":
success = test_cache_simple()
sys.exit(0 if success else 1)