Skip to content

Commit

Permalink
test: test signature of get_topics_names_and_services and node property
Browse files Browse the repository at this point in the history
  • Loading branch information
MagdalenaKotynia committed Feb 26, 2025
1 parent d73318f commit beeec2a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/rai_sim/test_o3de_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import typing
import unittest
from pathlib import Path
from typing import Optional, get_args, get_origin
from typing import List, Optional, Tuple, get_args, get_origin
from unittest.mock import MagicMock, patch

import rclpy
import rclpy.qos
from geometry_msgs.msg import Point, Pose, Quaternion, TransformStamped
from rai.communication.ros2.connectors import ROS2ARIConnector, ROS2ARIMessage
from rclpy.node import Node
from rclpy.qos import QoSProfile

from rai_sim.o3de.o3de_bridge import O3DExROS2Bridge, O3DExROS2SimulationConfig
Expand Down Expand Up @@ -330,3 +331,33 @@ def test_receive_message_signature(self):
ROS2ARIMessage,
f"Return type is incorrect, expected: ROS2ARIMessage, got: {signature.return_annotation}",
)

def test_get_topics_names_and_types_signature(self):
signature = inspect.signature(self.connector.get_topics_names_and_types)
parameters = signature.parameters

expected_params: dict[str, type] = {}

assert list(parameters.keys()) == list(expected_params.keys()), (
f"Parameter names do not match, expected: {list(expected_params.keys())}, got: {list(parameters.keys())}"
)

for param_name, expected_type in expected_params.items():
param = parameters[param_name]
assert param.annotation is expected_type, (
f"Parameter '{param_name}' has incorrect type annotation, expected: {expected_type}, got: {param.annotation}"
)

self.assertEqual(
signature.return_annotation,
List[Tuple[str, List[str]]],
f"Return type is incorrect, expected: List[Tuple[str, List[str]]], got: {signature.return_annotation}",
)

def test_node_property(self):
"""Test that the node property returns the expected Node instance."""
mock_node = MagicMock(spec=Node)
self.connector._node = mock_node

self.assertEqual(self.connector.node, mock_node)
self.assertIsInstance(self.connector.node, Node)

0 comments on commit beeec2a

Please sign in to comment.