33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from edge.zones import zones_from_config, thresholds_from_config
|
|
|
|
def test_parses_zone_rows_json_string_polygon():
|
|
cfg = {"zones": [
|
|
{"zone_id": "z1", "camera_id": "cam-1", "level": "restricted",
|
|
"polygon_json": "[[0,0],[9,0],[9,9]]"},
|
|
], "thresholds": {"fall_prone_s": 3.0}}
|
|
zones = zones_from_config(cfg)
|
|
assert len(zones) == 1
|
|
assert zones[0].zone_id == "z1"
|
|
assert zones[0].level == "restricted"
|
|
assert zones[0].polygon == [(0.0, 0.0), (9.0, 0.0), (9.0, 9.0)]
|
|
assert thresholds_from_config(cfg)["fall_prone_s"] == 3.0
|
|
|
|
def test_skips_malformed_row():
|
|
cfg = {"zones": [{"zone_id": "bad"}], "thresholds": {}}
|
|
assert zones_from_config(cfg) == []
|
|
|
|
def test_empty_config():
|
|
assert zones_from_config({}) == []
|
|
assert thresholds_from_config({}) == {}
|
|
|
|
def test_skips_short_point_without_crashing():
|
|
cfg = {"zones": [
|
|
{"zone_id": "bad", "camera_id": "c", "level": "restricted", "polygon_json": "[[0,0],[9],[9,9]]"},
|
|
{"zone_id": "ok", "camera_id": "c", "level": "restricted", "polygon_json": "[[0,0],[9,0],[9,9]]"},
|
|
]}
|
|
zones = zones_from_config(cfg)
|
|
# bad row skipped, good row survives -- function did not crash
|
|
assert [z.zone_id for z in zones] == ["ok"]
|
|
|
|
def test_non_iterable_zones_returns_empty():
|
|
assert zones_from_config({"zones": 5}) == []
|