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()