Skip to content

Commit

Permalink
Fix tests and typing.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed May 16, 2024
1 parent ba40751 commit a88271a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions tests/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def socket() -> FakeSocket:
return FakeSocket(1)


@pytest.fixture
def sub_socket() -> FakeSocket:
return FakeSocket(2)


def test_socket_unbind(socket: FakeSocket):
socket.bind("abc")
socket.unbind()
Expand All @@ -50,22 +55,21 @@ def test_socket_disconnect(socket: FakeSocket):


@pytest.mark.parametrize("topic", ("string", b"bytes"))
def test_socket_subscribe(socket: FakeSocket, topic):
socket.socket_type = 2
socket.subscribe(topic)
assert isinstance(socket._subscriptions[-1], bytes)
def test_socket_subscribe(sub_socket: FakeSocket, topic):
sub_socket.subscribe(topic)
assert isinstance(sub_socket._subscriptions[-1], bytes)


def test_subscribe_fails_for_not_SUB(socket: FakeSocket):
with pytest.raises(ValueError):
socket.subscribe("abc")


@pytest.mark.parametrize("topic", ("string", b"bytes"))
def test_socket_unsubscribe(socket: FakeSocket, topic):
socket.socket_type = 2
socket.unsubscribe(topic)
assert isinstance(socket._subscriptions[-1], bytes)
@pytest.mark.parametrize("topic", ("topic", b"topic"))
def test_socket_unsubscribe(sub_socket: FakeSocket, topic):
sub_socket._subscriptions.append(b"topic")
sub_socket.unsubscribe(topic)
assert b"topic" not in sub_socket._subscriptions


def test_unsubscribe_fails_for_not_SUB(socket: FakeSocket):
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_extended_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def test_handle_pickled_message(self, handler_hfl: ExtendedMessageHandler):
handler_hfl.handle_full_legacy_subscription_message(
DataMessage("topic", data=pickle.dumps(data), message_type=234)
)
handler_hfl.handle_subscription_data.assert_called_once_with({"topic": data})
handler_hfl.handle_subscription_data.assert_called_once_with({"topic": data}) # type: ignore

def test_handle_json_message(self, handler_hfl: ExtendedMessageHandler):
data = ["some", "data", 5]
handler_hfl.handle_full_legacy_subscription_message(
DataMessage("topic", data=json.dumps(data), message_type=235)
)
handler_hfl.handle_subscription_data.assert_called_once_with({"topic": data})
handler_hfl.handle_subscription_data.assert_called_once_with({"topic": data}) # type: ignore

def test_handle_unknown_message_type(self, handler_hfl: ExtendedMessageHandler):
with pytest.raises(ValueError):
Expand Down

0 comments on commit a88271a

Please sign in to comment.