phase 4
This commit is contained in:
@@ -1,87 +1,67 @@
|
||||
"""Tests for replay and OverrideProfile."""
|
||||
"""Tests for config overrides and replay."""
|
||||
|
||||
import pytest
|
||||
|
||||
from detect.profiles.soccer import SoccerBroadcastProfile
|
||||
from detect.profiles.base import RegionAnalysisConfig
|
||||
from detect.checkpoint.replay import OverrideProfile, replay_single_stage
|
||||
from core.detect.profile import get_profile, get_stage_config
|
||||
from core.detect.stages.models import RegionAnalysisConfig, OCRConfig, ResolverConfig
|
||||
from core.detect.checkpoint.replay import 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)
|
||||
def _apply_overrides(profile, overrides):
|
||||
"""Apply config overrides to a profile dict (same logic as nodes._load_profile)."""
|
||||
merged_configs = dict(profile.get("configs", {}))
|
||||
for stage_name, stage_overrides in overrides.items():
|
||||
if stage_name in merged_configs:
|
||||
merged_configs[stage_name] = {**merged_configs[stage_name], **stage_overrides}
|
||||
else:
|
||||
merged_configs[stage_name] = stage_overrides
|
||||
return {**profile, "configs": merged_configs}
|
||||
|
||||
config = profile.ocr_config()
|
||||
|
||||
def test_override_patches_ocr():
|
||||
profile = get_profile("soccer_broadcast")
|
||||
overrides = {"run_ocr": {"min_confidence": 0.3, "languages": ["en", "es", "pt"]}}
|
||||
patched = _apply_overrides(profile, overrides)
|
||||
|
||||
config = OCRConfig(**get_stage_config(patched, "run_ocr"))
|
||||
|
||||
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)
|
||||
def test_override_patches_resolver():
|
||||
profile = get_profile("soccer_broadcast")
|
||||
overrides = {"match_brands": {"fuzzy_threshold": 60}}
|
||||
patched = _apply_overrides(profile, overrides)
|
||||
|
||||
config = profile.resolver_config()
|
||||
config = ResolverConfig(**get_stage_config(patched, "match_brands"))
|
||||
|
||||
assert config.fuzzy_threshold == 60
|
||||
|
||||
|
||||
def test_override_profile_patches_detection():
|
||||
base = SoccerBroadcastProfile()
|
||||
overrides = {"detection": {"confidence_threshold": 0.5}}
|
||||
profile = OverrideProfile(base, overrides)
|
||||
def test_override_no_overrides():
|
||||
profile = get_profile("soccer_broadcast")
|
||||
patched = _apply_overrides(profile, {})
|
||||
|
||||
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()
|
||||
ocr = OCRConfig(**get_stage_config(patched, "run_ocr"))
|
||||
base_ocr = OCRConfig(**get_stage_config(profile, "run_ocr"))
|
||||
|
||||
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}})
|
||||
def test_override_patches_region_analysis():
|
||||
profile = get_profile("soccer_broadcast")
|
||||
overrides = {"detect_edges": {"edge_canny_low": 25, "edge_canny_high": 200}}
|
||||
patched = _apply_overrides(profile, overrides)
|
||||
|
||||
assert profile.name == "soccer_broadcast"
|
||||
assert profile.resolver_config().fuzzy_threshold > 0
|
||||
config = RegionAnalysisConfig(**get_stage_config(patched, "detect_edges"))
|
||||
|
||||
|
||||
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
|
||||
# Unchanged fields keep defaults from profile
|
||||
base_config = RegionAnalysisConfig(**get_stage_config(profile, "detect_edges"))
|
||||
assert config.edge_hough_threshold == base_config.edge_hough_threshold
|
||||
|
||||
|
||||
# --- replay_single_stage ---
|
||||
|
||||
Reference in New Issue
Block a user