diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_client.py | 44 | ||||
| -rw-r--r-- | tests/test_reply_packet_parser.py | 66 |
2 files changed, 39 insertions, 71 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index e8096de..b4c49a0 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -11,22 +11,34 @@ def test_that_custom_connections_can_be_used(mock_socket): keyword argument instead of relying on the default. """ connection = LircdConnection(socket=mock_socket) - client = Client(connection=connection) + + client = Client(connection=connection) # SUT assert client._Client__connection == connection def test_that_custom_connection_that_is_not_a_lircd_connection_raises_error(): - with pytest.raises(ValueError) as error: - Client(connection=Client()) + """ + lirc.Client.__init__ + + Ensure that passing in something that is not an instance of + LircdConnection raise a TypeError. + """ + with pytest.raises(TypeError) as error: + Client(connection=Client()) # SUT assert "must be an instance of `LircdConnection`" in str(error) def test_that_close_closes_the_socket(mock_client_and_connection): + """ + lirc.Client.close + + Ensure that a call to close() calls the socket's close(). + """ client, connection = mock_client_and_connection - client.close() + client.close() # SUT connection._LircdConnection__socket.close.assert_called() @@ -66,12 +78,34 @@ def test_that_close_closes_the_socket(mock_client_and_connection): def test_that_client_commands_send_the_correct_command( mock_client_and_connection, client_command, args, lircd_command ): + """ + lirc.Client.send + lirc.Client.start_repeat + lirc.Client.stop_repeat + lirc.Client.list_remotes + lirc.Client.list_remote_keys + lirc.Client.start_logging + lirc.Client.stop_logging + lirc.Client.version + lirc.Client.driver_option + lirc.Client.simulate + lirc.Client.set_transmitters + + Ensure that all the commands that are wrappers around the lircd + commands send the correct lircd command when given various arguments. + + Args: + mock_client_and_connection: Mocked client and connection to lircd. + client_command: The commond on the Client to call. + args: The args to call the client command with. + 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" ) - getattr(client, client_command)(**args) + getattr(client, client_command)(**args) # SUT connection._LircdConnection__socket.sendall.assert_called_with( (lircd_command + "\n").encode("utf-8") diff --git a/tests/test_reply_packet_parser.py b/tests/test_reply_packet_parser.py deleted file mode 100644 index 86ae311..0000000 --- a/tests/test_reply_packet_parser.py +++ /dev/null @@ -1,66 +0,0 @@ -# import pytest -# -# from lirc import ( -# LircdCommandFailureError, -# LircdInvalidReplyPacketError, -# LircdSocketTimeoutError, -# ) -# from lirc.reply_packet_parser import ReplyPacketParser -# from lirc.utils import ENCODING -# -# -# @pytest.mark.parametrize( -# "reply_packet", [b"BEGIN\nSEND_ONCE remote key\nSUCCESS\nEND\n"] -# ) -# def test_read_reply_packet(mock_socket, reply_packet): -# mock_socket.recv.return_value = reply_packet -# parser = ReplyPacketParser(mock_socket) -# parser.read() -# -# retrieved_packet = parser.feed() -# -# mock_socket.recv.assert_called_with(ReplyPacketParser.BUFFER_LENGTH) -# assert reply_packet == retrieved_packet.encode(ENCODING) -# -# -# @pytest.mark.skip(reason="Not working") -# @pytest.mark.parametrize("reply_packet", [b"INVALID PACKET"]) -# def test_read_reply_packet_socket_timeout(mock_lirc, reply_packet): -# with pytest.raises(LircdSocketTimeoutError): -# mock_lirc.socket.recv.return_value = reply_packet -# ReplyPacketParser.read(mock_lirc.socket) -# -# -# @pytest.mark.parametrize( -# "reply_packet, data, exception", -# [ -# (b"BEGIN\nSEND_ONCE remote key\nSUCCESS\nEND\n", [], None,), -# # ("INVALID PACKET", [], LircdInvalidReplyPacketError), -# ( -# b"BEGIN\nSEND_ONCE remote key\nERROR\nINVALID\n", -# [], -# LircdInvalidReplyPacketError, -# ), -# ( -# b"BEGIN\nSEND_ONCE remote key\nERROR\nDATA\n1\nunknown remote: remote\n", -# ["unknown remote: remote"], -# LircdCommandFailureError, -# ), -# ( -# b"BEGIN\nSEND_ONCE remote key\nSUCCESS\nDATA\n3\nraa\nblah\nbhal\n", -# ["raa", "blah", "bhal"], -# None, -# ), -# ], -# ) -# def test_parse_reply_packet(mock_socket, reply_packet, data, exception): -# mock_socket.recv.return_value = reply_packet -# parser = ReplyPacketParser(mock_socket) -# -# if exception: -# with pytest.raises(exception): -# parser.read() -# parser.feed() -# else: -# parser.read() -# assert parser.feed() == data |