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
13 changes: 13 additions & 0 deletions launch/launch/actions/execute_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,19 @@ def parse(
respawn_max_retries = entity.get_attr('respawn_max_retries', data_type=int,
optional=True)
if respawn_max_retries is not None:
if isinstance(respawn_max_retries, bool):
raise ValueError(
'Attribute respawn_max_retries of Entity `{}` expected to be '
'an integer but got `{}`'.format(entity.type_name, respawn_max_retries)
)
if isinstance(respawn_max_retries, str):
try:
respawn_max_retries = int(respawn_max_retries)
except ValueError:
raise ValueError(
'Attribute respawn_max_retries of Entity `{}` expected to be '
'an integer but got `{}`'.format(entity.type_name, respawn_max_retries)
) from None
kwargs['respawn_max_retries'] = respawn_max_retries

if 'respawn_delay' not in ignore:
Expand Down
49 changes: 49 additions & 0 deletions launch_yaml/test/launch_yaml/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

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

import pytest

from parser_no_extensions import load_no_extensions

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


def test_executable_respawn_max_retries_string_zero():
yaml_file = \
"""\
launch:
- executable:
cmd: echo test
respawn_max_retries: '0'
"""
yaml_file = textwrap.dedent(yaml_file)
root_entity, parser = load_no_extensions(io.StringIO(yaml_file))
_, kwargs = ExecuteProcess.parse(root_entity.children[0], parser)

assert kwargs['respawn_max_retries'] == 0
assert isinstance(kwargs['respawn_max_retries'], int)


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

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


def test_executable_respawn_max_retries_bool_error():
yaml_file = \
"""\
launch:
- executable:
cmd: echo test
respawn_max_retries: true
"""
yaml_file = textwrap.dedent(yaml_file)
root_entity, parser = load_no_extensions(io.StringIO(yaml_file))

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


if __name__ == '__main__':
test_executable()