Download scripts/tests/test_vivid_utils.py from XZhi/ViViD-5k: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/XZhi/ViViD-5k/resolve/main/scripts/tests/test_vivid_utils.py
- Command line
-
hf download hf://datasets/XZhi/ViViD-5k/scripts/tests/test_vivid_utils.py
-
curl -L -o test_vivid_utils.py https://huggingface.co/datasets/XZhi/ViViD-5k/resolve/main/scripts/tests/test_vivid_utils.py
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) | |