diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2021-11-28 17:58:09 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2021-11-28 17:58:09 -0600 |
| commit | c1eaaca5a370b384b8b6fea4b385bbe676021bdc (patch) | |
| tree | 2f9ce3a67fe3f12fb0112286eda7e623e509dcec /tests | |
| parent | Move maintenance section (diff) | |
| download | lirc-c1eaaca5a370b384b8b6fea4b385bbe676021bdc.zip | |
Use single underscore internal attribute prefixes
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_client.py | 22 | ||||
| -rw-r--r-- | tests/test_lircd_connection.py | 14 | ||||
| -rw-r--r-- | tests/test_reply_packet_parser.py | 2 |
3 files changed, 15 insertions, 23 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index e7b80d5..b930f5d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -17,7 +17,7 @@ def test_that_custom_connections_can_be_used(mock_socket): client = Client(connection=connection) # SUT - assert client._Client__connection == connection + assert client._connection == connection def test_that_custom_connection_that_is_not_an_abstract_connection_raises_error( @@ -50,7 +50,7 @@ def test_that_no_connection_passed_in_creates_default_one(): with mock.patch("lirc.client.LircdConnection", MockedLircdConnection): c = Client() - assert isinstance(c._Client__connection, MockedLircdConnection) + assert isinstance(c._connection, MockedLircdConnection) def test_that_close_closes_the_socket(mock_client_and_connection): @@ -63,7 +63,7 @@ def test_that_close_closes_the_socket(mock_client_and_connection): client.close() # SUT - connection._LircdConnection__socket.close.assert_called() + connection._socket.close.assert_called() @pytest.mark.parametrize( @@ -124,13 +124,11 @@ def test_that_client_commands_send_the_correct_command( lircd_command: The expected corresponding command sent to lircd. """ client, connection = mock_client_and_connection - connection._LircdConnection__socket.recv.return_value = ( - b"BEGIN\nCOMMAND\nSUCCESS\nEND\n" - ) + connection._socket.recv.return_value = b"BEGIN\nCOMMAND\nSUCCESS\nEND\n" getattr(client, client_command)(**args) # SUT - connection._LircdConnection__socket.sendall.assert_called_with( + connection._socket.sendall.assert_called_with( (lircd_command + "\n").encode("utf-8") ) @@ -143,9 +141,7 @@ def test_unsuccessful_command_raises_custom_exception(mock_client_and_connection LircdCommandFailureError. """ client, connection = mock_client_and_connection - connection._LircdConnection__socket.recv.return_value = ( - b"BEGIN\nCOMMAND\nERROR\nEND\n" - ) + connection._socket.recv.return_value = b"BEGIN\nCOMMAND\nERROR\nEND\n" with pytest.raises(LircdCommandFailureError) as error: client.send_once("remote", "key") @@ -163,13 +159,11 @@ def test_last_send_start_remote_and_key_is_used(mock_client_and_connection): had passed in as args if no args are provided to send_stop. """ client, connection = mock_client_and_connection - connection._LircdConnection__socket.recv.return_value = ( - b"BEGIN\nCOMMAND\nSUCCESS\nEND\n" - ) + connection._socket.recv.return_value = b"BEGIN\nCOMMAND\nSUCCESS\nEND\n" client.send_start("remote", "key") client.send_stop() # SUT - connection._LircdConnection__socket.sendall.assert_called_with( + connection._socket.sendall.assert_called_with( "SEND_STOP remote key\n".encode("utf-8") ) diff --git a/tests/test_lircd_connection.py b/tests/test_lircd_connection.py index 7221215..f8693b4 100644 --- a/tests/test_lircd_connection.py +++ b/tests/test_lircd_connection.py @@ -16,7 +16,7 @@ def test_close_closes_the_socket_connection(mock_connection): """ mock_connection.close() # SUT - mock_connection._LircdConnection__socket.close.assert_called() + mock_connection._socket.close.assert_called() def test_that_retrieving_the_address_property_retrieves_the_address(mock_socket): @@ -97,7 +97,7 @@ def test_that_send_adds_a_newline_to_the_end(mock_connection, test_command): """ mock_connection.send(test_command) # SUT - mock_connection._LircdConnection__socket.sendall.assert_called_with( + mock_connection._socket.sendall.assert_called_with( f"{test_command}\n".encode("utf-8") ) @@ -113,9 +113,7 @@ def test_that_send_does_not_add_too_many_newlines(mock_connection): mock_connection.send(command) # SUT - mock_connection._LircdConnection__socket.sendall.assert_called_with( - f"{command}".encode("utf-8") - ) + mock_connection._socket.sendall.assert_called_with(f"{command}".encode("utf-8")) @pytest.mark.parametrize("test_command", [5, False, 0.1, b"hello"]) @@ -147,7 +145,7 @@ def test_that_readline_uses_buffer_if_items_are_present_in_it( Ensure that readline uses the buffer if there are items in it. """ - mock_connection._LircdConnection__buffer.extend(buffer_payload) + mock_connection._buffer.extend(buffer_payload) line = mock_connection.readline() # SUT @@ -171,12 +169,12 @@ def test_that_readline_retrieves_data_from_socket_and_adds_to_buffer( Ensure that when we call readline(), it adds to the buffer if we retrieved more than a single line. """ - mock_connection._LircdConnection__socket.recv.return_value = socket_payload + mock_connection._socket.recv.return_value = socket_payload line = mock_connection.readline() # SUT assert line == expected_return - assert mock_connection._LircdConnection__buffer == expected_buffer + assert mock_connection._buffer == expected_buffer @patch("socket.socket.recv") diff --git a/tests/test_reply_packet_parser.py b/tests/test_reply_packet_parser.py index 304bb74..82af1a5 100644 --- a/tests/test_reply_packet_parser.py +++ b/tests/test_reply_packet_parser.py @@ -203,4 +203,4 @@ def test_command_state_raises_exception_on_empty_line(line): parser = ReplyPacketParser() with pytest.raises(LircdInvalidReplyPacketError): - parser._ReplyPacketParser__command(line) + parser._command(line) |