|
|
import json |
|
|
from pathlib import Path |
|
|
|
|
|
from ylff.services.scene_catalog import ( |
|
|
build_scene_catalog, |
|
|
validate_scene_catalog, |
|
|
write_scene_catalog_jsonl, |
|
|
) |
|
|
|
|
|
|
|
|
def test_scene_catalog_normalizes_common_manifest_variants(tmp_path: Path): |
|
|
p = tmp_path / "capture_x" |
|
|
p.mkdir() |
|
|
(p / "manifest.json").write_text( |
|
|
json.dumps( |
|
|
{ |
|
|
|
|
|
"schemaVersion": "1.0", |
|
|
"captureId": "cap_x", |
|
|
"regime": "indoor_constrained", |
|
|
"difficultyFlags": "mirror, glass", |
|
|
|
|
|
"devices": { |
|
|
"iphone_a": { |
|
|
"deviceType": "iphone", |
|
|
"video_path": "devices/iphone_a/video.mov", |
|
|
"intrinsics_path": "devices/iphone_a/intrinsics.json", |
|
|
"timestamps_path": "devices/iphone_a/timestamps.json", |
|
|
} |
|
|
}, |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
cat = build_scene_catalog([str(p / "manifest.json")]) |
|
|
assert cat.summary["num_scenes"] == 1 |
|
|
sc = cat.scenes[0] |
|
|
assert sc.capture_id == "cap_x" |
|
|
assert sc.operating_regime == "indoor_constrained" |
|
|
assert set(sc.difficulty_flags) == {"mirror", "glass"} |
|
|
assert sc.num_devices == 1 |
|
|
|
|
|
|
|
|
def test_scene_catalog_can_write_jsonl_and_report(tmp_path: Path): |
|
|
b1 = tmp_path / "capture_a" |
|
|
b1.mkdir() |
|
|
(b1 / "manifest.json").write_text( |
|
|
json.dumps({"schema_version": "1.0", "capture_id": "cap_a", "devices": []}) |
|
|
) |
|
|
|
|
|
cat = build_scene_catalog([str(b1 / "manifest.json")]) |
|
|
out_jsonl = tmp_path / "catalog.jsonl" |
|
|
write_scene_catalog_jsonl(cat, out_jsonl) |
|
|
txt = out_jsonl.read_text().strip().splitlines() |
|
|
assert len(txt) == 1 |
|
|
obj = json.loads(txt[0]) |
|
|
assert obj["capture_id"] == "cap_a" |
|
|
|
|
|
report = validate_scene_catalog(cat) |
|
|
assert report["num_scenes"] == 1 |
|
|
assert report["no_devices"] == 1 |
|
|
|
|
|
report = validate_scene_catalog(cat) |
|
|
assert report["num_scenes"] == 1 |
|
|
assert report["no_devices"] == 1 |
|
|
|