diff --git a/launch/launch/actions/execute_process.py b/launch/launch/actions/execute_process.py index c74d062d8..8d741d2ca 100644 --- a/launch/launch/actions/execute_process.py +++ b/launch/launch/actions/execute_process.py @@ -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 ' diff --git a/launch_yaml/test/launch_yaml/test_executable.py b/launch_yaml/test/launch_yaml/test_executable.py index 84bac7183..c2a241281 100644 --- a/launch_yaml/test/launch_yaml/test_executable.py +++ b/launch_yaml/test/launch_yaml/test_executable.py @@ -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(): @@ -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()