def test_subscription_constructor(self): callbacks = SubscriptionEventCallbacks() liveliness_callback = Mock() deadline_callback = Mock() message_callback = Mock() # No arg subscription = self.node.create_subscription(EmptyMsg, 'test_topic', message_callback, 10) self.assertEqual(len(subscription.event_handlers), 0) self.node.destroy_subscription(subscription) # Arg with no callbacks subscription = self.node.create_subscription( EmptyMsg, 'test_topic', message_callback, 10, event_callbacks=callbacks) self.assertEqual(len(subscription.event_handlers), 0) self.node.destroy_subscription(subscription) # Arg with one of the callbacks callbacks.deadline = deadline_callback subscription = self.node.create_subscription( EmptyMsg, 'test_topic', message_callback, 10, event_callbacks=callbacks) self.assertEqual(len(subscription.event_handlers), 1) self.node.destroy_subscription(subscription) # Arg with both callbacks callbacks.liveliness = liveliness_callback subscription = self.node.create_subscription( EmptyMsg, 'test_topic', message_callback, 10, event_callbacks=callbacks) self.assertEqual(len(subscription.event_handlers), 2) self.node.destroy_subscription(subscription)
def test_subscription_constructor(self): callbacks = SubscriptionEventCallbacks() liveliness_callback = Mock() deadline_callback = Mock() message_callback = Mock() incompatible_qos_callback = Mock() expected_num_event_handlers = 1 # No arg subscription = self.node.create_subscription(EmptyMsg, self.topic_name, message_callback, 10) self.assertEqual(len(subscription.event_handlers), expected_num_event_handlers) self.node.destroy_subscription(subscription) # Arg with no callbacks subscription = self.node.create_subscription(EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks) self.assertEqual(len(subscription.event_handlers), expected_num_event_handlers) self.node.destroy_subscription(subscription) # Arg with one of the callbacks callbacks.deadline = deadline_callback expected_num_event_handlers += 1 subscription = self.node.create_subscription(EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks) self.assertEqual(len(subscription.event_handlers), expected_num_event_handlers) self.node.destroy_subscription(subscription) # Arg with two callbacks callbacks.liveliness = liveliness_callback expected_num_event_handlers += 1 subscription = self.node.create_subscription(EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks) self.assertEqual(len(subscription.event_handlers), expected_num_event_handlers) self.node.destroy_subscription(subscription) # Arg with three callbacks callbacks.incompatible_qos = incompatible_qos_callback 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)