Skip to content

Commit 21986e0

Browse files
authored
Added case for instances of ExecuteLocal in resolveProcess function (#587)
* Added case for instances of ExecuteLocal & unit tests Signed-off-by: matthew.lanting <[email protected]>
1 parent 13d0c28 commit 21986e0

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

launch_testing/launch_testing/util/proc_lookup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def _proc_to_name_and_args(proc):
5151
def perform_subs(subs):
5252
return ''.join([sub.perform(_fake_context()) for sub in subs])
5353
try:
54-
cmd = [perform_subs(sub) for sub in proc.cmd]
54+
cmd = []
55+
if (isinstance(proc, launch.actions.ExecuteProcess)):
56+
cmd = [perform_subs(sub) for sub in proc.cmd]
57+
elif (isinstance(proc, launch.actions.ExecuteLocal)):
58+
cmd = [perform_subs(sub) for sub in proc.process_description.cmd]
5559
return ' '.join(cmd)
5660
except _FakeContextException:
5761
return 'Unknown - Process not launched yet'
@@ -104,7 +108,8 @@ def resolveProcesses(info_obj, *, process=None, cmd_args=None, strict_proc_match
104108
raise NoMatchingProcessException('No data recorded for any process')
105109
return all_procs
106110

107-
if isinstance(process, launch.actions.ExecuteProcess):
111+
if (isinstance(process, launch.actions.ExecuteProcess) or
112+
isinstance(process, launch.actions.ExecuteLocal)):
108113
# We want to search a specific process
109114
if process in info_obj.processes():
110115
return [process]

launch_testing/test/launch_testing/test_resolve_process.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@ class TestResolveProcess(unittest.TestCase):
3232
def test_unlaunched_process_lookup(self):
3333
info_obj = launch_testing.ProcInfoHandler()
3434

35+
lookup_obj = launch.actions.ExecuteLocal(
36+
process_description=launch.descriptions.Executable(
37+
cmd=[
38+
'python',
39+
'-c',
40+
'',
41+
]
42+
)
43+
)
44+
45+
with self.assertRaises(launch_testing.util.NoMatchingProcessException) as cm:
46+
launch_testing.util.resolveProcesses(
47+
info_obj,
48+
process=lookup_obj
49+
)
50+
51+
# We'll get a good error mesasge here because there were no substitutions in
52+
# the execute process cmd - it's all text
53+
self.assertIn('python -c', str(cm.exception))
54+
55+
def test_backward_compatible_unlaunched_process_lookup(self):
56+
info_obj = launch_testing.ProcInfoHandler()
57+
3558
lookup_obj = launch.actions.ExecuteProcess(
3659
cmd=[
3760
'python',
@@ -53,6 +76,30 @@ def test_unlaunched_process_lookup(self):
5376
def test_unlaunched_process_lookup_with_substitutions(self):
5477
info_obj = launch_testing.ProcInfoHandler()
5578

79+
lookup_obj = launch.actions.ExecuteLocal(
80+
process_description=launch.descriptions.Executable(
81+
cmd=[
82+
launch.substitutions.LocalSubstitution('foo'),
83+
'python',
84+
'-c',
85+
'',
86+
]
87+
)
88+
)
89+
90+
with self.assertRaises(launch_testing.util.NoMatchingProcessException) as cm:
91+
launch_testing.util.resolveProcesses(
92+
info_obj,
93+
process=lookup_obj
94+
)
95+
96+
# Since the process wasn't launched yet, and it has substitutions that need to be
97+
# resolved by the launch system, we won't be able to take a guess at the command
98+
self.assertIn('Unknown', str(cm.exception))
99+
100+
def test_backward_compatible_unlaunched_process_lookup_with_substitutions(self):
101+
info_obj = launch_testing.ProcInfoHandler()
102+
56103
lookup_obj = launch.actions.ExecuteProcess(
57104
cmd=[
58105
launch.substitutions.LocalSubstitution('foo'),

0 commit comments

Comments
 (0)