예제 #1
0
def test_declare_qos_parameters_with_overrides():
    node = Node('my_node',
                parameter_overrides=[
                    Parameter('qos_overrides./my_topic.publisher.depth',
                              value=100),
                    Parameter('qos_overrides./my_topic.publisher.reliability',
                              value='best_effort'),
                ])
    for i in range(
            2
    ):  # try twice, the second time the parameters will be get and not declared
        _declare_qos_parameters(Publisher, node, '/my_topic',
                                QoSProfile(depth=10),
                                QoSOverridingOptions.with_default_policies())
        qos_overrides = node.get_parameters_by_prefix('qos_overrides')
        assert len(qos_overrides) == 3
        expected_params = (
            ('/my_topic.publisher.depth', 100),
            ('/my_topic.publisher.history', 'keep_last'),
            ('/my_topic.publisher.reliability', 'best_effort'),
        )
        for actual, expected in zip(
                sorted(qos_overrides.items(), key=lambda x: x[0]),
                expected_params):
            assert actual[0] == expected[0]  # same param name
            assert actual[1].value == expected[1]  # same param value
예제 #2
0
 def __init__(self):
     super().__init__('qos_overrides_listener')
     self.sub = self.create_subscription(
         String, 'qos_overrides_chatter', self.chatter_callback, 10,
         qos_overriding_options=QoSOverridingOptions.with_default_policies(
             callback=self.qos_callback,
             #  entity_id='my_custom_id',  # Use this if you want a custo qos override id.
         ))
예제 #3
0
 def __init__(self):
     super().__init__('qos_overrides_talker')
     self.i = 0
     self.pub = self.create_publisher(
         String, 'qos_overrides_chatter', 10,
         qos_overriding_options=QoSOverridingOptions.with_default_policies(
             callback=self.qos_callback,
             #  entity_id='my_custom_id',  # Use this if you want a custo qos override id.
         ))
     timer_period = 1.0
     self.tmr = self.create_timer(timer_period, self.timer_callback)
예제 #4
0
def test_declare_qos_parameters_with_unhappy_callback():
    def qos_validation_callback(qos):
        result = QosCallbackResult()
        result.successful = False
        result.reason = 'my_custom_error_message'
        return result

    node = Node('my_node')

    with pytest.raises(InvalidQosOverridesError) as err:
        _declare_qos_parameters(
            Publisher, node, '/my_topic', QoSProfile(depth=10),
            QoSOverridingOptions.with_default_policies(
                callback=qos_validation_callback))
    assert 'my_custom_error_message' in str(err.value)
예제 #5
0
def test_declare_qos_parameters():
    node = Node('my_node')
    _declare_qos_parameters(Publisher, node, '/my_topic', QoSProfile(depth=10),
                            QoSOverridingOptions.with_default_policies())
    qos_overrides = node.get_parameters_by_prefix('qos_overrides')
    assert len(qos_overrides) == 3
    expected_params = (
        ('/my_topic.publisher.depth', 10),
        ('/my_topic.publisher.history', 'keep_last'),
        ('/my_topic.publisher.reliability', 'reliable'),
    )
    for actual, expected in zip(
            sorted(qos_overrides.items(), key=lambda x: x[0]),
            expected_params):
        assert actual[0] == expected[0]  # same param name
        assert actual[1].value == expected[1]  # same param value
예제 #6
0
def test_declare_qos_parameters_with_happy_callback():
    def qos_validation_callback(qos):
        result = QosCallbackResult()
        result.successful = True
        return result

    node = Node('my_node')
    _declare_qos_parameters(
        Publisher, node, '/my_topic', QoSProfile(depth=10),
        QoSOverridingOptions.with_default_policies(
            callback=qos_validation_callback))
    qos_overrides = node.get_parameters_by_prefix('qos_overrides')
    assert len(qos_overrides) == 3
    expected_params = (
        ('/my_topic.publisher.depth', 10),
        ('/my_topic.publisher.history', 'keep_last'),
        ('/my_topic.publisher.reliability', 'reliable'),
    )
    for actual, expected in zip(
            sorted(qos_overrides.items(), key=lambda x: x[0]),
            expected_params):
        assert actual[0] == expected[0]  # same param name
        assert actual[1].value == expected[1]  # same param value