def test_matches_single_process():
    target_action = Mock(spec=ExecuteProcess)
    handler = OnProcessExit(
        target_action=target_action,
        on_exit=Mock())
    assert handler.matches(ProcessExited(
        action=target_action, name='foo', cmd=['ls'], cwd=None, env=None, pid=3,
        returncode=0))
    assert not handler.matches(phony_process_started)
    assert not handler.matches(phony_process_exited)
    def test_assert_exit_code_allows_specific_codes(self):
        self.dummy_proc_info.append(
            ProcessExited(
                action=object(),
                name='test_process_1',
                cmd=['test_process'],
                pid=10,
                returncode=131,
                cwd=None,
                env=None,
            ))

        assertExitCodes(self.dummy_proc_info, allowable_exit_codes=[0, 131])
    def setUp(self):
        self.dummy_proc_info = ProcInfoHandler()

        for n in range(4):
            proc_data = ProcessExited(
                action=object(),
                name='process_{}'.format(n),
                cmd=['process'],
                pid=n,
                returncode=0,
                cwd=None,
                env=None,
            )
            self.dummy_proc_info.append(proc_data)
    def test_assert_exit_codes_notices_error(self):
        self.dummy_proc_info.append(
            ProcessExited(
                action=object(),
                name='test_process_1',
                cmd=['test_process'],
                pid=10,
                returncode=1,
                cwd=None,
                env=None,
            ))

        with self.assertRaises(AssertionError) as cm:
            assertExitCodes(self.dummy_proc_info)

        # Check that the process name made it into the error message
        self.assertIn('test_process_1', str(cm.exception))
예제 #5
0
from launch.event_handlers.on_process_start import OnProcessStart
from launch.events.process import ProcessExited
from launch.events.process import ProcessStarted

import pytest

phony_process_started = ProcessStarted(action=Mock(spec=Action),
                                       name='PhonyProcessStarted',
                                       cmd=['ls'],
                                       cwd=None,
                                       env=None,
                                       pid=1)
phony_process_exited = ProcessExited(action=Mock(spec=Action),
                                     name='PhonyProcessExited',
                                     cmd=['ls'],
                                     cwd=None,
                                     env=None,
                                     pid=2,
                                     returncode=0)
phony_context = Mock(spec=LaunchContext)


def test_non_execute_process_target():
    with pytest.raises(TypeError):
        OnProcessStart(target_action=NonCallableMock(),
                       on_start=NonCallableMock(spec=Action))


def test_non_action_on_start():
    with pytest.raises(TypeError):
        OnProcessStart(target_action=NonCallableMock(),