Skip to content

Commit

Permalink
Add testing for launch prefix filtering
Browse files Browse the repository at this point in the history
Signed-off-by: Cameron Miller <cammlle@amazon.com>
  • Loading branch information
Cameron Miller committed Aug 18, 2021
1 parent b6d5e67 commit ad4dc2c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions launch/test/launch/test_execute_process.py
Expand Up @@ -19,8 +19,10 @@
import signal
import sys

from launch import LaunchContext
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import SetLaunchConfiguration
from launch.actions.emit_event import EmitEvent
from launch.actions.execute_process import ExecuteProcess
from launch.actions.opaque_function import OpaqueFunction
Expand Down Expand Up @@ -168,3 +170,40 @@ def generate_launch_description():
ls.include_launch_description(generate_launch_description())
assert 0 == ls.run()
assert expected_called_count == on_exit_callback.called_count


def test_execute_process_prefix_filter_match():
lc = LaunchContext()
SetLaunchConfiguration('launch-prefix', 'time').visit(lc)
assert len(lc.launch_configurations) == 1
SetLaunchConfiguration(
'launch-prefix-filter',
f'{os.path.basename(sys.executable)}').visit(lc)
assert len(lc.launch_configurations) == 2

test_process = ExecuteProcess(
cmd=[sys.executable, '-c', "print('action')"],
output='screen'
)

test_process.execute(lc)

assert 'time' in test_process.process_details()['cmd']


def test_execute_process_prefix_filter_no_match():
lc = LaunchContext()
SetLaunchConfiguration('launch-prefix', 'time').visit(lc)
assert len(lc.launch_configurations) == 1
SetLaunchConfiguration(
'launch-prefix-filter', 'no-match').visit(lc)
assert len(lc.launch_configurations) == 2

test_process = ExecuteProcess(
cmd=[sys.executable, '-c', "print('action')"],
output='screen'
)

test_process.execute(lc)

assert 'time' not in test_process.process_details()['cmd']

0 comments on commit ad4dc2c

Please sign in to comment.