File size: 3,165 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
#!/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)