async def test_dispatch(self, method, *, view): request = Mock(name='request', autospec=Request) request.method = method handler = AsyncMock(name=method) view.methods[method.lower()] = handler assert await view(request) is handler.coro() handler.assert_called_once_with(request)
async def test_execute__error_callbacks(self, exc, raises, callback, *, runner, execution): if raises is None: raises = type(exc) cb = AsyncMock() setattr(runner, callback, cb) runner.on_pass = AsyncMock() with pytest.raises(raises): await self._do_execute( runner, execution, active=True, expired=False, side_effect=exc, ) cb.assert_called_once_with(exc) runner.on_pass.assert_not_called()
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__check_frequency__last(self, *, case, frozen_monotonic): frozen_monotonic.return_value = 600.0 case.warn_stalled_after = 10.0 case.on_suite_fail = AsyncMock() with patch("mode.services.Timer") as ti: async def on_itertimer(*args, **kwargs): case.last_test_received = 10.0 for val in [0.1, 0.2, 0.3, 0.4, 0.5]: yield val ti.side_effect = on_itertimer case.sleep = AsyncMock() await case._check_frequency(case) case.on_suite_fail.assert_called_once_with(ANY, State.STALL) @pytest.mark.asyncio async def test__check_frequency__should_stop1(self, *, case): with patch("mode.services.Timer") as ti: async def on_itertimer(*args, **kwargs): case._stopped.set() yield 0.1 yield 0.2 yield 0.3 yield 0.4 yield 0.5 ti.side_effect = on_itertimer