feat(lib): add ScrollModel (numpy + ONNX Runtime); rename legacy scroll module

This commit is contained in:
2026-05-12 01:14:37 +08:00
parent bae9a93ffa
commit 4e69ecc963
6 changed files with 178 additions and 6 deletions

37
tests/unit/test_scroll.py Normal file
View File

@@ -0,0 +1,37 @@
"""Tests for ScrollModel and ai_mouse.generate_scroll()."""
from __future__ import annotations
import pytest
def test_scroll_model_init_default() -> None:
from ai_mouse.scroll import ScrollModel
m = ScrollModel()
assert m._seq_len > 0
m.close()
def test_scroll_model_generate_target_mode() -> None:
from ai_mouse.scroll import ScrollModel
m = ScrollModel()
events = m.generate(0, 1500, mode="target")
assert len(events) >= 5
total = sum(e["deltaY"] for e in events)
assert 1000 <= total <= 2000 # broad — quantisation can drift
assert events[0]["t"] == 0
assert all(e["deltaMode"] == 0 for e in events)
def test_scroll_model_direction() -> None:
from ai_mouse.scroll import ScrollModel
m = ScrollModel()
events = m.generate(2000, 0, mode="target")
total = sum(e["deltaY"] for e in events)
assert total < 0
def test_scroll_invalid_path() -> None:
from ai_mouse.errors import ModelLoadError
from ai_mouse.scroll import ScrollModel
with pytest.raises(ModelLoadError):
ScrollModel(model_path="/no/such/path")