Skip to content

Commit

Permalink
Ensure exception types in our tests match websocket-client
Browse files Browse the repository at this point in the history
  • Loading branch information
timwoj committed Dec 6, 2024
1 parent 627f19f commit 4acc42e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_connect_fails_with_refused(self):

def test_connect_fails_with_timeout(self):
controller = zeekclient.controller.Controller()
controller.wsock.mock_connect_exc = websocket.WebSocketTimeoutError(
controller.wsock.mock_connect_exc = websocket.WebSocketTimeoutException(
"connection timed out",
)
# Dial down attempts and waits to make this fast:
Expand All @@ -153,7 +153,7 @@ def test_connect_fails_with_timeout(self):

def test_connect_fails_with_websocket_error(self):
controller = zeekclient.controller.Controller()
controller.wsock.mock_connect_exc = websocket.WebSocketError("uh-oh")
controller.wsock.mock_connect_exc = websocket.WebSocketException("uh-oh")
self.assertFalse(controller.connect())
self.assertLogLines(
"info: connecting to controller 127.0.0.1:2149",
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_connect_fails_with_unknown_error(self):

def test_handshake_fails_with_timeout(self):
controller = zeekclient.controller.Controller()
controller.wsock.mock_recv_exc = websocket.WebSocketTimeoutError(
controller.wsock.mock_recv_exc = websocket.WebSocketTimeoutException(
"connection timed out",
)
self.assertFalse(controller.connect())
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_receive_fails_with_protocol_data_error(self):
def test_receive_fails_with_timeout(self):
controller = zeekclient.controller.Controller()
self.assertTrue(controller.connect())
controller.wsock.mock_recv_exc = websocket.WebSocketTimeoutError(
controller.wsock.mock_recv_exc = websocket.WebSocketTimeoutException(
"connection timed out",
)
res, msg = controller.receive()
Expand Down
6 changes: 4 additions & 2 deletions tests/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import zeekclient


class WebSocketError(Exception):
# This typename needs to match the one in websocket-client or tests will fail.
class WebSocketException(Exception): # noqa: N818
pass


class WebSocketTimeoutError(WebSocketError):
# This typename needs to match the one in websocket-client or tests will fail.
class WebSocketTimeoutException(WebSocketException): # noqa: N818
pass


Expand Down

0 comments on commit 4acc42e

Please sign in to comment.