Files
feedmill-recounter/tests/test_zone_config.py
T

48 lines
1.5 KiB
Python

import json
import os
import pytest
from src.zone_config import load_zone_config, build_static_roi, list_zone_presets
def test_load_zone_config_reads_json(tmp_path):
cfg = {"presets": {"test": {"count_line": {"x_start": 100, "x_end": 200, "y": 150}}}, "active_preset": "test"}
p = tmp_path / "zones.json"
p.write_text(json.dumps(cfg))
result = load_zone_config(str(p))
assert result["active_preset"] == "test"
assert result["presets"]["test"]["count_line"]["y"] == 150
def test_build_static_roi_from_zone_config():
zone = {
"truck_area": [[100, 50], [110, 300], [400, 310], [390, 40]],
"count_line": {"x_start": 110, "x_end": 400, "y": 150},
}
roi = build_static_roi(zone, video_w=640, video_h=480)
assert roi.line_y == 150
assert roi.confidence == 1.0
assert roi.x1 < roi.x2
assert roi.y1 < roi.y2
def test_build_static_roi_scales_coords():
zone = {
"truck_area": [[600, 385], [609, 1076], [1404, 1078], [1381, 343]],
"count_line": {"x_start": 577, "x_end": 1401, "y": 330},
}
roi = build_static_roi(zone, video_w=1920, video_h=1080)
assert roi.line_y == 330
assert roi.x1 == 600
assert roi.x2 == 1404
def test_list_zone_presets(tmp_path):
cfg = {"presets": {"p1": {"description": "Zone 1"}, "p2": {"description": "Zone 2"}}}
p = tmp_path / "zones.json"
p.write_text(json.dumps(cfg))
presets = list_zone_presets(str(p))
assert len(presets) == 2
names = [p["name"] for p in presets]
assert "p1" in names
assert "p2" in names