Sign2Voice / tests /test_wlasl_i3d_detector.py
lilblueyes's picture
Add experimental WLASL I3D backend
20aa7e1
Raw
History Blame Contribute Delete
1.04 kB
import json
import numpy as np
from signspeak.asl.wlasl_i3d_detector import WLASLI3DDetector
def test_wlasl_detector_loads_cached_labels(tmp_path):
cache_dir = tmp_path / "wlasl_i3d"
cache_dir.mkdir()
(cache_dir / "wlasl_2000_labels.json").write_text(json.dumps(["book", "hello"]), encoding="utf-8")
detector = WLASLI3DDetector(cache_dir=cache_dir)
assert detector.labels == ["book", "hello"]
assert detector._label_for_index(1) == "hello"
assert detector._label_for_index(99) == "99"
def test_wlasl_detector_reports_missing_runtime(monkeypatch, tmp_path):
(tmp_path / "wlasl_2000_labels.json").write_text(json.dumps(["book"]), encoding="utf-8")
detector = WLASLI3DDetector(cache_dir=tmp_path)
monkeypatch.setattr(detector, "_load_torch", lambda: (_ for _ in ()).throw(RuntimeError("missing torch")))
result = detector.predict_sequence_from_frames([np.zeros((2, 2, 3), dtype=np.uint8)])
assert result["status"] == "wlasl_i3d_error"
assert "missing torch" in result["error"]