96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
|
|
"""Tests for multi-modal interface adapters."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
|
||
|
|
from fusionagi.interfaces.adapters import (
|
||
|
|
BiometricAdapter,
|
||
|
|
GestureAdapter,
|
||
|
|
HapticAdapter,
|
||
|
|
VisualAdapter,
|
||
|
|
)
|
||
|
|
from fusionagi.interfaces.base import InterfaceMessage, ModalityType
|
||
|
|
|
||
|
|
|
||
|
|
def _msg(modality: ModalityType, content: str = "test") -> InterfaceMessage:
|
||
|
|
return InterfaceMessage(id="msg-1", modality=modality, content=content)
|
||
|
|
|
||
|
|
|
||
|
|
class TestVisualAdapter:
|
||
|
|
def test_capabilities(self) -> None:
|
||
|
|
a = VisualAdapter()
|
||
|
|
caps = a.capabilities()
|
||
|
|
assert ModalityType.VISUAL in caps.supported_modalities
|
||
|
|
assert caps.supports_streaming is True
|
||
|
|
|
||
|
|
def test_send_and_drain(self) -> None:
|
||
|
|
a = VisualAdapter()
|
||
|
|
asyncio.get_event_loop().run_until_complete(
|
||
|
|
a.send(_msg(ModalityType.VISUAL, "frame"))
|
||
|
|
)
|
||
|
|
outputs = a.get_pending_outputs()
|
||
|
|
assert len(outputs) == 1
|
||
|
|
assert outputs[0].content == "frame"
|
||
|
|
assert a.get_pending_outputs() == []
|
||
|
|
|
||
|
|
def test_receive_timeout(self) -> None:
|
||
|
|
a = VisualAdapter()
|
||
|
|
result = asyncio.get_event_loop().run_until_complete(a.receive(timeout_seconds=0.01))
|
||
|
|
assert result is None
|
||
|
|
|
||
|
|
|
||
|
|
class TestHapticAdapter:
|
||
|
|
def test_capabilities(self) -> None:
|
||
|
|
a = HapticAdapter()
|
||
|
|
caps = a.capabilities()
|
||
|
|
assert ModalityType.HAPTIC in caps.supported_modalities
|
||
|
|
|
||
|
|
def test_send(self) -> None:
|
||
|
|
a = HapticAdapter()
|
||
|
|
asyncio.get_event_loop().run_until_complete(
|
||
|
|
a.send(_msg(ModalityType.HAPTIC, "vibrate"))
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_receive_returns_none(self) -> None:
|
||
|
|
a = HapticAdapter()
|
||
|
|
result = asyncio.get_event_loop().run_until_complete(a.receive(timeout_seconds=0.01))
|
||
|
|
assert result is None
|
||
|
|
|
||
|
|
|
||
|
|
class TestGestureAdapter:
|
||
|
|
def test_capabilities(self) -> None:
|
||
|
|
a = GestureAdapter()
|
||
|
|
caps = a.capabilities()
|
||
|
|
assert ModalityType.GESTURE in caps.supported_modalities
|
||
|
|
|
||
|
|
def test_inject_and_receive(self) -> None:
|
||
|
|
a = GestureAdapter()
|
||
|
|
msg = _msg(ModalityType.GESTURE, "wave")
|
||
|
|
loop = asyncio.get_event_loop()
|
||
|
|
loop.run_until_complete(a.inject_gesture(msg))
|
||
|
|
received = loop.run_until_complete(a.receive(timeout_seconds=1.0))
|
||
|
|
assert received is not None
|
||
|
|
assert received.content == "wave"
|
||
|
|
|
||
|
|
|
||
|
|
class TestBiometricAdapter:
|
||
|
|
def test_capabilities(self) -> None:
|
||
|
|
a = BiometricAdapter()
|
||
|
|
caps = a.capabilities()
|
||
|
|
assert ModalityType.BIOMETRIC in caps.supported_modalities
|
||
|
|
|
||
|
|
def test_inject_and_aggregate(self) -> None:
|
||
|
|
a = BiometricAdapter()
|
||
|
|
msg = InterfaceMessage(
|
||
|
|
id="bio-1",
|
||
|
|
modality=ModalityType.BIOMETRIC,
|
||
|
|
content={"heart_rate": 72, "stress_level": 0.3},
|
||
|
|
)
|
||
|
|
loop = asyncio.get_event_loop()
|
||
|
|
loop.run_until_complete(a.inject_reading(msg))
|
||
|
|
received = loop.run_until_complete(a.receive(timeout_seconds=1.0))
|
||
|
|
assert received is not None
|
||
|
|
latest = a.get_latest()
|
||
|
|
assert latest["heart_rate"] == 72
|