Ejemplo n.º 1
0
def test_asynchecker_run(patches, raises):
    checker = AsyncChecker()

    patched = patches(
        "asyncio",
        "Checker.exit",
        ("AsyncChecker._run", dict(new_callable=MagicMock)),
        ("AsyncChecker.on_checks_complete", dict(new_callable=MagicMock)),
        prefix="tools.base.checker")

    with patched as (m_async, m_exit, m_run, m_complete):
        if raises:
            m_run.side_effect = raises

            if raises == KeyboardInterrupt:
                result = checker.run()
            else:
                with pytest.raises(raises):
                    checker.run()
                return
        else:
            assert (
                checker.run()
                == m_async.get_event_loop.return_value.run_until_complete.return_value)

    if raises == KeyboardInterrupt:
        assert (
            list(m_exit.call_args)
            == [(), {}])
        assert (
            list(m_async.get_event_loop.call_args_list[1])
            == [(), {}])
        assert (
            list(m_async.get_event_loop.return_value.run_until_complete.call_args)
            == [(m_complete.return_value,), {}])
        assert (
            list(m_complete.call_args)
            == [(), {}])
        assert result == m_async.get_event_loop.return_value.run_until_complete.return_value
        return

    assert not m_exit.called
    assert (
        list(m_async.get_event_loop.call_args)
        == [(), {}])
    assert (
        list(m_async.get_event_loop.return_value.run_until_complete.call_args)
        == [(m_run.return_value,), {}])
    assert (
        list(m_run.call_args)
        == [(), {}])
Ejemplo n.º 2
0
def test_asynchecker_run(patches):
    checker = AsyncChecker()

    patched = patches("asyncio",
                      ("AsyncChecker._run", dict(new_callable=MagicMock)),
                      prefix="tools.base.checker")

    with patched as (m_async, m_run):
        assert (checker.run() == m_async.get_event_loop.return_value.
                run_until_complete.return_value)

    assert (list(m_async.get_event_loop.call_args) == [(), {}])
    assert (list(
        m_async.get_event_loop.return_value.run_until_complete.call_args) == [
            (m_run.return_value, ), {}
        ])
    assert (list(m_run.call_args) == [(), {}])