97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
"""Tests for replay and OverrideProfile."""
|
|
|
|
import pytest
|
|
|
|
from detect.profiles.soccer import SoccerBroadcastProfile
|
|
from detect.profiles.base import RegionAnalysisConfig
|
|
from detect.checkpoint.replay import OverrideProfile, replay_single_stage
|
|
|
|
|
|
def test_override_profile_patches_ocr():
|
|
base = SoccerBroadcastProfile()
|
|
overrides = {"ocr": {"min_confidence": 0.3, "languages": ["en", "es", "pt"]}}
|
|
profile = OverrideProfile(base, overrides)
|
|
|
|
config = profile.ocr_config()
|
|
|
|
assert config.min_confidence == 0.3
|
|
assert config.languages == ["en", "es", "pt"]
|
|
|
|
|
|
def test_override_profile_patches_resolver():
|
|
base = SoccerBroadcastProfile()
|
|
overrides = {"resolver": {"fuzzy_threshold": 60}}
|
|
profile = OverrideProfile(base, overrides)
|
|
|
|
config = profile.resolver_config()
|
|
|
|
assert config.fuzzy_threshold == 60
|
|
|
|
|
|
def test_override_profile_patches_detection():
|
|
base = SoccerBroadcastProfile()
|
|
overrides = {"detection": {"confidence_threshold": 0.5}}
|
|
profile = OverrideProfile(base, overrides)
|
|
|
|
config = profile.detection_config()
|
|
|
|
assert config.confidence_threshold == 0.5
|
|
|
|
|
|
def test_override_profile_no_overrides():
|
|
base = SoccerBroadcastProfile()
|
|
profile = OverrideProfile(base, {})
|
|
|
|
ocr = profile.ocr_config()
|
|
base_ocr = base.ocr_config()
|
|
|
|
assert ocr.min_confidence == base_ocr.min_confidence
|
|
assert ocr.languages == base_ocr.languages
|
|
|
|
|
|
def test_override_profile_delegates_non_config():
|
|
base = SoccerBroadcastProfile()
|
|
profile = OverrideProfile(base, {"ocr": {"min_confidence": 0.1}})
|
|
|
|
assert profile.name == "soccer_broadcast"
|
|
assert profile.resolver_config().fuzzy_threshold > 0
|
|
|
|
|
|
def test_override_profile_ignores_unknown_fields():
|
|
base = SoccerBroadcastProfile()
|
|
overrides = {"ocr": {"nonexistent_field": 42}}
|
|
profile = OverrideProfile(base, overrides)
|
|
|
|
config = profile.ocr_config()
|
|
|
|
assert not hasattr(config, "nonexistent_field")
|
|
assert config.min_confidence == base.ocr_config().min_confidence
|
|
|
|
|
|
# --- OverrideProfile for region_analysis ---
|
|
|
|
def test_override_profile_patches_region_analysis():
|
|
base = SoccerBroadcastProfile()
|
|
overrides = {"region_analysis": {"edge_canny_low": 25, "edge_canny_high": 200}}
|
|
profile = OverrideProfile(base, overrides)
|
|
|
|
config = profile.region_analysis_config()
|
|
|
|
assert isinstance(config, RegionAnalysisConfig)
|
|
assert config.edge_canny_low == 25
|
|
assert config.edge_canny_high == 200
|
|
# Unchanged fields keep defaults
|
|
assert config.edge_hough_threshold == base.region_analysis_config().edge_hough_threshold
|
|
|
|
|
|
# --- replay_single_stage ---
|
|
|
|
def test_replay_single_stage_unknown_stage():
|
|
with pytest.raises(ValueError, match="Unknown stage"):
|
|
replay_single_stage("fake-job", "nonexistent_stage")
|
|
|
|
|
|
def test_replay_single_stage_first_stage():
|
|
with pytest.raises(ValueError, match="Cannot replay the first stage"):
|
|
replay_single_stage("fake-job", "extract_frames")
|