Skip to content

Commit

Permalink
Remove useless try/except
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Oct 29, 2024
1 parent b5195c9 commit c52d960
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 48 deletions.
35 changes: 16 additions & 19 deletions go2rtc_client/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,22 @@ async def _receive_messages(self) -> None:
assert self._client

while self.connected:
try:
msg = await self._client.receive()
match msg.type:
case (
WSMsgType.CLOSE
| WSMsgType.CLOSED
| WSMsgType.CLOSING
| WSMsgType.PING
| WSMsgType.PONG
):
break
case WSMsgType.ERROR:
_LOGGER.error("Error received: %s", msg.data)
case WSMsgType.TEXT:
self._process_text_message(msg.data)
case _:
_LOGGER.warning("Received unknown message: %s", msg)
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected error while receiving message")
msg = await self._client.receive()
match msg.type:
case (
WSMsgType.CLOSE
| WSMsgType.CLOSED
| WSMsgType.CLOSING
| WSMsgType.PING
| WSMsgType.PONG
):
break
case WSMsgType.ERROR:
_LOGGER.error("Error received: %s", msg.data)
case WSMsgType.TEXT:
self._process_text_message(msg.data)
case _:
_LOGGER.warning("Received unknown message: %s", msg)

def subscribe(
self, callback: Callable[[ReceiveMessages], None]
Expand Down
29 changes: 0 additions & 29 deletions tests/ws/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,32 +363,3 @@ async def receive() -> WSMessage:
await asyncio.sleep(0.1)

assert caplog.record_tuples == [record]


async def test_receive_raised(
caplog: pytest.LogCaptureFixture,
ws_client: Go2RtcWsClient,
) -> None:
"""Test getting message raised an exception."""
client = AsyncMock()
client.return_value.closed = False
ws_client._session.ws_connect = client # type: ignore[method-assign] # pylint: disable=protected-access

async def receive() -> WSMessage:
nonlocal client
client.return_value.closed = True

raise ValueError

client.return_value.receive.side_effect = receive

await ws_client.connect()
await asyncio.sleep(0.1)

assert caplog.record_tuples == [
(
"go2rtc_client.ws.client",
logging.ERROR,
"Unexpected error while receiving message",
)
]

0 comments on commit c52d960

Please sign in to comment.