"""Tests for message utility functions."""
import pytest
class TestMessageToDict:
"""Tests for message_to_dict function."""
def test_primitive_values(self):
"""Test that primitive values pass through unchanged."""
from ros_mcp_server.utils.message_utils import message_to_dict
assert message_to_dict(42) == 42
assert message_to_dict(3.14) == 3.14
assert message_to_dict("hello") == "hello"
assert message_to_dict(True) is True
assert message_to_dict(None) is None
def test_list_values(self):
"""Test that lists are processed recursively."""
from ros_mcp_server.utils.message_utils import message_to_dict
assert message_to_dict([1, 2, 3]) == [1, 2, 3]
assert message_to_dict(["a", "b"]) == ["a", "b"]
def test_bytes_decoding(self):
"""Test that bytes are decoded to string."""
from ros_mcp_server.utils.message_utils import message_to_dict
result = message_to_dict(b"hello")
assert result == "hello"
class TestDictToMessage:
"""Tests for dict_to_message function (requires ROS)."""
@pytest.mark.skipif(True, reason="Requires ROS environment")
def test_simple_message(self):
"""Test converting dict to simple ROS message."""
from ros_mcp_server.utils.message_utils import dict_to_message
msg = dict_to_message({"data": "hello"}, "std_msgs/String")
assert msg.data == "hello"