summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_client.py16
-rw-r--r--tests/test_lircd_connection.py14
2 files changed, 21 insertions, 9 deletions
diff --git a/tests/test_client.py b/tests/test_client.py
index 523119b..e8096de 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -4,6 +4,12 @@ from lirc import Client, LircdConnection
def test_that_custom_connections_can_be_used(mock_socket):
+ """
+ lirc.Client.__init__
+
+ Ensure we can pass in custom connections using the
+ keyword argument instead of relying on the default.
+ """
connection = LircdConnection(socket=mock_socket)
client = Client(connection=connection)
@@ -22,7 +28,7 @@ def test_that_close_closes_the_socket(mock_client_and_connection):
client.close()
- connection.socket.close.assert_called()
+ connection._LircdConnection__socket.close.assert_called()
@pytest.mark.parametrize(
@@ -61,8 +67,12 @@ def test_that_client_commands_send_the_correct_command(
mock_client_and_connection, client_command, args, lircd_command
):
client, connection = mock_client_and_connection
- connection.socket.recv.return_value = b"BEGIN\nCOMMAND\nSUCCESS\nEND\n"
+ connection._LircdConnection__socket.recv.return_value = (
+ b"BEGIN\nCOMMAND\nSUCCESS\nEND\n"
+ )
getattr(client, client_command)(**args)
- connection.socket.sendall.assert_called_with((lircd_command + "\n").encode("utf-8"))
+ connection._LircdConnection__socket.sendall.assert_called_with(
+ (lircd_command + "\n").encode("utf-8")
+ )
diff --git a/tests/test_lircd_connection.py b/tests/test_lircd_connection.py
index 6c8679c..827ff90 100644
--- a/tests/test_lircd_connection.py
+++ b/tests/test_lircd_connection.py
@@ -25,14 +25,14 @@ def test_socket_and_address_have_correct_cross_platform_values(
expected_socket = connection._LircdConnection__socket
expected_address = connection._LircdConnection__address
- assert connection.socket.family == expected_socket.family
- assert connection.socket.type == expected_socket.type
+ assert connection._LircdConnection__socket.family == expected_socket.family
+ assert connection._LircdConnection__socket.type == expected_socket.type
assert connection.address == expected_address
def test_close_closes_the_socket_connection(mock_connection):
mock_connection.close()
- mock_connection.socket.close.assert_called()
+ mock_connection._LircdConnection__socket.close.assert_called()
def test_that_connection_error_is_raised_on_invalid_address():
@@ -50,7 +50,7 @@ def test_that_send_adds_a_newline_to_the_end_if_not_present(
mock_connection, test_command
):
mock_connection.send(test_command)
- mock_connection.socket.sendall.assert_called_with(
+ mock_connection._LircdConnection__socket.sendall.assert_called_with(
f"{test_command}\n".encode("utf-8")
)
@@ -70,7 +70,9 @@ def test_that_send_sends_the_command_unaltered_to_the_socket_if_in_correct_forma
mock_connection, test_command
):
mock_connection.send(test_command)
- mock_connection.socket.sendall.assert_called_with(test_command.encode("utf-8"))
+ mock_connection._LircdConnection__socket.sendall.assert_called_with(
+ test_command.encode("utf-8")
+ )
@pytest.mark.parametrize(
@@ -95,7 +97,7 @@ def test_that_readline_uses_buffer_if_items_are_present_in_it(
def test_that_readline_retrieves_data_from_socket_and_adds_to_buffer(
mock_connection, socket_payload, expected_return, expected_buffer
):
- mock_connection.socket.recv.return_value = socket_payload
+ mock_connection._LircdConnection__socket.recv.return_value = socket_payload
line = mock_connection.readline()