Esempio n. 1
0
def test_handle_once():
    context = Mock(spec=LaunchContext)
    unregister_event_handler_mock = context.unregister_event_handler

    handler = OnProcessIO(handle_once=True)
    handler.handle(phony_process_io, context)
    unregister_event_handler_mock.assert_called_once_with(handler)
Esempio n. 2
0
def test_event_added_to_context():
    context = Mock(spec=LaunchContext)
    extend_locals_mock = context.extend_locals
    unregister_event_handler_mock = context.unregister_event_handler

    handler = OnProcessIO()
    handler.handle(phony_process_io, context)
    extend_locals_mock.assert_called_once_with({'event': phony_process_io})
    unregister_event_handler_mock.assert_not_called()
Esempio n. 3
0
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)
Esempio n. 4
0
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()
Esempio n. 5
0
def test_matches_process_io():
    handler = OnProcessIO()
    assert handler.matches(phony_process_io)
    assert not handler.matches(phony_process_started)
Esempio n. 6
0
def test_non_execute_target():
    with pytest.raises(TypeError):
        OnProcessIO(target_action=NonCallableMock())