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