コード例 #1
0
ファイル: test_client_ws.py プロジェクト: narzeja/aiohttp
def test_receive_runtime_err(loop):
    resp = ClientWebSocketResponse(mock.Mock(), mock.Mock(), mock.Mock(),
                                   mock.Mock(), 10.0, True, True, loop)
    resp._waiting = True

    with pytest.raises(RuntimeError):
        yield from resp.receive()
コード例 #2
0
 async def _ping_pong_loop(self, ws: aiohttp.ClientWebSocketResponse):
     while True:
         ping_send_time = time.time()
         await ws.ping()
         await asyncio.sleep(CONSTANTS.WS_PING_HEARTBEAT)
         if self._last_recv_time < ping_send_time:
             ws._pong_not_received()
             raise asyncio.TimeoutError
コード例 #3
0
    def test_receive_runtime_err(self):
        resp = ClientWebSocketResponse(mock.Mock(), mock.Mock(), mock.Mock(),
                                       mock.Mock(), 10.0, True, True,
                                       self.loop)
        resp._waiting = True

        self.assertRaises(RuntimeError, self.loop.run_until_complete,
                          resp.receive())
コード例 #4
0
ファイル: test_client_ws.py プロジェクト: cr0hn/aiohttp
def test_receive_runtime_err(loop):
    resp = ClientWebSocketResponse(
        mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), 10.0,
        True, True, loop)
    resp._waiting = True

    with pytest.raises(RuntimeError):
        yield from resp.receive()
コード例 #5
0
ファイル: test_client_ws.py プロジェクト: przerull/aiohttp
    def test_receive_runtime_err(self):
        resp = ClientWebSocketResponse(
            mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), 10.0,
            True, True, self.loop)
        resp._waiting = True

        self.assertRaises(
            RuntimeError, self.loop.run_until_complete, resp.receive())
コード例 #6
0
ファイル: common.py プロジェクト: natekspencer/pylitterbot
async def get_account(logged_in: bool = False,
                      load_robots: bool = False) -> Account:
    """Get an account that has the underlying API patched."""
    with patch(
            "pylitterbot.session.ClientSession.ws_connect",
            return_value=ClientWebSocketResponse(Mock(), Mock(), Mock(),
                                                 Mock(), Mock(), Mock(),
                                                 Mock(), Mock()),
    ):
        account = Account()
        if logged_in:
            await account.connect(username=USERNAME,
                                  password=PASSWORD,
                                  load_robots=load_robots)
        return account
コード例 #7
0
 async def _inner_messages(
         self, ws: aiohttp.ClientWebSocketResponse) -> AsyncIterable[str]:
     try:
         while True:
             msg = await asyncio.wait_for(ws.receive(),
                                          timeout=self.MESSAGE_TIMEOUT)
             if msg.type == aiohttp.WSMsgType.CLOSED:
                 raise ConnectionError
             yield json.loads(msg.data)
     except asyncio.TimeoutError:
         return
     except ConnectionClosed:
         return
     except ConnectionError:
         return
コード例 #8
0
 async def _subscribe_to_streams(self, ws: ClientWebSocketResponse):
     coros = (ws.send_json(key) for key in self._subscription_keys())
     await asyncio.gather(*coros)