示例#1
0
async def test_asynchecker_on_check_run(patches):
    checker = AsyncChecker()
    patched = patches("BaseChecker.on_check_run", prefix="tools.base.checker")

    with patched as (m_super, ):
        assert not await checker.on_check_run("CHECKNAME")

    assert (list(m_super.call_args) == [('CHECKNAME', ), {}])
示例#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) == [(), {}])
示例#3
0
async def test_asynchecker_on_checks_begin(patches):
    checker = AsyncChecker()
    patched = patches("BaseChecker.on_checks_begin",
                      prefix="tools.base.checker")

    with patched as (m_super, ):
        assert not await checker.on_checks_begin()

    assert (list(m_super.call_args) == [(), {}])
示例#4
0
async def test_asynchecker_on_checks_complete(patches):
    checker = AsyncChecker()

    patched = patches("BaseChecker.on_checks_complete",
                      prefix="tools.base.checker")

    with patched as (m_complete, ):
        assert (await checker.on_checks_complete() == m_complete.return_value)

    assert (list(m_complete.call_args) == [(), {}])
示例#5
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)
        == [(), {}])
示例#6
0
def test_asynchecker_constructor():
    checker = AsyncChecker()
    assert isinstance(checker, BaseChecker)
示例#7
0
async def test_asynchecker_on_checks_begin():
    checker = AsyncChecker()

    assert not await checker.on_checks_begin()
示例#8
0
async def test_asynchecker_on_check_run():
    checker = AsyncChecker()

    assert not await checker.on_check_run("CHECKNAME")