ViViD-5k / scripts /tests /test_vivid_utils.py
XZhi's picture
Claude Fable 5
Add scripts scaffolding: shared helpers, tests, gitignore
14d9f17
Raw History Blame Contribute Delete
1.07 kB
import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from vivid_utils import parse_bbox, load_splits
def test_parse_bbox_flat():
assert parse_bbox([352.0, 63.0, 2858.0, 3711.0]) == (352.0, 63.0, 2858.0, 3711.0)
def test_parse_bbox_nested():
assert parse_bbox([[352.0, 63.0, 2858.0, 3711.0]]) == (352.0, 63.0, 2858.0, 3711.0)
def test_parse_bbox_invalid():
with pytest.raises(ValueError):
parse_bbox([1.0, 2.0])
def test_load_splits(tmp_path):
(tmp_path / "train.txt").write_text("a.jpg\nb.png\n")
(tmp_path / "val.txt").write_text("c.png\n")
(tmp_path / "test.txt").write_text("d.jpg\n")
splits = load_splits(tmp_path)
assert splits == {"a.jpg": "train", "b.png": "train", "c.png": "val", "d.jpg": "test"}
def test_load_splits_duplicate_raises(tmp_path):
(tmp_path / "train.txt").write_text("a.jpg\n")
(tmp_path / "val.txt").write_text("a.jpg\n")
(tmp_path / "test.txt").write_text("")
with pytest.raises(ValueError):
load_splits(tmp_path)