예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 def test_init_when_aiohttp_is_not_installed(self):
     with _patch(aiohttp_, "aiohttp", None):
         with pytest.raises(NotImplementedError):
             AiohttpClient()
예제 #4
0
 def test_init_with_session_None(self, mocker):
     mocker.spy(AiohttpClient, "_create_session")
     AiohttpClient(kwarg1="value")
     AiohttpClient._create_session.assert_called_with(kwarg1="value")