def test_wrap_callback(self, mocker): # Setup c = AiohttpClient() mocker.spy(c, "_sync_callback_adapter") # Run: with callback that is not a coroutine def callback(*_): pass c.wrap_callback(callback) # Verify: Should wrap it c._sync_callback_adapter.assert_called_with(callback) # Run: with coroutine callback async def awaitable_callback(): pass assert c.wrap_callback(awaitable_callback) is awaitable_callback
def test_wrap_callback(self, mocker): import asyncio # Setup c = AiohttpClient() mocker.spy(c, "_sync_callback_adapter") # Run: with callback that is not a coroutine def callback(*_): pass c.wrap_callback(callback) # Verify: Should wrap it c._sync_callback_adapter.assert_called_with(callback) # Run: with coroutine callback coroutine_callback = asyncio.coroutine(callback) assert c.wrap_callback(coroutine_callback) is coroutine_callback
def test_init_when_aiohttp_is_not_installed(self): with _patch(aiohttp_, "aiohttp", None): with pytest.raises(NotImplementedError): AiohttpClient()
def test_init_with_session_None(self, mocker): mocker.spy(AiohttpClient, "_create_session") AiohttpClient(kwarg1="value") AiohttpClient._create_session.assert_called_with(kwarg1="value")