def test_set_param_with_node():
    lc = MockContext()
    node = Node(
        package='asd',
        executable='bsd',
        name='my_node',
        namespace='my_ns',
        parameters=[{'asd': 'bsd'}]
    )
    set_param = SetParameter(name='my_param', value='my_value')
    set_param.execute(lc)
    node._perform_substitutions(lc)
    expanded_parameter_files = node._Node__expanded_parameter_files
    assert len(expanded_parameter_files) == 2
    with open(expanded_parameter_files[0], 'r') as h:
        expanded_parameters_dict = yaml.load(h, Loader=yaml.FullLoader)
        assert expanded_parameters_dict == {
            '/my_ns/my_node': {
                'ros__parameters': {'my_param': 'my_value'}
            }
        }
    with open(expanded_parameter_files[1], 'r') as h:
        expanded_parameters_dict = yaml.load(h, Loader=yaml.FullLoader)
        assert expanded_parameters_dict == {
            '/my_ns/my_node': {
                'ros__parameters': {'asd': 'bsd'}
            }
        }
示例#2
0
def test_set_param_with_node():
    lc = MockContext()
    node = Node(package='asd',
                executable='bsd',
                name='my_node',
                namespace='my_ns',
                parameters=[{
                    'asd': 'bsd'
                }])
    set_param = SetParameter(name='my_param', value='my_value')
    set_param.execute(lc)
    node._perform_substitutions(lc)
    actual_command = [
        perform_substitutions(lc, item) for item in node.cmd
        if type(item[0]) == TextSubstitution
    ]
    assert actual_command.count('--params-file') == 1
    assert actual_command.count('-p') == 1

    param_cmdline_index = actual_command.index('-p') + 1
    param_cmdline = actual_command[param_cmdline_index]
    assert param_cmdline == 'my_param:=my_value'

    param_file_index = actual_command.index('--params-file') + 1
    param_file_path = actual_command[param_file_index]
    assert os.path.isfile(param_file_path)
    with open(param_file_path, 'r') as h:
        expanded_parameters_dict = yaml.load(h, Loader=yaml.FullLoader)
        assert expanded_parameters_dict == {
            '/my_ns/my_node': {
                'ros__parameters': {
                    'asd': 'bsd'
                }
            }
        }
示例#3
0
def test_set_remap_with_node():
    lc = MockContext()
    node = Node(package='asd',
                executable='bsd',
                name='my_node',
                namespace='my_ns',
                remappings=[('from2', 'to2')])
    set_remap = SetRemap('from1', 'to1')
    set_remap.execute(lc)
    node._perform_substitutions(lc)
    assert len(node.expanded_remapping_rules) == 2
    assert node.expanded_remapping_rules == [('from1', 'to1'),
                                             ('from2', 'to2')]
示例#4
0
def test_push_ros_namespace(config):
    lc = LaunchContext()
    if config.push_ns is not None:
        pns1 = PushRosNamespace(config.push_ns)
        pns1.execute(lc)
    if config.second_push_ns is not None:
        pns2 = PushRosNamespace(config.second_push_ns)
        pns2.execute(lc)
    node = Node(
        package='dont_care',
        executable='whatever',
        node_namespace=config.node_ns,
    )
    node._perform_substitutions(lc)
    expected_ns = config.expected_ns if config.expected_ns is not None else ''
    assert expected_ns == node.expanded_node_namespace
def test_push_ros_namespace(config):
    lc = LaunchContext()
    if config.push_ns is not None:
        pns1 = PushRosNamespace(config.push_ns)
        pns1.execute(lc)
    if config.second_push_ns is not None:
        pns2 = PushRosNamespace(config.second_push_ns)
        pns2.execute(lc)
    node = Node(package='dont_care',
                executable='whatever',
                namespace=config.node_ns,
                name=config.node_name)
    node._perform_substitutions(lc)
    expected_ns = (config.expected_ns if config.expected_ns is not None else
                   Node.UNSPECIFIED_NODE_NAMESPACE)
    expected_name = (config.node_name if config.node_name is not None else
                     Node.UNSPECIFIED_NODE_NAME)
    expected_fqn = expected_ns.rstrip('/') + '/' + expected_name
    assert expected_ns == node.expanded_node_namespace
    assert expected_fqn == node.node_name