- Add FeatureExtractor for CLIP-based image/text feature extraction - Add ObjectiveMetricsCalculator for technical quality metrics - Add VLMEvaluator for vision language model evaluation - Add HybridQualityGate combining objective + VLM evaluation - Enhance CharacterMemory with visual feature support - Add quality optional dependency (torch, ftfy, regex) - Add unit tests for new modules 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
# 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
|