workspace / tests /test_B /test_spatial_codes.py
AntonioJun's picture
Replace tests with local workspace contents
e8055cf verified
Raw
History Blame Contribute Delete
1.56 kB
"""Tests for harness/B/spatial_codes.py -- loading on-disk spatial codes as plain JSON."""
import json
import pytest
from harness.B import spatial_codes
def test_load_spatial_code_rejects_unknown_format():
with pytest.raises(ValueError):
spatial_codes.load_spatial_code(
"scene", "metric", "selective", "tracking", 64, "bogus"
)
def test_load_spatial_code_raises_clearly_when_missing(tmp_path, monkeypatch):
monkeypatch.setattr(
spatial_codes,
"spatial_code_path",
lambda *a, **k: str(tmp_path / "missing.json"),
)
with pytest.raises(FileNotFoundError):
spatial_codes.load_spatial_code(
"scene", "metric", "selective", "tracking", 64, "explicit"
)
def test_load_spatial_code_returns_dict_and_path(tmp_path, monkeypatch):
fixture = tmp_path / "13c3e046d7.json"
fixture.write_text(json.dumps({"objects": {}, "room": {}}))
monkeypatch.setattr(
spatial_codes, "spatial_code_path", lambda *a, **k: str(fixture)
)
code, path = spatial_codes.load_spatial_code(
"13c3e046d7", "metric", "selective", "tracking", 64, "explicit"
)
assert code == {"objects": {}, "room": {}}
assert path == str(fixture)
def test_spatial_code_path_uses_tracking_frames_hierarchy():
path = spatial_codes.spatial_code_path(
"scene-a", "metric", "selective", "tracking", 64, "explicit"
)
assert path.endswith(
"data/spatial codes/sam3+depth-anything-3/tracking/frames/selective/64/explicit/scene-a.json"
)