# Copyright (C) 2025 AIDC-AI # Tests for ObjectiveMetricsCalculator import pytest from pathlib import Path from pixelle_video.services.quality.objective_metrics import ( ObjectiveMetricsCalculator, TechnicalMetrics, ) class TestTechnicalMetrics: """Tests for TechnicalMetrics dataclass""" def test_default_values(self): metrics = TechnicalMetrics() assert metrics.sharpness_score == 0.0 assert metrics.overall_technical == 0.0 assert metrics.issues == [] def test_to_dict(self): metrics = TechnicalMetrics( sharpness_score=0.8, brightness_score=0.5, issues=["test issue"] ) d = metrics.to_dict() assert d["sharpness_score"] == 0.8 assert "test issue" in d["issues"] class TestObjectiveMetricsCalculator: """Tests for ObjectiveMetricsCalculator""" def test_init_default(self): calc = ObjectiveMetricsCalculator() assert calc.sharpness_threshold == 0.3 def test_init_custom(self): calc = ObjectiveMetricsCalculator(sharpness_threshold=0.5) assert calc.sharpness_threshold == 0.5 def test_analyze_nonexistent_image(self): calc = ObjectiveMetricsCalculator() metrics = calc.analyze_image("/nonexistent/path.png") assert len(metrics.issues) > 0 assert "failed" in metrics.issues[0].lower() def test_analyze_real_image(self, tmp_path): """Test with a real image file""" from PIL import Image # Create test image img = Image.new("RGB", (256, 256), color=(128, 128, 128)) img_path = tmp_path / "test.png" img.save(img_path) calc = ObjectiveMetricsCalculator() metrics = calc.analyze_image(str(img_path)) assert 0.0 <= metrics.sharpness_score <= 1.0 assert 0.0 <= metrics.brightness_score <= 1.0 assert 0.0 <= metrics.overall_technical <= 1.0