def test_executable():
    """Parse executable yaml example."""
    yaml_file = \
        """\
        launch:
        -   executable:
                cmd: ls -l -a -s
                cwd: '/'
                name: my_ls
                shell: true
                output: log
                launch_prefix: $(env LAUNCH_PREFIX)
                env:
                    -   name: var
                        value: '1'
        """
    yaml_file = textwrap.dedent(yaml_file)
    root_entity, parser = Parser.load(io.StringIO(yaml_file))
    ld = parser.parse_description(root_entity)
    executable = ld.entities[0]
    cmd = [i[0].perform(None) for i in executable.cmd]
    assert(
        cmd == ['ls', '-l', '-a', '-s'])
    assert(executable.cwd[0].perform(None) == '/')
    assert(executable.name[0].perform(None) == 'my_ls')
    assert(executable.shell is True)
    assert(executable.output == 'log')
    key, value = executable.additional_env[0]
    key = key[0].perform(None)
    value = value[0].perform(None)
    assert(key == 'var')
    assert(value == '1')
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert(0 == ls.run())
Exemple #2
0
def test_group():
    yaml_file = \
        """\
        launch:
            - let:
                name: 'foo'
                value: 'FOO'
            - let:
                name: 'bar'
                value: 'BAR'
            - group:
                scoped: True
                forwarding: False
                keep:
                    -   name: 'bar'
                        value: $(var bar)
                    -   name: 'baz'
                        value: 'BAZ'
                children:
                    - let:
                        name: 'var1'
                        value: 'asd'
                    - let:
                        name: 'var2'
                        value: 'asd'
        """  # noqa: E501
    yaml_file = textwrap.dedent(yaml_file)
    root_entity, parser = Parser.load(io.StringIO(yaml_file))
    ld = parser.parse_description(root_entity)

    assert isinstance(ld.entities[0], SetLaunchConfiguration)
    assert isinstance(ld.entities[1], SetLaunchConfiguration)
    assert isinstance(ld.entities[2], GroupAction)

    lc = LaunchContext()
    assert 0 == len(lc.launch_configurations)
    ld.entities[0].visit(lc)
    ld.entities[1].visit(lc)
    assert 2 == len(lc.launch_configurations)
    assert 'foo' in lc.launch_configurations.keys()
    assert 'FOO' == lc.launch_configurations['foo']
    assert 'bar' in lc.launch_configurations.keys()
    assert 'BAR' == lc.launch_configurations['bar']
    actions = ld.entities[2].execute(lc)
    assert 5 == len(actions)
    assert isinstance(actions[0], PushLaunchConfigurations)
    assert isinstance(actions[1], ResetLaunchConfigurations)
    assert isinstance(actions[2], SetLaunchConfiguration)
    assert isinstance(actions[3], SetLaunchConfiguration)
    assert isinstance(actions[4], PopLaunchConfigurations)
    actions[0].visit(lc)
    actions[1].visit(lc)
    assert 'foo' not in lc.launch_configurations.keys()
    assert 'bar' in lc.launch_configurations.keys()
    assert 'BAR' == lc.launch_configurations['bar']
    assert 'baz' in lc.launch_configurations.keys()
    assert 'BAZ' == lc.launch_configurations['baz']
    actions[2].visit(lc)
    actions[3].visit(lc)
    actions[4].visit(lc)
Exemple #3
0
def test_reset():
    xml_file = \
        """\
        <launch>
            <let name="foo" value="FOO"/>
            <let name="bar" value="BAR"/>
            <reset>
                <keep name="bar" value="$(var bar)"/>
                <keep name="baz" value="BAZ"/>
            </reset>
        </launch>
        """  # noqa: E501
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)

    assert isinstance(ld.entities[0], SetLaunchConfiguration)
    assert isinstance(ld.entities[1], SetLaunchConfiguration)
    assert isinstance(ld.entities[2], ResetLaunchConfigurations)

    lc = LaunchContext()
    assert len(lc.launch_configurations) == 0
    ld.entities[0].visit(lc)
    ld.entities[1].visit(lc)
    assert len(lc.launch_configurations) == 2
    assert 'foo' in lc.launch_configurations.keys()
    assert lc.launch_configurations['foo'] == 'FOO'
    assert 'bar' in lc.launch_configurations.keys()
    assert lc.launch_configurations['bar'] == 'BAR'
    ld.entities[2].visit(lc)
    assert 'foo' not in lc.launch_configurations.keys()
    assert 'bar' in lc.launch_configurations.keys()
    assert lc.launch_configurations['bar'] == 'BAR'
    assert 'baz' in lc.launch_configurations.keys()
    assert lc.launch_configurations['baz'] == 'BAZ'
Exemple #4
0
 def _assert_launch_frontend_no_errors(self, file) -> Trace:
     root_entity, parser = Parser.load(file)
     ld = parser.parse_description(root_entity)
     ls = LaunchService()
     ls.include_launch_description(ld)
     assert 0 == ls.run()
     trace_action = ld.describe_sub_entities()[0]
     return trace_action
Exemple #5
0
def check_launch_namespace(file):
    root_entity, parser = Parser.load(file)
    ld = parser.parse_description(root_entity)
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert 0 == ls.run()
    assert 'ros_namespace' in ls.context.launch_configurations
    assert '/asd' == ls.context.launch_configurations['ros_namespace']
def check_launch_node(file):
    root_entity, parser = Parser.load(file)
    ld = parser.parse_description(root_entity)
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert(0 == ls.run())
    evaluated_parameters = evaluate_parameters(
        ls.context,
        ld.describe_sub_entities()[3]._Node__parameters
    )
    assert len(evaluated_parameters) == 3
    assert isinstance(evaluated_parameters[0], dict)
    assert isinstance(evaluated_parameters[1], dict)
    assert isinstance(evaluated_parameters[2], pathlib.Path)

    assert 'param1' in evaluated_parameters[0]
    assert evaluated_parameters[0]['param1'] == 'ads'

    param_dict = evaluated_parameters[1]
    assert 'param_group1.param_group2.param2' in param_dict
    assert 'param_group1.param3' in param_dict
    assert 'param_group1.param4' in param_dict
    assert 'param_group1.param5' in param_dict
    assert 'param_group1.param6' in param_dict
    assert 'param_group1.param7' in param_dict
    assert 'param_group1.param8' in param_dict
    assert 'param_group1.param9' in param_dict
    assert 'param_group1.param10' in param_dict
    assert 'param_group1.param11' in param_dict
    assert 'param_group1.param12' in param_dict
    assert 'param_group1.param13' in param_dict
    assert 'param_group1.param14' in param_dict
    assert 'param_group1.param15' in param_dict
    assert param_dict['param_group1.param_group2.param2'] == 2
    assert param_dict['param_group1.param3'] == [2, 5, 8]
    assert param_dict['param_group1.param4'] == [2, 5, 8]
    assert param_dict['param_group1.param5'] == '[2, 5, 8]'
    assert param_dict['param_group1.param6'] == [2., 5., 8.]
    assert param_dict['param_group1.param7'] == ['2', '5', '8']
    assert param_dict['param_group1.param8'] == ["'2'", "'5'", "'8'"]
    assert param_dict['param_group1.param9'] == ["'2'", "'5'", "'8'"]
    assert param_dict['param_group1.param10'] == ["'asd'", "'bsd'", "'csd'"]
    assert param_dict['param_group1.param11'] == ['asd', 'bsd', 'csd']
    assert param_dict['param_group1.param12'] == ''
    assert param_dict['param_group1.param13'] == '100'
    assert param_dict['param_group1.param14'] == ["'2'", "'5'", "'8'"]
    assert param_dict['param_group1.param15'] == ['2', '5', '8']

    # Check remappings exist
    remappings = ld.describe_sub_entities()[3]._Node__remappings
    assert remappings is not None
    assert len(remappings) == 2

    listener_node_action = ld.describe_sub_entities()[4]
    listener_node_cmd = listener_node_action.process_details['cmd']
    assert [
        sys.executable, '-c', 'import sys; print(sys.argv[1:])'
    ] == listener_node_cmd[:3]
def test_node_frontend(file):
    """Parse node xml example."""
    root_entity, parser = Parser.load(io.StringIO(file))
    ld = parser.parse_description(root_entity)
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert 0 == ls.run()
    assert 'ros_namespace' in ls.context.launch_configurations
    assert '/asd' == ls.context.launch_configurations['ros_namespace']
Exemple #8
0
def generate_launch_description():

    xml_file_path = str(
        os.path.join(get_package_share_directory('crs_application'), 'launch',
                     XML_FILE_NAME))
    print('Opening ROS2 launch file: %s' % (xml_file_path))
    root_entity, parser = Parser.load(xml_file_path)
    ld = parser.parse_description(root_entity)
    return ld
Exemple #9
0
def test_append_env():
    xml_file = \
        """\
        <launch>
            <append_env name="my_env_var" value="asd"/>
            <append_env name="my_env_var" value="zxc" separator="|"/>
            <append_env name="my_other_env_var" value="fgh"/>
            <append_env name="my_other_env_var" value="jkl" prepend="false"/>
            <append_env name="my_other_env_var" value="qwe" prepend="yes"/>
            <append_env name="my_other_env_var" value="rty" prepend="true" separator="|"/>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    assert len(ld.entities) == 6
    assert isinstance(ld.entities[0], AppendEnvironmentVariable)
    assert isinstance(ld.entities[1], AppendEnvironmentVariable)
    assert isinstance(ld.entities[2], AppendEnvironmentVariable)
    assert isinstance(ld.entities[3], AppendEnvironmentVariable)
    assert isinstance(ld.entities[4], AppendEnvironmentVariable)
    assert isinstance(ld.entities[5], AppendEnvironmentVariable)
    assert 'my_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[0].name])
    assert 'my_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[0].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[2].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[3].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[4].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[5].name])
    assert 'asd' == ''.join([x.perform(None) for x in ld.entities[0].value])
    assert 'zxc' == ''.join([x.perform(None) for x in ld.entities[1].value])
    assert 'fgh' == ''.join([x.perform(None) for x in ld.entities[2].value])
    assert 'jkl' == ''.join([x.perform(None) for x in ld.entities[3].value])
    assert 'qwe' == ''.join([x.perform(None) for x in ld.entities[4].value])
    assert 'rty' == ''.join([x.perform(None) for x in ld.entities[5].value])
    assert not ld.entities[0].prepend
    assert not ld.entities[1].prepend
    assert not ld.entities[2].prepend
    assert not ld.entities[3].prepend
    assert ld.entities[4].prepend
    assert ld.entities[5].prepend
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[0].separator])
    assert '|' == ''.join([x.perform(None) for x in ld.entities[1].separator])
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[2].separator])
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[3].separator])
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[4].separator])
    assert '|' == ''.join([x.perform(None) for x in ld.entities[5].separator])
Exemple #10
0
def test_deprecated_launch_file():
    xml_file = \
        """\
        <launch deprecated="MY_DEPRECATED_MESSAGE"/>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    assert isinstance(ld, LaunchDescription)
    assert 'MY_DEPRECATED_MESSAGE' == ld.deprecated_reason
Exemple #11
0
def test_arg_wrong_attribute():
    xml_file = \
        """\
        <launch>
            <arg name="my_arg" whats_this="hello" default="asd" description="something"/>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    with pytest.raises(ValueError) as excinfo:
        parser.parse_description(root_entity)
    assert '`arg`' in str(excinfo.value)
    assert 'whats_this' in str(excinfo.value)
Exemple #12
0
def test_arg():
    xml_file = \
        """\
        <launch>
            <arg name="my_arg" default="asd" description="something"/>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    arg = ld.entities[0]
    assert 'my_arg' == arg.name
    assert 'asd' == ''.join([x.perform(None) for x in arg.default_value])
    assert 'something' == arg.description
def test_unset_env():
    xml_file = \
        """\
        <launch>
            <unset_env name="my_env_var"/>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    assert len(ld.entities) == 1
    unset_env = ld.entities[0]
    assert isinstance(unset_env, UnsetEnvironmentVariable)
    assert 'my_env_var' == ''.join([x.perform(None) for x in unset_env.name])
Exemple #14
0
def test_log():
    launch_context = LaunchContext()
    xml_file = \
        """\
        <launch>
            <log message="Hello world!" />
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    launch_description = parser.parse_description(root_entity)
    log_info = launch_description.entities[0]
    assert isinstance(log_info, LogInfo)
    assert perform_substitutions(launch_context,
                                 log_info.msg) == 'Hello world!'
Exemple #15
0
def test_group():
    xml_file = \
        """\
        <launch>
            <let name="foo" value="FOO"/>
            <let name="bar" value="BAR"/>
            <group scoped="True" forwarding="False">
                <keep name="bar" value="$(var bar)"/>
                <keep name="baz" value="BAZ"/>
                <let name="var1" value="asd"/>
                <let name="var2" value="asd"/>
            </group>
        </launch>
        """  # noqa: E501
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)

    assert isinstance(ld.entities[0], SetLaunchConfiguration)
    assert isinstance(ld.entities[1], SetLaunchConfiguration)
    assert isinstance(ld.entities[2], GroupAction)

    lc = LaunchContext()
    assert 0 == len(lc.launch_configurations)
    ld.entities[0].visit(lc)
    ld.entities[1].visit(lc)
    assert 2 == len(lc.launch_configurations)
    assert 'foo' in lc.launch_configurations.keys()
    assert 'FOO' == lc.launch_configurations['foo']
    assert 'bar' in lc.launch_configurations.keys()
    assert 'BAR' == lc.launch_configurations['bar']
    actions = ld.entities[2].execute(lc)
    assert 5 == len(actions)
    assert isinstance(actions[0], PushLaunchConfigurations)
    assert isinstance(actions[1], ResetLaunchConfigurations)
    assert isinstance(actions[2], SetLaunchConfiguration)
    assert isinstance(actions[3], SetLaunchConfiguration)
    assert isinstance(actions[4], PopLaunchConfigurations)
    actions[0].visit(lc)
    actions[1].visit(lc)
    assert 'foo' not in lc.launch_configurations.keys()
    assert 'bar' in lc.launch_configurations.keys()
    assert 'BAR' == lc.launch_configurations['bar']
    assert 'baz' in lc.launch_configurations.keys()
    assert 'BAZ' == lc.launch_configurations['baz']
    actions[2].visit(lc)
    actions[3].visit(lc)
    actions[4].visit(lc)
def test_list():
    """Parse tags with list attributes."""
    xml_file = \
        """\
        <root>
            <tag attr="1,2,3" attr-sep=","/>
            <tag attr="1 2 3" attr-sep=" "/>
            <tag attr="1, 2, 3" attr-sep=", "/>
        </root>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    tags = root_entity.children
    assert tags[0].get_attr('attr', data_type=List[str]) == ['1', '2', '3']
    assert tags[0].get_attr('attr', data_type=List[int]) == [1, 2, 3]
    assert tags[0].get_attr('attr', data_type=List[float]) == [1., 2., 3.]
Exemple #17
0
def test_timer():
    xml_file = \
        """\
        <launch>
            <timer period="5">
                <executable cmd="ls -las"/>
            </timer>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    timer = ld.entities[0]
    assert isinstance(timer, TimerAction)
    assert isinstance(timer.period, float)
    assert math.isclose(timer.period, 5.)
    assert len(timer.actions) == 1
Exemple #18
0
def test_timer_period_is_substitution():
    xml_file = \
        """\
        <launch>
            <timer period="$(var my_period 5)">
                <executable cmd="ls -las"/>
            </timer>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    timer = ld.entities[0]
    assert isinstance(timer, TimerAction)
    assert isinstance(timer.period, list)
    assert len(timer.period) == 1
    assert isinstance(timer.period[0], LaunchConfiguration)
    assert len(timer.actions) == 1
def test_let_var():
    """Parse let and var example."""
    xml_file = \
        """\
        <launch>
            <let name="var1" value="asd"/>
            <let name="var2" value="2 $(var var1)"/>
        </launch>
        """
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    context = LaunchContext()
    assert len(ld.entities) == 2
    ld.entities[0].execute(context)
    ld.entities[1].execute(context)
    assert context.launch_configurations['var1'] == 'asd'
    assert context.launch_configurations['var2'] == '2 asd'
Exemple #20
0
def test_group():
    xml_file = \
        """\
        <launch>
            <group scoped="False">
                <let name="var1" value="asd"/>
                <let name="var2" value="asd"/>
            </group>
        </launch>
        """  # noqa: E501
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    group = ld.entities[0]
    actions = group.execute(None)
    assert 2 == len(actions)
    assert isinstance(actions[0], SetLaunchConfiguration)
    assert isinstance(actions[1], SetLaunchConfiguration)
def test_node_frontend(file):
    """Parse node xml example."""
    root_entity, parser = Parser.load(io.StringIO(file))
    ld = parser.parse_description(root_entity)
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert (0 == ls.run())
    evaluated_parameters = evaluate_parameters(
        ls.context,
        ld.describe_sub_entities()[2]._Node__parameters)
    assert isinstance(evaluated_parameters[0], dict)
    assert isinstance(evaluated_parameters[1], dict)
    assert isinstance(evaluated_parameters[2], pathlib.Path)

    assert 'param1' in evaluated_parameters[0]
    assert evaluated_parameters[0]['param1'] == 'ads'

    param_dict = evaluated_parameters[1]
    assert 'param_group1.param_group2.param2' in param_dict
    assert 'param_group1.param3' in param_dict
    assert 'param_group1.param4' in param_dict
    assert 'param_group1.param5' in param_dict
    assert 'param_group1.param6' in param_dict
    assert 'param_group1.param7' in param_dict
    assert 'param_group1.param8' in param_dict
    assert 'param_group1.param9' in param_dict
    assert 'param_group1.param10' in param_dict
    assert 'param_group1.param11' in param_dict
    assert param_dict['param_group1.param_group2.param2'] == 2
    assert param_dict['param_group1.param3'] == (2, 5, 8)
    assert param_dict['param_group1.param4'] == (2, 5, 8)
    assert param_dict['param_group1.param5'] == '[2, 5, 8]'
    assert param_dict['param_group1.param6'] == (2., 5., 8.)
    assert param_dict['param_group1.param7'] == ('2', '5', '8')
    assert param_dict['param_group1.param8'] == ("'2'", "'5'", "'8'")
    assert param_dict['param_group1.param9'] == ("'2'", "'5'", "'8'")
    assert param_dict['param_group1.param10'] == ("'asd'", "'bsd'", "'csd'")
    assert param_dict['param_group1.param11'] == ('asd', 'bsd', 'csd')
    assert param_dict['param_group1.param12'] == ''

    listener_node_action = ld.describe_sub_entities()[3]
    listener_node_cmd = listener_node_action.process_details['cmd']
    assert [sys.executable, '-c',
            'import sys; print(sys.argv[1:])'] == listener_node_cmd[:3]
def test_include():
    """Parse node xml example."""
    # Always use posix style paths in launch XML files.
    path = (Path(__file__).parent / 'executable.xml').as_posix()
    xml_file = \
        """\
        <launch>
            <include file="{}"/>
        </launch>
        """.format(path)  # noqa: E501
    xml_file = textwrap.dedent(xml_file)
    root_entity, parser = Parser.load(io.StringIO(xml_file))
    ld = parser.parse_description(root_entity)
    include = ld.entities[0]
    assert isinstance(include, IncludeLaunchDescription)
    assert isinstance(include.launch_description_source, AnyLaunchDescriptionSource)
    ls = LaunchService(debug=True)
    ls.include_launch_description(ld)
    assert 0 == ls.run()
Exemple #23
0
def test_reset():
    yaml_file = \
        """\
        launch:
            - let:
                name: 'foo'
                value: 'FOO'
            - let:
                name: 'bar'
                value: 'BAR'
            - reset:
                keep:
                    -   name: 'bar'
                        value: $(var bar)
                    -   name: 'baz'
                        value: 'BAZ'
        """  # noqa: E501
    print('Load YAML')
    yaml_file = textwrap.dedent(yaml_file)
    print('Load Parser')
    root_entity, parser = Parser.load(io.StringIO(yaml_file))
    print('Parse Description')
    ld = parser.parse_description(root_entity)

    assert isinstance(ld.entities[0], SetLaunchConfiguration)
    assert isinstance(ld.entities[1], SetLaunchConfiguration)
    assert isinstance(ld.entities[2], ResetLaunchConfigurations)

    lc = LaunchContext()
    assert len(lc.launch_configurations) == 0
    ld.entities[0].visit(lc)
    ld.entities[1].visit(lc)
    assert len(lc.launch_configurations) == 2
    assert 'foo' in lc.launch_configurations.keys()
    assert lc.launch_configurations['foo'] == 'FOO'
    assert 'bar' in lc.launch_configurations.keys()
    assert lc.launch_configurations['bar'] == 'BAR'
    ld.entities[2].visit(lc)
    assert 'foo' not in lc.launch_configurations.keys()
    assert 'bar' in lc.launch_configurations.keys()
    assert lc.launch_configurations['bar'] == 'BAR'
    assert 'baz' in lc.launch_configurations.keys()
    assert lc.launch_configurations['baz'] == 'BAZ'
def test_executable():
    """Parse node xml example."""
    xml_file = str(Path(__file__).parent / 'executable.xml')
    root_entity, parser = Parser.load(xml_file)
    ld = parser.parse_description(root_entity)
    executable = ld.entities[0]
    cmd = [i[0].perform(None) for i in executable.cmd]
    assert cmd == ['ls', '-l', '-a', '-s']
    assert executable.cwd[0].perform(None) == '/'
    assert executable.name[0].perform(None) == 'my_ls'
    assert executable.shell is True
    assert executable.output == 'log'
    key, value = executable.additional_env[0]
    key = key[0].perform(None)
    value = value[0].perform(None)
    assert key == 'var'
    assert value == '1'
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert 0 == ls.run()
def test_group():
    yaml_file = \
        """\
        launch:
            - group:
                scoped: False
                children:
                    - let:
                        name: 'var1'
                        value: 'asd'
                    - let:
                        name: 'var2'
                        value: 'asd'
        """  # noqa: E501
    yaml_file = textwrap.dedent(yaml_file)
    root_entity, parser = Parser.load(io.StringIO(yaml_file))
    ld = parser.parse_description(root_entity)
    group = ld.entities[0]
    actions = group.execute(None)
    assert 2 == len(actions)
    assert isinstance(actions[0], SetLaunchConfiguration)
    assert isinstance(actions[1], SetLaunchConfiguration)
Exemple #26
0
def test_node_frontend(file):
    """Parse node xml example."""
    root_entity, parser = Parser.load(io.StringIO(file))
    ld = parser.parse_description(root_entity)
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert(0 == ls.run())
    evaluated_parameters = evaluate_parameters(
        ls.context,
        ld.describe_sub_entities()[2]._Node__parameters
    )
    assert isinstance(evaluated_parameters[0], pathlib.Path)
    assert isinstance(evaluated_parameters[1], dict)
    param_dict = evaluated_parameters[1]
    assert 'param1' in param_dict
    assert param_dict['param1'] == 'ads'
    assert 'param_group1.param_group2.param2' in param_dict
    assert 'param_group1.param3' in param_dict
    assert 'param_group1.param4' in param_dict
    assert 'param_group1.param5' in param_dict
    assert 'param_group1.param6' in param_dict
    assert 'param_group1.param7' in param_dict
    assert 'param_group1.param8' in param_dict
    assert 'param_group1.param9' in param_dict
    assert 'param_group1.param10' in param_dict
    assert 'param_group1.param11' in param_dict
    assert param_dict['param_group1.param_group2.param2'] == 2
    assert param_dict['param_group1.param3'] == (2, 5, 8)
    assert param_dict['param_group1.param4'] == (2, 5, 8)
    assert param_dict['param_group1.param5'] == '[2, 5, 8]'
    assert param_dict['param_group1.param6'] == (2., 5., 8.)
    assert param_dict['param_group1.param7'] == ('2', '5', '8')
    assert param_dict['param_group1.param8'] == ("'2'", "'5'", "'8'")
    assert param_dict['param_group1.param9'] == ("'2'", "'5'", "'8'")
    assert param_dict['param_group1.param10'] == ("'asd'", "'bsd'", "'csd'")
    assert param_dict['param_group1.param11'] == ('asd', 'bsd', 'csd')
    assert param_dict['param_group1.param12'] == ''
def check_launch_component_container(file):
    root_entity, parser = Parser.load(file)
    ld = parser.parse_description(root_entity)
    ls = LaunchService()
    ls.include_launch_description(ld)

    loop = osrf_pycommon.process_utils.get_loop()
    launch_task = loop.create_task(ls.run_async())

    node_container, load_composable_node = ld.describe_sub_entities()
    talker = node_container._ComposableNodeContainer__composable_node_descriptions[
        0]
    listener = load_composable_node._LoadComposableNodes__composable_node_descriptions[
        0]

    def perform(substitution):
        return perform_substitutions(ls.context, substitution)

    # Check container params
    assert perform(node_container._Node__package) == 'rclcpp_components'
    assert perform(
        node_container._Node__node_executable) == 'component_container'
    assert perform(node_container._Node__node_name) == 'my_container'
    assert perform(node_container._Node__node_namespace) == ''
    assert perform(node_container._Node__arguments[0]) == 'test_args'

    assert perform(load_composable_node._LoadComposableNodes__target_container
                   ) == 'my_container'

    # Check node parameters
    talker_remappings = list(talker._ComposableNode__remappings)
    listener_remappings = list(listener._ComposableNode__remappings)

    talker_params = evaluate_parameters(ls.context,
                                        talker._ComposableNode__parameters)
    listener_params = evaluate_parameters(ls.context,
                                          listener._ComposableNode__parameters)

    talker_extra_args = evaluate_parameters(
        ls.context, talker._ComposableNode__extra_arguments)
    listener_extra_args = evaluate_parameters(
        ls.context, listener._ComposableNode__extra_arguments)

    assert perform(talker._ComposableNode__package) == 'composition'
    assert perform(
        talker._ComposableNode__node_plugin) == 'composition::Talker'
    assert perform(talker._ComposableNode__node_name) == 'talker'
    assert perform(talker._ComposableNode__node_namespace) == 'test_namespace'
    assert (perform(talker_remappings[0][0]),
            perform(talker_remappings[0][1])) == ('chatter', '/remap/chatter')
    assert talker_params[0]['use_sim_time'] is True

    assert perform(listener._ComposableNode__package) == 'composition'
    assert perform(
        listener._ComposableNode__node_plugin) == 'composition::Listener'
    assert perform(listener._ComposableNode__node_name) == 'listener'
    assert perform(
        listener._ComposableNode__node_namespace) == 'test_namespace'
    assert (perform(listener_remappings[0][0]),
            perform(listener_remappings[0][1])) == ('chatter',
                                                    '/remap/chatter')
    assert listener_params[0]['use_sim_time'] is True

    # Check extra arguments
    assert talker_extra_args[0]['use_intra_process_comms'] is True
    assert listener_extra_args[0]['use_intra_process_comms'] is True

    timeout_sec = 5
    loop.run_until_complete(asyncio.sleep(timeout_sec))
    if not launch_task.done():
        loop.create_task(ls.shutdown())
        loop.run_until_complete(launch_task)
    assert 0 == launch_task.result()
def test_append_env():
    yaml_file = \
        """\
        launch:
        -   append_env:
                name: my_env_var
                value: asd
        -   append_env:
                name: my_env_var
                value: zxc
                separator: "|"
        -   append_env:
                name: my_other_env_var
                value: fgh
        -   append_env:
                name: my_other_env_var
                value: jkl
                prepend: false
        -   append_env:
                name: my_other_env_var
                value: qwe
                prepend: yes
        -   append_env:
                name: my_other_env_var
                value: rty
                prepend: true
                separator: "|"
        """
    yaml_file = textwrap.dedent(yaml_file)
    root_entity, parser = Parser.load(io.StringIO(yaml_file))
    ld = parser.parse_description(root_entity)
    assert len(ld.entities) == 6
    assert isinstance(ld.entities[0], AppendEnvironmentVariable)
    assert isinstance(ld.entities[1], AppendEnvironmentVariable)
    assert isinstance(ld.entities[2], AppendEnvironmentVariable)
    assert isinstance(ld.entities[3], AppendEnvironmentVariable)
    assert isinstance(ld.entities[4], AppendEnvironmentVariable)
    assert isinstance(ld.entities[5], AppendEnvironmentVariable)
    assert 'my_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[0].name])
    assert 'my_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[0].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[2].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[3].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[4].name])
    assert 'my_other_env_var' == ''.join(
        [x.perform(None) for x in ld.entities[5].name])
    assert 'asd' == ''.join([x.perform(None) for x in ld.entities[0].value])
    assert 'zxc' == ''.join([x.perform(None) for x in ld.entities[1].value])
    assert 'fgh' == ''.join([x.perform(None) for x in ld.entities[2].value])
    assert 'jkl' == ''.join([x.perform(None) for x in ld.entities[3].value])
    assert 'qwe' == ''.join([x.perform(None) for x in ld.entities[4].value])
    assert 'rty' == ''.join([x.perform(None) for x in ld.entities[5].value])
    assert not ld.entities[0].prepend
    assert not ld.entities[1].prepend
    assert not ld.entities[2].prepend
    assert not ld.entities[3].prepend
    assert ld.entities[4].prepend
    assert ld.entities[5].prepend
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[0].separator])
    assert '|' == ''.join([x.perform(None) for x in ld.entities[1].separator])
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[2].separator])
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[3].separator])
    assert os.pathsep == ''.join(
        [x.perform(None) for x in ld.entities[4].separator])
    assert '|' == ''.join([x.perform(None) for x in ld.entities[5].separator])