103 lines
3.6 KiB
Python
103 lines
3.6 KiB
Python
"""Config / input validation — FCP src/validation.py parity."""
|
|
|
|
import pytest
|
|
from src.validation import ValidationError, validate_config
|
|
|
|
|
|
def test_validate_config_accepts_current_config():
|
|
from src.config import load_config
|
|
validate_config(load_config()) # must not raise
|
|
|
|
|
|
def test_validate_config_rejects_out_of_range_conf():
|
|
with pytest.raises(ValidationError):
|
|
validate_config({"detection": {"sack_conf": 1.5, "box_conf": 0.35, "truck_conf": 0.45},
|
|
"iou": {"dedup": 0.5, "suppress_sack_box": 0.4, "synthetic": 0.3, "sticky_truck": 0.3}})
|
|
|
|
|
|
def test_validate_config_rejects_non_positive_iou():
|
|
with pytest.raises(ValidationError):
|
|
validate_config({"detection": {"sack_conf": 0.3, "box_conf": 0.35, "truck_conf": 0.45},
|
|
"iou": {"dedup": 0.0, "suppress_sack_box": 0.4, "synthetic": 0.3, "sticky_truck": 0.3}})
|
|
|
|
|
|
def test_validate_config_rejects_negative_min_bbox_area():
|
|
with pytest.raises(ValidationError):
|
|
validate_config({"detection": {"sack_conf": 0.3, "box_conf": 0.35, "truck_conf": 0.45},
|
|
"iou": {"dedup": 0.5, "suppress_sack_box": 0.4, "synthetic": 0.3, "sticky_truck": 0.3},
|
|
"min_bbox_area": {"sack": -1}})
|
|
|
|
|
|
# ── extra coverage for the validation rules not covered above ──────────
|
|
|
|
|
|
def test_validate_config_rejects_zero_conf():
|
|
with pytest.raises(ValidationError):
|
|
validate_config({"detection": {"sack_conf": 0.0}})
|
|
|
|
|
|
def test_validate_config_accepts_boundary_values():
|
|
validate_config({"detection": {"sack_conf": 1.0},
|
|
"iou": {"dedup": 1.0},
|
|
"min_bbox_area": {"sack": 0}})
|
|
|
|
|
|
def test_validate_config_rejects_non_mapping():
|
|
with pytest.raises(ValidationError):
|
|
validate_config(["not", "a", "mapping"])
|
|
|
|
|
|
def test_validate_config_ignores_absent_sections():
|
|
"""Partial dicts are fine — only offending values raise."""
|
|
validate_config({"detection": {"sack_conf": 0.3}})
|
|
validate_config({})
|
|
|
|
|
|
# ── InputValidator (FCP src/validation.py parity) ─────────────────────
|
|
|
|
|
|
def test_validate_model_path_accepts_existing_model(tmp_path):
|
|
from src.validation import InputValidator
|
|
|
|
model = tmp_path / "best.pt"
|
|
model.write_bytes(b"weights")
|
|
assert InputValidator.validate_model_path(str(model)) is True
|
|
|
|
|
|
def test_validate_model_path_rejects_bad_extension(tmp_path):
|
|
from src.validation import InputValidator
|
|
|
|
model = tmp_path / "best.txt"
|
|
model.write_bytes(b"weights")
|
|
with pytest.raises(ValidationError):
|
|
InputValidator.validate_model_path(str(model))
|
|
|
|
|
|
def test_validate_model_path_rejects_missing_file(tmp_path):
|
|
from src.validation import InputValidator
|
|
|
|
with pytest.raises(ValidationError):
|
|
InputValidator.validate_model_path(str(tmp_path / "nope.pt"))
|
|
|
|
|
|
def test_validate_video_source_accepts_existing_video(tmp_path):
|
|
from src.validation import InputValidator
|
|
|
|
video = tmp_path / "clip.mp4"
|
|
video.write_bytes(b"data")
|
|
assert InputValidator.validate_video_source(str(video)) is True
|
|
|
|
|
|
def test_validate_video_source_rejects_unknown_format():
|
|
from src.validation import InputValidator
|
|
|
|
with pytest.raises(ValidationError):
|
|
InputValidator.validate_video_source("not a video")
|
|
|
|
|
|
def test_validate_video_source_accepts_url():
|
|
"""URL branch kept for FCP parity — the recounter itself is file-based."""
|
|
from src.validation import InputValidator
|
|
|
|
assert InputValidator.validate_video_source("rtsp://camera.local/stream") is True
|