Ejemplo n.º 1
0
def test_scan_process():
  # TODO(jon): add more tests for successful cases; this really just looks for errors.

  assert TRH.scan_process(
      make_runner_state(cpid=None, pid=None), PROCESS_NAME) == (None, None, set())

  with mock.patch(PSUTIL_PATH) as p_mock:
    class WrappedNoSuchProcess(psutil.NoSuchProcess):
      # psutil.NoSuchProcess exception requires an argument, but mock doesn't support that.
      def __init__(self): pass
    p_mock.side_effect = WrappedNoSuchProcess
    assert TRH.scan_process(
        make_runner_state(cpid=None), PROCESS_NAME) == (None, None, set())
    assert TRH.scan_process(
        make_runner_state(pid=None), PROCESS_NAME) == (None, None, set())

  with mock.patch(PSUTIL_PATH) as p_mock:
    p_mock.side_effect = psutil.Error
    assert TRH.scan_process(
        make_runner_state(cpid=None), PROCESS_NAME) == (None, None, set())
    assert TRH.scan_process(
        make_runner_state(pid=None), PROCESS_NAME) == (None, None, set())

  with mock.patch(TRH_PATH) as trh_mock:
    trh_mock.this_is_really_our_pid.returns = False
    assert TRH.scan_process(
        make_runner_state(), PROCESS_NAME) == (None, None, set())

  with mock.patch(TRH_PATH) as trh_mock:
    trh_mock.this_is_really_our_pid.sideffect = psutil.Error
    assert TRH.scan_process(
        make_runner_state(), PROCESS_NAME) == (None, None, set())
Ejemplo n.º 2
0
def test_scan_process():
    # TODO(jon): add more tests for successful cases; this really just looks for errors.

    assert TRH.scan_process(make_runner_state(cpid=None, pid=None),
                            PROCESS_NAME) == (None, None, set())

    with mock.patch(PSUTIL_PATH) as p_mock:

        class WrappedNoSuchProcess(psutil.NoSuchProcess):
            # psutil.NoSuchProcess exception requires an argument, but mock doesn't support that.
            def __init__(self):
                pass

        p_mock.side_effect = WrappedNoSuchProcess
        assert TRH.scan_process(make_runner_state(cpid=None),
                                PROCESS_NAME) == (None, None, set())
        assert TRH.scan_process(make_runner_state(pid=None),
                                PROCESS_NAME) == (None, None, set())

    with mock.patch(PSUTIL_PATH) as p_mock:
        p_mock.side_effect = psutil.Error
        assert TRH.scan_process(make_runner_state(cpid=None),
                                PROCESS_NAME) == (None, None, set())
        assert TRH.scan_process(make_runner_state(pid=None),
                                PROCESS_NAME) == (None, None, set())

    with mock.patch(TRH_PATH) as trh_mock:
        trh_mock.this_is_really_our_pid.returns = False
        assert TRH.scan_process(make_runner_state(),
                                PROCESS_NAME) == (None, None, set())

    with mock.patch(TRH_PATH) as trh_mock:
        trh_mock.this_is_really_our_pid.sideffect = psutil.Error
        assert TRH.scan_process(make_runner_state(),
                                PROCESS_NAME) == (None, None, set())