c316309fc6
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from simulator.clips import Clip, load_manifest
|
|
|
|
|
|
def _manifest_dict():
|
|
return {
|
|
"clips": [
|
|
{
|
|
"id": "forest",
|
|
"title": "Yosemite Falls (neutral)",
|
|
"base_file": "forest/base.mp4",
|
|
"license": "poc-sample",
|
|
"source": "hef-poc",
|
|
"right_variants": {
|
|
"4": {"file": "forest/right4.mp4", "model": "sd-turbo+flow"},
|
|
"1": {"file": "forest/right1.mp4"},
|
|
},
|
|
"annotations": [
|
|
{"key": "detected.water", "box": [0.1, 0.2, 0.3, 0.4], "min_level": 1},
|
|
{"key": "detected.conifer", "box": [0.6, 0.1, 0.2, 0.2], "min_level": 3},
|
|
],
|
|
"strings": {"en": {"detected.water": "flowing water", "detected.conifer": "conifer"}},
|
|
}
|
|
]
|
|
}
|
|
|
|
|
|
def test_load_manifest_parses_clips(tmp_path):
|
|
p = tmp_path / "manifest.json"
|
|
p.write_text(json.dumps(_manifest_dict()))
|
|
clips = load_manifest(p)
|
|
assert len(clips) == 1
|
|
c = clips[0]
|
|
assert isinstance(c, Clip)
|
|
assert c.id == "forest"
|
|
assert c.base_file == "forest/base.mp4"
|
|
|
|
|
|
def test_clip_lists_variant_files_by_strength(tmp_path):
|
|
p = tmp_path / "manifest.json"
|
|
p.write_text(json.dumps(_manifest_dict()))
|
|
c = load_manifest(p)[0]
|
|
# variant 0 is always the raw base; authored strengths come from the manifest
|
|
assert c.variant_file(0) == "forest/base.mp4"
|
|
assert c.variant_file(4) == "forest/right4.mp4"
|
|
assert c.variant_file(1) == "forest/right1.mp4"
|
|
# an unauthored strength falls back to the raw base
|
|
assert c.variant_file(2) == "forest/base.mp4"
|
|
|
|
|
|
def test_clip_serializes_to_dict_for_the_api(tmp_path):
|
|
p = tmp_path / "manifest.json"
|
|
p.write_text(json.dumps(_manifest_dict()))
|
|
d = load_manifest(p)[0].to_dict()
|
|
assert d["id"] == "forest"
|
|
assert d["base_file"] == "forest/base.mp4"
|
|
assert d["annotations"][0]["key"] == "detected.water"
|
|
assert d["strings"]["en"]["detected.water"] == "flowing water"
|
|
# variant map is exposed keyed by strength string, including 0 -> base
|
|
assert d["right_variants"]["0"]["file"] == "forest/base.mp4"
|
|
assert d["right_variants"]["4"]["file"] == "forest/right4.mp4"
|
|
|
|
|
|
def test_missing_manifest_raises(tmp_path):
|
|
with pytest.raises(FileNotFoundError):
|
|
load_manifest(tmp_path / "nope.json")
|