示例#1
0
def test_launch_description_get_launch_arguments():
    """Test the get_launch_arguments() method of the LaunchDescription class."""
    ld = LaunchDescription([])
    assert len(ld.get_launch_arguments()) == 0

    ld = LaunchDescription([DeclareLaunchArgument('foo')])
    la = ld.get_launch_arguments()
    assert len(la) == 1
    assert la[0]._conditionally_included is False

    ld = LaunchDescription(
        [DeclareLaunchArgument('foo', condition=IfCondition('True'))])
    la = ld.get_launch_arguments()
    assert len(la) == 1
    assert la[0]._conditionally_included is True

    ld = LaunchDescription([
        IncludeLaunchDescription(
            LaunchDescriptionSource(
                LaunchDescription([
                    DeclareLaunchArgument('foo'),
                ]))),
    ])
    la = ld.get_launch_arguments()
    assert len(la) == 1
    assert la[0]._conditionally_included is False

    this_dir = os.path.dirname(os.path.abspath(__file__))
    ld = LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(this_dir,
                             'launch_file_with_argument.launch.py'))),
    ])
    la = ld.get_launch_arguments()
    assert len(la) == 1
    assert la[0]._conditionally_included is False

    ld = LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource([
                # This will prevent loading of this launch file to find arguments in it.
                ThisLaunchFileDir(),
                'launch_file_with_argument.launch.py',
            ])),
    ])
    la = ld.get_launch_arguments()
    assert len(la) == 0
def test_launch_description_get_launch_arguments():
    """Test the get_launch_arguments() method of the LaunchDescription class."""
    ld = LaunchDescription([])
    assert len(ld.get_launch_arguments()) == 0

    ld = LaunchDescription([DeclareLaunchArgument('foo')])
    la = ld.get_launch_arguments()
    assert len(la) == 1
    assert la[0]._conditionally_included is False

    ld = LaunchDescription(
        [DeclareLaunchArgument('foo', condition=IfCondition('True'))])
    la = ld.get_launch_arguments()
    assert len(la) == 1
    assert la[0]._conditionally_included is True

    ld = LaunchDescription([
        IncludeLaunchDescription(
            LaunchDescriptionSource(
                LaunchDescription([
                    DeclareLaunchArgument('foo'),
                ]))),
    ])
    la = ld.get_launch_arguments()
    assert len(la) == 1

    this_dir = os.path.dirname(os.path.abspath(__file__))
    ld = LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(this_dir,
                             'launch_file_with_argument.launch.py'))),
    ])
    la = ld.get_launch_arguments()
    assert len(la) == 1

    # From issue #144: get_launch_arguments was broken when an entitity had conditional
    # sub entities
    class EntityWithConditional(LaunchDescriptionEntity):
        def describe_conditional_sub_entities(self):
            return [('String describing condition',
                     [DeclareLaunchArgument('foo')])]

    ld = LaunchDescription([EntityWithConditional()])
    la = ld.get_launch_arguments()
    assert len(la) == 1