def __init__(self, conf=ipv6_conf):
     super().__init__()
     self.conf = conf
     self.pass_enter = asyncio.Event()
     self.pass_enter.set()
     self.__aenter__ = mock_coroutine(self)
     self.__aexit__ = mock_coroutine(None)
    async def test_notifies_subscriber_on_subcription(self):
        dummy = mock.MagicMock()
        dummy.__aenter__ = mock_coroutine(self)
        dummy.__aexit__ = mock_coroutine(None)
        dummy.fn.return_value = 42
        observer = mock.MagicMock()

        async with Subscribable(dummy) as subscribable:
            await subscribable.subscribe(observer, dummy.fn, 1, 2, three=3)
        dummy.fn.assert_called_once_with(1, 2, three=3)
        observer.on_next.assert_called_once_with(42)
 async def test_can_send_queries_to_kernel(self, ws_connect_mock,
                                           connection_mock):
     connection_mock.recv = mock_coroutine('data')
     async with ConnectedKernel(KernelMock()) as connected_kernel:
         result = await connected_kernel.query('{ model { id } }',
                                               variables={'var': 'value'})
         connection_mock.send.assert_called_once_with(
             json.dumps({
                 'query': '{ model { id } }',
                 'variables': {
                     'var': 'value'
                 }
             }))
     assert result == 'data'
def connection_mock():
    m = mock.MagicMock()
    m.__aenter__ = mock_coroutine(m)
    m.__aexit__ = mock_coroutine(None)
    m.send = mock_coroutine(None)
    return m