File size: 1,560 Bytes
e8055cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""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"
    )