Spaces:
Build error
Build error
| import pytest | |
| from image_processor.analyzer import ImageAnalyzer | |
| from PIL import Image | |
| import numpy as np | |
| import logging | |
| def sample_image(): | |
| return Image.fromarray(np.random.randint(0, 255, (512, 512, 3), 'RGB') | |
| def test_initialization(): | |
| analyzer = ImageAnalyzer(device="cpu") | |
| assert analyzer.models is not None | |
| assert 'captioning' in analyzer.models | |
| def test_image_analysis(sample_image): | |
| analyzer = ImageAnalyzer(device="cpu") | |
| results = analyzer.analyze_image(sample_image) | |
| assert isinstance(results, dict) | |
| assert 'title' in results | |
| assert 'style' in results | |
| assert len(results['colors']) == 5 | |
| def test_error_handling(): | |
| analyzer = ImageAnalyzer(device="cpu") | |
| invalid_input = "not_an_image" | |
| with pytest.raises(Exception): | |
| analyzer.analyze_image(invalid_input) | |
| def test_color_detection(sample_image): | |
| analyzer = ImageAnalyzer(device="cpu") | |
| colors = analyzer._get_colors(sample_image) | |
| assert len(colors) == 5 | |
| assert all('hex' in c for c in colors) | |
| assert all(0 <= c['score'] <= 1 for c in colors) |