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()
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
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())
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()
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())
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
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
async def _subscribe_to_streams(self, ws: ClientWebSocketResponse): coros = (ws.send_json(key) for key in self._subscription_keys()) await asyncio.gather(*coros)