Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added case for instances of ExecuteLocal in resolveProcess function #587

Merged
merged 2 commits into from
Feb 22, 2022
Merged
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: 7 additions & 2 deletions launch_testing/launch_testing/util/proc_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def _proc_to_name_and_args(proc):
def perform_subs(subs):
return ''.join([sub.perform(_fake_context()) for sub in subs])
try:
cmd = [perform_subs(sub) for sub in proc.cmd]
cmd = []
if (isinstance(proc, launch.actions.ExecuteProcess)):
cmd = [perform_subs(sub) for sub in proc.cmd]
elif (isinstance(proc, launch.actions.ExecuteLocal)):
cmd = [perform_subs(sub) for sub in proc.process_description.cmd]
return ' '.join(cmd)
except _FakeContextException:
return 'Unknown - Process not launched yet'
Expand Down Expand Up @@ -104,7 +108,8 @@ def resolveProcesses(info_obj, *, process=None, cmd_args=None, strict_proc_match
raise NoMatchingProcessException('No data recorded for any process')
return all_procs

if isinstance(process, launch.actions.ExecuteProcess):
if (isinstance(process, launch.actions.ExecuteProcess) or
isinstance(process, launch.actions.ExecuteLocal)):
# We want to search a specific process
if process in info_obj.processes():
return [process]
Expand Down
47 changes: 47 additions & 0 deletions launch_testing/test/launch_testing/test_resolve_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ class TestResolveProcess(unittest.TestCase):
def test_unlaunched_process_lookup(self):
info_obj = launch_testing.ProcInfoHandler()

lookup_obj = launch.actions.ExecuteLocal(
process_description=launch.descriptions.Executable(
cmd=[
'python',
'-c',
'',
]
)
)

with self.assertRaises(launch_testing.util.NoMatchingProcessException) as cm:
launch_testing.util.resolveProcesses(
info_obj,
process=lookup_obj
)

# We'll get a good error mesasge here because there were no substitutions in
# the execute process cmd - it's all text
self.assertIn('python -c', str(cm.exception))

def test_backward_compatible_unlaunched_process_lookup(self):
info_obj = launch_testing.ProcInfoHandler()

lookup_obj = launch.actions.ExecuteProcess(
cmd=[
'python',
Expand All @@ -53,6 +76,30 @@ def test_unlaunched_process_lookup(self):
def test_unlaunched_process_lookup_with_substitutions(self):
info_obj = launch_testing.ProcInfoHandler()

lookup_obj = launch.actions.ExecuteLocal(
process_description=launch.descriptions.Executable(
cmd=[
launch.substitutions.LocalSubstitution('foo'),
'python',
'-c',
'',
]
)
)

with self.assertRaises(launch_testing.util.NoMatchingProcessException) as cm:
launch_testing.util.resolveProcesses(
info_obj,
process=lookup_obj
)

# Since the process wasn't launched yet, and it has substitutions that need to be
# resolved by the launch system, we won't be able to take a guess at the command
self.assertIn('Unknown', str(cm.exception))

def test_backward_compatible_unlaunched_process_lookup_with_substitutions(self):
info_obj = launch_testing.ProcInfoHandler()

lookup_obj = launch.actions.ExecuteProcess(
cmd=[
launch.substitutions.LocalSubstitution('foo'),
Expand Down