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 1be7845
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions launch/test/launch/test_execute_process.py
Expand Up @@ -14,13 +14,16 @@

"""Tests for the ExecuteProcess Action."""

import asyncio
import os
import platform
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 +171,41 @@ 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()
lc._set_asyncio_loop(asyncio.get_event_loop())
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 1be7845

Please sign in to comment.