File size: 1,686 Bytes
f2e524e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6919bb
f2e524e
 
 
 
 
c6919bb
f2e524e
 
 
 
 
 
 
 
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
from src.analyzer import ImageAnalyzer
import json

def test_legacy_separation():
    analyzer = ImageAnalyzer()
    
    # Mock data with mixed poor quality types
    site_data = {
        "https://example.com/mixed": [
            {"src": "bad1.jpg", "alt": "logo"},              # BAD: Generic
            {"src": "bad2.jpg", "alt": "product-123.jpg"},   # BAD: Filename
            {"src": "bad3.jpg", "alt": "a"},                 # BAD: Short (Legacy short)
            {"src": "bad4.jpg", "alt": "ok"},                # BAD: Short (Legacy short)
            {"src": "bad5.jpg", "alt": "one"},               # BAD: Sparse (Legacy short)
            {"src": "good.jpg", "alt": "Great Product Photo"}, # GOOD
        ]
    }
    
    print("Running Legacy Separation Test...")
    report = analyzer.analyze_site(site_data)
    
    print("--- Summary ---")
    print(json.dumps(report['summary'], indent=2))
    
    print("\n--- Checking for keys ---")
    details = report['details'][0]
    
    if "images_with_short_alt" not in details:
        print("SUCCESS: 'images_with_short_alt' key is ABSENT.")
    else:
        print("FAILURE: 'images_with_short_alt' key is PRESENT.")
        exit(1)
        
    if "short_alt_count" not in details:
        print("SUCCESS: 'short_alt_count' key is ABSENT.")
    else:
        print("FAILURE: 'short_alt_count' key is PRESENT.")
        exit(1)
        
    print(f"\nPoor Quality Count: {details['poor_quality_count']}")
    print("\n--- Poor Quality List Content ---")
    for img in details['images_with_poor_alt']:
        print(f"  [{img['reason']}] {img['alt']}")
        
if __name__ == "__main__":
    test_legacy_separation()