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
10 changes: 7 additions & 3 deletions launch/launch/actions/execute_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def __init__(
:param: additional_env dictionary of environment variables to be added.
If 'env' was None, they are added to the current environment.
If not, 'env' is updated with additional_env.
:param: shell if True, a shell is used to execute the cmd
:param: shell if True, a shell is used to execute the cmd. This must be
a boolean value in XML launch files; substitutions are not supported.
:param: sigterm_timeout time until shutdown should escalate to SIGTERM,
as a string or a list of strings and Substitutions to be resolved
at runtime, defaults to the LaunchConfiguration called
Expand All @@ -211,6 +212,8 @@ def __init__(
be overridden with the LaunchConfiguration called 'emulate_tty',
the value of which is evaluated as true or false according to
:py:func:`evaluate_condition_expression`.
In XML launch files, this attribute must be a boolean value;
substitutions are not supported.
Throws :py:exc:`InvalidConditionExpressionError` if the
'emulate_tty' configuration does not represent a boolean.
:param: prefix a set of commands/arguments to precede the cmd, used for
Expand Down Expand Up @@ -411,12 +414,13 @@ def parse(
kwargs['sigterm_timeout'] = str(sigterm_timeout)

if 'shell' not in ignore:
shell = entity.get_attr('shell', data_type=bool, optional=True)
shell = entity.get_attr('shell', data_type=bool, optional=True, can_be_str=False)
if shell is not None:
kwargs['shell'] = shell

if 'emulate_tty' not in ignore:
emulate_tty = entity.get_attr('emulate_tty', data_type=bool, optional=True)
emulate_tty = entity.get_attr(
'emulate_tty', data_type=bool, optional=True, can_be_str=False)
if emulate_tty is not None:
kwargs['emulate_tty'] = emulate_tty

Expand Down
29 changes: 29 additions & 0 deletions launch_xml/test/launch_xml/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,35 @@ def test_executable_wrong_subtag():
assert 'whats_this' in str(excinfo.value)


@pytest.mark.parametrize(
'value', ['true', 'false', 'True', 'False', 'yes', 'no', 'on', 'off', '1', '0'])
@pytest.mark.parametrize('attribute', ['shell', 'emulate_tty'])
def test_executable_accepts_boolean_values(attribute, value):
"""Accept the boolean spellings supported by the XML type converter."""
xml_file = textwrap.dedent(f"""
<launch>
<executable cmd="echo test" {attribute}="{value}" />
</launch>
""")
root_entity, parser = load_no_extensions(io.StringIO(xml_file))
executable = parser.parse_description(root_entity).entities[0]
assert getattr(executable, attribute) is (value.lower() in ('true', 'yes', 'on', '1'))


@pytest.mark.parametrize('attribute', ['shell', 'emulate_tty'])
def test_executable_rejects_arbitrary_boolean_strings(attribute):
"""Reject arbitrary strings for boolean executable attributes."""
for value in ('', ' ', 'not-a-boolean', '$(var flag)'):
xml_file = textwrap.dedent(f"""
<launch>
<executable cmd="echo test" {attribute}="{value}" />
</launch>
""")
root_entity, parser = load_no_extensions(io.StringIO(xml_file))
with pytest.raises(TypeError, match=attribute):
parser.parse_description(root_entity)


def test_executable_on_exit():
xml_file = \
"""\
Expand Down