Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions launch_xml/test/launch_xml/inner.launch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<arg name="inner_argument" />
</launch>
3 changes: 3 additions & 0 deletions launch_xml/test/launch_xml/inner_default.launch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<arg name="inner_argument" default="some default" />
</launch>
93 changes: 92 additions & 1 deletion launch_xml/test/launch_xml/test_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pathlib import Path
import textwrap

from launch import LaunchService
from launch import LaunchDescription, LaunchDescriptionSource, LaunchService
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import AnyLaunchDescriptionSource

Expand Down Expand Up @@ -54,5 +54,96 @@ def test_include():
assert ls.context.launch_configurations['baz'] == 'BAZ'


def include_inner(inner_launch_file: str):
# Always use posix style paths in launch XML files.
path = (Path(__file__).parent / inner_launch_file).as_posix()
xml_file = \
"""\
<launch>
<include file="{}"/>
</launch>
""".format(path) # noqa: E501
xml_file = textwrap.dedent(xml_file)
root_entity, parser = load_no_extensions(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)

return ld


def test_include_inner_argument_default_no_argument():
"""Test inner launch file having an argument with default value (no commandline input)."""
argument_name = 'inner_argument'
ld = include_inner('inner_default.launch.xml')

ls = LaunchService(debug=True)
# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(LaunchDescriptionSource(ld), launch_arguments=[])
]))
assert 0 == ls.run()
assert len(ls.context.launch_configurations) == 1
assert ls.context.launch_configurations == {argument_name: 'some default'}


def test_include_inner_argument_default_with_argument():
"""Test inner launch file having an argument with default value overwritten via commandline."""
argument_name = 'inner_argument'
argument_value = 'another_value'
ld = include_inner('inner_default.launch.xml')

ls = LaunchService(debug=True, argv=[f'{argument_name}:="{argument_value}"'])

# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(
LaunchDescriptionSource(ld),
launch_arguments=[(argument_name, argument_value)]
)
]))
assert 0 == ls.run()
assert len(ls.context.launch_configurations) == 1
assert ls.context.launch_configurations == {argument_name: argument_value}


def test_include_inner_argument_no_argument():
"""Test inner launch file having a required argument (no commandline input)."""
ld = include_inner('inner.launch.xml')

ls = LaunchService(debug=True)
# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(LaunchDescriptionSource(ld), launch_arguments=[])
]))
assert 1 == ls.run()
assert len(ls.context.launch_configurations) == 0


def test_include_inner_argument_with_argument():
"""Test inner launch file having a required argument overwritten via commandline."""
argument_name = 'inner_argument'
argument_value = 'another_value'
ld = include_inner('inner.launch.xml')

ls = LaunchService(debug=True, argv=[f'{argument_name}:="{argument_value}"'])

# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(
LaunchDescriptionSource(ld),
launch_arguments=[(argument_name, argument_value)]
)
]))
assert 0 == ls.run()
assert len(ls.context.launch_configurations) == 1
assert ls.context.launch_configurations == {argument_name: argument_value}


if __name__ == '__main__':
test_include()
test_include_inner_argument_default_no_argument()
test_include_inner_argument_default_with_argument()
test_include_inner_argument_no_argument()
test_include_inner_argument_with_argument()
3 changes: 3 additions & 0 deletions launch_yaml/test/launch_yaml/inner.launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
launch:
- arg:
name: inner_argument
4 changes: 4 additions & 0 deletions launch_yaml/test/launch_yaml/inner_default.launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
launch:
- arg:
name: inner_argument
default: some default
94 changes: 93 additions & 1 deletion launch_yaml/test/launch_yaml/test_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pathlib import Path
import textwrap

from launch import LaunchService
from launch import LaunchDescription, LaunchDescriptionSource, LaunchService
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import AnyLaunchDescriptionSource

Expand All @@ -27,6 +27,7 @@

def test_include():
"""Parse include YAML example."""
# Always use posix style paths in launch YAML files.
path = (Path(__file__).parent / 'executable.yaml').as_posix()
yaml_file = \
"""\
Expand Down Expand Up @@ -61,5 +62,96 @@ def test_include():
assert ls.context.launch_configurations['baz'] == 'BAZ'


def include_inner(inner_launch_file: str):
# Always use posix style paths in launch YAML files.
path = (Path(__file__).parent / inner_launch_file).as_posix()
yaml_file = \
"""\
launch:
- include:
file: "{}"
""".format(path) # noqa: E501
yaml_file = textwrap.dedent(yaml_file)
root_entity, parser = load_no_extensions(io.StringIO(yaml_file))
ld = parser.parse_description(root_entity)
include = ld.entities[0]
assert isinstance(include, IncludeLaunchDescription)
assert isinstance(include.launch_description_source, AnyLaunchDescriptionSource)

return ld


def test_include_inner_argument_default_no_argument():
"""Test inner launch file having an argument with default value (no commandline input)."""
argument_name = 'inner_argument'
ld = include_inner('inner_default.launch.yaml')

ls = LaunchService(debug=True)
# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(LaunchDescriptionSource(ld), launch_arguments=[])
]))
assert 0 == ls.run()
assert len(ls.context.launch_configurations) == 1
assert ls.context.launch_configurations == {argument_name: 'some default'}


def test_include_inner_argument_default_with_argument():
"""Test inner launch file having an argument with default value overwritten via commandline."""
argument_name = 'inner_argument'
argument_value = 'another_value'
ld = include_inner('inner_default.launch.yaml')

ls = LaunchService(debug=True, argv=[f'{argument_name}:="{argument_value}"'])

# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(
LaunchDescriptionSource(ld),
launch_arguments=[(argument_name, argument_value)]
)
]))
assert 0 == ls.run()
assert len(ls.context.launch_configurations) == 1
assert ls.context.launch_configurations == {argument_name: argument_value}


def test_include_inner_argument_no_argument():
"""Test inner launch file having a required argument value (no commandline input)."""
ld = include_inner('inner.launch.yaml')

ls = LaunchService(debug=True)
# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(LaunchDescriptionSource(ld), launch_arguments=[])
]))
assert 1 == ls.run()
assert len(ls.context.launch_configurations) == 0


def test_include_inner_argument_with_argument():
"""Test inner launch file having a required argument value overwritten via commandline."""
argument_name = 'inner_argument'
argument_value = 'another_value'
ld = include_inner('inner.launch.yaml')

ls = LaunchService(debug=True, argv=[f'{argument_name}:="{argument_value}"'])

# Pass the arguments as it is done in ros2launch
ls.include_launch_description(LaunchDescription([
IncludeLaunchDescription(
LaunchDescriptionSource(ld),
launch_arguments=[(argument_name, argument_value)]
)
]))
assert 0 == ls.run()
assert len(ls.context.launch_configurations) == 1
assert ls.context.launch_configurations == {argument_name: argument_value}


if __name__ == '__main__':
test_include()
test_include_inner_argument_default_no_argument()
test_include_inner_argument_default_with_argument()
test_include_inner_argument_no_argument()
test_include_inner_argument_with_argument()