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