From 89b9cb9edf73bdecb662498fef72e07c5e1df25f Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 15 Feb 2022 10:13:58 +0100 Subject: [PATCH 1/2] Remove fastrtps customization on tests Signed-off-by: Miguel Company --- rclpy/test/test_qos_event.py | 139 ++++++++++++++--------------------- 1 file changed, 56 insertions(+), 83 deletions(-) diff --git a/rclpy/test/test_qos_event.py b/rclpy/test/test_qos_event.py index a94b95865..bc3e67f7f 100644 --- a/rclpy/test/test_qos_event.py +++ b/rclpy/test/test_qos_event.py @@ -39,7 +39,6 @@ class TestQoSEvent(unittest.TestCase): - is_fastrtps = False topic_name = 'test_topic' def setUp(self): @@ -48,7 +47,6 @@ def setUp(self): self.node = rclpy.create_node('TestQoSEvent', namespace='/rclpy/test', context=self.context) - self.is_fastrtps = 'rmw_fastrtps' in get_rmw_implementation_identifier() def tearDown(self): # These tests create a bunch of events by hand instead of using Node APIs, @@ -64,7 +62,7 @@ def test_publisher_constructor(self): liveliness_callback = Mock() deadline_callback = Mock() incompatible_qos_callback = Mock() - expected_num_event_handlers = 0 if self.is_fastrtps else 1 + expected_num_event_handlers = 1 # No arg publisher = self.node.create_publisher(EmptyMsg, self.topic_name, 10) @@ -95,13 +93,10 @@ def test_publisher_constructor(self): # Arg with three callbacks callbacks.incompatible_qos = incompatible_qos_callback - try: - publisher = self.node.create_publisher( - EmptyMsg, self.topic_name, 10, event_callbacks=callbacks) - self.assertEqual(len(publisher.event_handlers), 3) - self.node.destroy_publisher(publisher) - except UnsupportedEventTypeError: - self.assertTrue(self.is_fastrtps) + publisher = self.node.create_publisher( + EmptyMsg, self.topic_name, 10, event_callbacks=callbacks) + self.assertEqual(len(publisher.event_handlers), 3) + self.node.destroy_publisher(publisher) def test_subscription_constructor(self): callbacks = SubscriptionEventCallbacks() @@ -109,7 +104,7 @@ def test_subscription_constructor(self): deadline_callback = Mock() message_callback = Mock() incompatible_qos_callback = Mock() - expected_num_event_handlers = 0 if self.is_fastrtps else 1 + expected_num_event_handlers = 1 # No arg subscription = self.node.create_subscription( @@ -141,13 +136,10 @@ def test_subscription_constructor(self): # Arg with three callbacks callbacks.incompatible_qos = incompatible_qos_callback - try: - subscription = self.node.create_subscription( - EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks) - self.assertEqual(len(subscription.event_handlers), 3) - self.node.destroy_subscription(subscription) - except UnsupportedEventTypeError: - self.assertTrue(self.is_fastrtps) + subscription = self.node.create_subscription( + EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks) + self.assertEqual(len(subscription.event_handlers), 3) + self.node.destroy_subscription(subscription) def test_default_incompatible_qos_callbacks(self): original_logger = rclpy.logging._root_logger @@ -187,17 +179,16 @@ def warn(self, message, once=False): executor = rclpy.executors.SingleThreadedExecutor(context=self.context) rclpy.spin_until_future_complete(self.node, log_msgs_future, executor, 10.0) - if not self.is_fastrtps: - self.assertEqual( - pub_log_msg, - "New subscription discovered on topic '{}', requesting incompatible QoS. " - 'No messages will be sent to it. ' - 'Last incompatible policy: DURABILITY'.format(self.topic_name)) - self.assertEqual( - sub_log_msg, - "New publisher discovered on topic '{}', offering incompatible QoS. " - 'No messages will be received from it. ' - 'Last incompatible policy: DURABILITY'.format(self.topic_name)) + self.assertEqual( + pub_log_msg, + "New subscription discovered on topic '{}', requesting incompatible QoS. " + 'No messages will be sent to it. ' + 'Last incompatible policy: DURABILITY'.format(self.topic_name)) + self.assertEqual( + sub_log_msg, + "New publisher discovered on topic '{}', offering incompatible QoS. " + 'No messages will be received from it. ' + 'Last incompatible policy: DURABILITY'.format(self.topic_name)) rclpy.logging._root_logger = original_logger @@ -217,11 +208,8 @@ def test_publisher_event_create_destroy(self): publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_DEADLINE_MISSED) self._do_create_destroy( publisher, QoSPublisherEventType.RCL_PUBLISHER_LIVELINESS_LOST) - try: - self._do_create_destroy( - publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS) - except UnsupportedEventTypeError: - self.assertTrue(self.is_fastrtps) + self._do_create_destroy( + publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS) self.node.destroy_publisher(publisher) def test_subscription_event_create_destroy(self): @@ -232,11 +220,8 @@ def test_subscription_event_create_destroy(self): subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_LIVELINESS_CHANGED) self._do_create_destroy( subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED) - try: - self._do_create_destroy( - subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS) - except UnsupportedEventTypeError: - self.assertTrue(self.is_fastrtps) + self._do_create_destroy( + subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS) self.node.destroy_subscription(subscription) def test_call_publisher_rclpy_event_apis(self): @@ -259,24 +244,19 @@ def test_call_publisher_rclpy_event_apis(self): liveliness_event_handle) self.assertIsNotNone(liveliness_event_index) - try: - incompatible_qos_event_handle = self._create_event_handle( - publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS) - with incompatible_qos_event_handle: - incompatible_qos_event_index = wait_set.add_event( - incompatible_qos_event_handle) - self.assertIsNotNone(incompatible_qos_event_index) - except UnsupportedEventTypeError: - self.assertTrue(self.is_fastrtps) + incompatible_qos_event_handle = self._create_event_handle( + publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS) + with incompatible_qos_event_handle: + incompatible_qos_event_index = wait_set.add_event( + incompatible_qos_event_handle) + self.assertIsNotNone(incompatible_qos_event_index) # We live in our own namespace and have created no other participants, so # there can't be any of these events. wait_set.wait(0) self.assertFalse(wait_set.is_ready('event', deadline_event_index)) self.assertFalse(wait_set.is_ready('event', liveliness_event_index)) - if not self.is_fastrtps: - self.assertFalse(wait_set.is_ready( - 'event', incompatible_qos_event_index)) + self.assertFalse(wait_set.is_ready('event', incompatible_qos_event_index)) # Calling take data even though not ready should provide me an empty initialized message # Tests data conversion utilities in C side @@ -298,16 +278,15 @@ def test_call_publisher_rclpy_event_apis(self): except NotImplementedError: pass - if not self.is_fastrtps: - try: - with incompatible_qos_event_handle: - event_data = incompatible_qos_event_handle.take_event() - self.assertIsInstance(event_data, QoSOfferedIncompatibleQoSInfo) - self.assertEqual(event_data.total_count, 0) - self.assertEqual(event_data.total_count_change, 0) - self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID) - except NotImplementedError: - pass + try: + with incompatible_qos_event_handle: + event_data = incompatible_qos_event_handle.take_event() + self.assertIsInstance(event_data, QoSOfferedIncompatibleQoSInfo) + self.assertEqual(event_data.total_count, 0) + self.assertEqual(event_data.total_count_change, 0) + self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID) + except NotImplementedError: + pass self.node.destroy_publisher(publisher) @@ -330,24 +309,19 @@ def test_call_subscription_rclpy_event_apis(self): liveliness_event_index = wait_set.add_event(liveliness_event_handle) self.assertIsNotNone(liveliness_event_index) - try: - incompatible_qos_event_handle = self._create_event_handle( - subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS) - with incompatible_qos_event_handle: - incompatible_qos_event_index = wait_set.add_event( - incompatible_qos_event_handle) - self.assertIsNotNone(incompatible_qos_event_index) - except UnsupportedEventTypeError: - self.assertTrue(self.is_fastrtps) + incompatible_qos_event_handle = self._create_event_handle( + subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS) + with incompatible_qos_event_handle: + incompatible_qos_event_index = wait_set.add_event( + incompatible_qos_event_handle) + self.assertIsNotNone(incompatible_qos_event_index) # We live in our own namespace and have created no other participants, so # there can't be any of these events. wait_set.wait(0) self.assertFalse(wait_set.is_ready('event', deadline_event_index)) self.assertFalse(wait_set.is_ready('event', liveliness_event_index)) - if not self.is_fastrtps: - self.assertFalse(wait_set.is_ready( - 'event', incompatible_qos_event_index)) + self.assertFalse(wait_set.is_ready('event', incompatible_qos_event_index)) # Calling take data even though not ready should provide me an empty initialized message # Tests data conversion utilities in C side @@ -371,15 +345,14 @@ def test_call_subscription_rclpy_event_apis(self): except NotImplementedError: pass - if not self.is_fastrtps: - try: - with incompatible_qos_event_handle: - event_data = incompatible_qos_event_handle.take_event() - self.assertIsInstance(event_data, QoSRequestedIncompatibleQoSInfo) - self.assertEqual(event_data.total_count, 0) - self.assertEqual(event_data.total_count_change, 0) - self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID) - except NotImplementedError: - pass + try: + with incompatible_qos_event_handle: + event_data = incompatible_qos_event_handle.take_event() + self.assertIsInstance(event_data, QoSRequestedIncompatibleQoSInfo) + self.assertEqual(event_data.total_count, 0) + self.assertEqual(event_data.total_count_change, 0) + self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID) + except NotImplementedError: + pass self.node.destroy_subscription(subscription) From 85ac2d80c6ac4e2794d7922575bec2019bc06baf Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 16 Feb 2022 07:15:34 +0100 Subject: [PATCH 2/2] Removed unused imports. Signed-off-by: Miguel Company --- rclpy/test/test_qos_event.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rclpy/test/test_qos_event.py b/rclpy/test/test_qos_event.py index bc3e67f7f..4acfc1b90 100644 --- a/rclpy/test/test_qos_event.py +++ b/rclpy/test/test_qos_event.py @@ -31,9 +31,7 @@ from rclpy.qos_event import QoSRequestedIncompatibleQoSInfo from rclpy.qos_event import QoSSubscriptionEventType from rclpy.qos_event import SubscriptionEventCallbacks -from rclpy.qos_event import UnsupportedEventTypeError from rclpy.task import Future -from rclpy.utilities import get_rmw_implementation_identifier from test_msgs.msg import Empty as EmptyMsg