-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_thumbnail_cache.py
More file actions
84 lines (69 loc) · 2.33 KB
/
Copy pathverify_thumbnail_cache.py
File metadata and controls
84 lines (69 loc) · 2.33 KB
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
import os
import sys
import time
import shutil
# Ensure we can import core modules
sys.path.append(os.getcwd())
from core.thumbnail_cache import PersistentThumbnailCache
def verify_cache():
print("Testing PersistentThumbnailCache...")
# Use a temporary DB file
db_path = "test_thumbnails.db"
if os.path.exists(db_path):
os.remove(db_path)
cache = PersistentThumbnailCache(db_path=db_path)
# Test Data
test_path = os.path.abspath("test_image.jpg")
test_mtime = 123456789
test_size = 1024
test_width = 100
test_height = 100
test_data = b"fake_jpeg_data"
# 1. Put
print("1. Testing PUT...")
cache.put(test_path, test_mtime, test_size, test_width, test_height, test_data)
# 2. Get (Hit)
print("2. Testing GET (Hit)...")
retrieved = cache.get(test_path, test_mtime, test_size)
if retrieved == test_data:
print(" PASS: Data retrieved correctly.")
else:
print(f" FAIL: Retrieved data mismatch. Got {retrieved}")
return False
# 3. Get (Miss - wrong mtime)
print("3. Testing GET (Miss - Modified file)...")
miss = cache.get(test_path, test_mtime + 1, test_size)
if miss is None:
print(" PASS: Correctly returned None for modified mtime.")
else:
print(" FAIL: Should have missed.")
return False
# 4. Get (Miss - wrong size)
print("4. Testing GET (Miss - Resized file)...")
miss = cache.get(test_path, test_mtime, test_size + 1)
if miss is None:
print(" PASS: Correctly returned None for modified size.")
else:
print(" FAIL: Should have missed.")
return False
# 5. Persistence (Close and Reopen)
print("5. Testing Persistence...")
del cache
cache2 = PersistentThumbnailCache(db_path=db_path)
retrieved2 = cache2.get(test_path, test_mtime, test_size)
if retrieved2 == test_data:
print(" PASS: Data persisted after reload.")
else:
print(" FAIL: Persistence failed.")
return False
# Cleanup
if os.path.exists(db_path):
try:
os.remove(db_path)
except:
pass
print("\nSUCCESS: PersistentThumbnailCache verified!")
return True
if __name__ == "__main__":
success = verify_cache()
sys.exit(0 if success else 1)