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
9 changes: 9 additions & 0 deletions launch/launch/actions/execute_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@ def parse(
if 'respawn_delay' not in ignore:
respawn_delay = entity.get_attr('respawn_delay', data_type=float, optional=True)
if respawn_delay is not None:
if isinstance(respawn_delay, str):
try:
respawn_delay = float(respawn_delay)
except ValueError:
raise ValueError(
'Attribute respawn_delay of Entity node expected to be '
'a non-negative floating-point value but got `{}`'.format(
respawn_delay)
) from None
if respawn_delay < 0.0:
raise ValueError(
'Attribute respawn_delay of Entity node expected to be '
Expand Down
34 changes: 34 additions & 0 deletions launch_yaml/test/launch_yaml/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

from launch import LaunchService
from launch.actions import Shutdown
from launch.actions.execute_process import ExecuteProcess

from parser_no_extensions import load_no_extensions
import pytest


def test_executable():
Expand Down Expand Up @@ -82,5 +84,37 @@ def test_executable_on_exit():
assert isinstance(sub_entities[0], Shutdown)


def test_executable_respawn_delay_string():
yaml_file = textwrap.dedent(
"""
launch:
- executable:
cmd: echo test
respawn_delay: '2.0'
"""
)
root_entity, parser = load_no_extensions(io.StringIO(yaml_file))

_, kwargs = ExecuteProcess.parse(root_entity.children[0], parser)

assert kwargs['respawn_delay'] == 2.0
assert isinstance(kwargs['respawn_delay'], float)


def test_executable_respawn_delay_invalid_string():
yaml_file = textwrap.dedent(
"""
launch:
- executable:
cmd: echo test
respawn_delay: ''
"""
)
root_entity, parser = load_no_extensions(io.StringIO(yaml_file))

with pytest.raises(ValueError, match='respawn_delay'):
ExecuteProcess.parse(root_entity.children[0], parser)


if __name__ == '__main__':
test_executable()