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', ), {}])
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) == [(), {}])
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) == [(), {}])
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) == [(), {}])
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) == [(), {}])
def test_asynchecker_constructor(): checker = AsyncChecker() assert isinstance(checker, BaseChecker)
async def test_asynchecker_on_checks_begin(): checker = AsyncChecker() assert not await checker.on_checks_begin()
async def test_asynchecker_on_check_run(): checker = AsyncChecker() assert not await checker.on_check_run("CHECKNAME")