async def test_start_client(self, *, app): app.maybe_start = AsyncMock(name='app.maybe_start') await app.start_client() assert app.client_only app.maybe_start.assert_called_once_with()
async def test_on_recovery_completed(self, *, table): table.call_recover_callbacks = AsyncMock() await table.on_recovery_completed(set(), set()) table.call_recover_callbacks.assert_called_once_with()
async def test_decode(self, *, topic, message): topic._compile_decode = Mock(name='_compile_decode') topic._compile_decode.return_value = AsyncMock() await topic.decode(message, propagate=True) topic._compile_decode.assert_called_once_with()
async def test_on_start(self, *, runner): runner.case.on_test_start = AsyncMock() await runner.on_start() runner.case.on_test_start.assert_called_once_with(runner)
async def test_skip(self, runner): with pytest.raises(TestSkipped): runner.on_skipped = AsyncMock() await runner.skip('broken') runner.on_skipped.coro.assert_called_once_with(ANY)
async def test_on_isolated_partition_revoked(self, *, actor): actor.cancel = Mock(name='cancel') actor.stop = AsyncMock(name='stop') await actor.on_isolated_partition_revoked(TP('foo', 0)) actor.cancel.assert_called_once_with() actor.stop.assert_called_once_with()
async def test__sample(self, *, case): await case._sample() case.frequency_history.extend(range(100)) case.latency_history.extend(range(100, 200)) case.runtime_history.extend(range(200, 300)) await case._sample() assert case.frequency_avg == median(case.frequency_history) assert case.latency_avg == median(case.latency_history) assert case.runtime_avg == median(case.runtime_history) @pytest.mark.asyncio async def test_maybe_trigger(self, *, case): case.trigger = AsyncMock("trigger") with patch("faust.livecheck.case.uuid"): with patch("faust.livecheck.case.uniform") as uniform: uniform.return_value = 1.0 async with case.maybe_trigger() as test: assert test is None case.trigger.assert_not_called() uniform.return_value = 0.0 async with case.maybe_trigger() as test: assert test is case.trigger.coro.return_value assert case.current_test is test @pytest.mark.asyncio async def test_run(self, *, case):
async def test_on_partitions_revoked__isolated(self, *, isolated_agent): revoked = {TP('foo', 0)} i = isolated_agent.on_isolated_partitions_revoked = AsyncMock(name='i') await isolated_agent.on_partitions_revoked(revoked) i.assert_called_once_with(revoked)
async def test_on_partitions_assigned(self, *, agent): assigned = {TP('foo', 0)} agent.on_shared_partitions_assigned = AsyncMock(name='ospr') await agent.on_partitions_assigned(assigned) agent.on_shared_partitions_assigned.assert_called_once_with(assigned)
async def test_wait_for_subscriptions(self, *, con): with patch('asyncio.Future', AsyncMock()) as Future: con._subscription_done = None await con.wait_for_subscriptions() Future.assert_called_once_with(loop=con.loop)
async def test_on_stop(self, *, agent): agent._stop_supervisor = AsyncMock(name='_stop_supervisor') await agent.on_stop() agent._stop_supervisor.assert_called_once_with()
def thread(self): return Mock( name='thread', on_partitions_assigned=AsyncMock(), on_partitions_revoked=AsyncMock(), )
async def test__commit__CommitFailedError(self, *, cthread, _consumer): cthread._consumer = _consumer exc = _consumer.commit.side_effect = CommitFailedError('xx') cthread.crash = AsyncMock() assert not (await cthread._commit({TP1: 1001})) cthread.crash.assert_called_once_with(exc)
def thread(): return Mock( name='thread', create_topic=AsyncMock(), )
async def test_on_stop(self, *, app): app._http_client = Mock(name='http_client', close=AsyncMock()) await app.on_stop() app._http_client.close.assert_called_once_with() app._http_client = None await app.on_stop()
async def test_on_partitions_assigned__isolated(self, *, isolated_agent): assigned = {TP('foo', 0)} i = isolated_agent.on_isolated_partitions_assigned = AsyncMock() await isolated_agent.on_partitions_assigned(assigned) i.assert_called_once_with(assigned)
async def test_execute(self, *, command): command.run = AsyncMock() command.on_stop = AsyncMock() await command.execute(2, kw=3) command.run.assert_called_once_with(2, kw=3) command.on_stop.assert_called_once_with()
async def test_on_isolated_partitions_assigned(self, *, agent): agent._assign_isolated_partition = AsyncMock(name='aip') await agent.on_isolated_partitions_assigned({TP('foo', 0)}) agent._assign_isolated_partition.assert_called_once_with(TP('foo', 0))
async def test_on_message(self, *, con): cb = con._tp_to_callback[TP1] = AsyncMock(name='callback') message = Mock(name='message', autospec=Message) message.tp = TP1 await con.on_message(message) cb.assert_called_once_with(message)
async def test_start_isolated(self, *, agent): agent._start_for_partitions = AsyncMock( name='agent._start_for_partitions', ) ret = await agent._start_isolated(TP('foo', 0)) agent._start_for_partitions.assert_called_once_with({TP('foo', 0)}) assert ret is agent._start_for_partitions.coro()
async def test_post_report(self, *, case): report = Mock() case.app.post_report = AsyncMock() await case.post_report(report) case.app.post_report.assert_called_once_with(report)
async def test_start_task(self, *, agent): agent._prepare_actor = AsyncMock(name='_prepare_actor') ret = await agent._start_task(index=0) agent._prepare_actor.assert_called_once_with(ANY, agent.beacon) assert ret is agent._prepare_actor.coro()
async def test_execute__pass(self, *, runner, execution): runner.on_pass = AsyncMock() await self._do_execute(runner, execution) runner.on_pass.coro.assert_called_once_with()
async def test__waiting__has_logs(self, bb): assert not bb._logs bb._buffer_log(logging.ERROR, 'msg %r %(foo)s', (1, ), {'foo': 'bar'}) assert bb._logs with patch('asyncio.sleep', AsyncMock()): await bb._waiting()
async def test_init_on_recover(self, *, app): on_recover = AsyncMock(name="on_recover") t = MyTable(app, name="name", on_recover=on_recover) assert on_recover in t._recover_callbacks await t.call_recover_callbacks() on_recover.assert_called_once_with()
async def test__waiting__no_logs(self, bb): assert not bb._logs with patch('asyncio.sleep', AsyncMock()): await bb._waiting()
async def test_wait_until_agents_started(self, *, agents): agents.wait_for_stopped = AsyncMock() await agents.wait_until_agents_started() agents.wait_for_stopped.assert_called_once_with( agents._agents_started, )
async def test__waiting__raises(self, bb): assert not bb._logs bb.logger.warning = Mock(side_effect=KeyError()) with patch('asyncio.sleep', AsyncMock()): with pytest.raises(KeyError): await bb._waiting()
async def test_put(self, *, topic): topic.is_iterator = True topic.queue.put = AsyncMock(name='queue.put') event = Mock(name='event', autospec=Event) await topic.put(event) topic.queue.put.assert_called_once_with(event)
async def test_on_partitions_assigned__when_stopped(self, *, app): app._stopped.set() app._on_rebalance_when_stopped = AsyncMock() await app._on_partitions_assigned(set()) app._on_rebalance_when_stopped.assert_called_once_with()