def test_matches_with_callable(): target_action = Mock(spec=ExecuteProcess) handler = OnProcessIO(target_action=target_action) assert handler.matches( ProcessIO(action=target_action, name='foo', cmd=['ls'], cwd=None, env=None, pid=3, text=b'phony io', fd=0)) assert not handler.matches(phony_process_started) assert handler.matches(phony_process_io)
def test_handle_callable_stdin(): mock_stdin_callable = Mock() mock_stdout_callable = Mock() mock_stderr_callable = Mock() handler = OnProcessIO(on_stdin=mock_stdin_callable, on_stdout=mock_stdout_callable, on_stderr=mock_stderr_callable) event = ProcessIO(action=Mock(spec=Action), name='stdin', cmd=['ls'], cwd=None, env=None, pid=1, text=b'stdin', fd=0) handler.handle(event, phony_context) mock_stdin_callable.assert_called_once_with(event) mock_stdout_callable.assert_not_called() mock_stderr_callable.assert_not_called()
from launch.event_handlers.on_process_io import OnProcessIO from launch.events.process import ProcessIO 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_io = ProcessIO(action=Mock(spec=Action), name='PhonyProcessIO', cmd=['ls'], cwd=None, env=None, pid=1, text=b'phony io', fd=0) phony_context = Mock(spec=LaunchContext) def test_non_execute_target(): with pytest.raises(TypeError): OnProcessIO(target_action=NonCallableMock()) def test_matches_process_io(): handler = OnProcessIO() assert handler.matches(phony_process_io) assert not handler.matches(phony_process_started)