prince1604
Enhance API stability: Add KeepAlive, increase timeout, and optimize crawler threads
f2e524e | from src.analyzer import ImageAnalyzer | |
| import json | |
| def test_analyzer(): | |
| analyzer = ImageAnalyzer() | |
| # Mock data with focused Generic / Filler cases | |
| site_data = { | |
| "https://example.com/test-generic": [ | |
| {"src": "g1.jpg", "alt": "logo"}, # BAD: Exact generic | |
| {"src": "g2.jpg", "alt": "image"}, # BAD: Exact generic | |
| {"src": "g3.jpg", "alt": "company logo"}, # BAD: Short partial generic (< 3 words) | |
| {"src": "g4.jpg", "alt": "header banner"}, # BAD: Short partial generic (< 3 words) | |
| {"src": "g5.jpg", "alt": "Eminent Tactiles Logo"}, # GOOD: Long partial generic (>= 3 words) | |
| {"src": "g6.jpg", "alt": "Product Thumbnail View"}, # GOOD: Long partial generic (>= 3 words) | |
| {"src": "g7.jpg", "alt": "placeholder icon"}, # BAD: Short partial generic | |
| {"src": "g8.jpg", "alt": "unique identifier"}, # BAD: Too few words (caught by logic C, safe check) | |
| {"src": "g9.jpg", "alt": "My Photo"}, # BAD: Short partial generic | |
| ] | |
| } | |
| print("Running Generic Term Analyzer Test...") | |
| report = analyzer.analyze_site(site_data) | |
| # Extract just the poor quality logic results for clarity | |
| results = [] | |
| for img in report['details'][0]['images_with_poor_alt']: | |
| results.append(f"ALT: '{img['alt']}' -> REASON: {img['reason']}") | |
| for res in results: | |
| print(res) | |
| if __name__ == "__main__": | |
| test_analyzer() | |