diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-12-13 21:28:20 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-12-13 21:28:20 -0600 |
| commit | 21d9993eef8c68ad0f6e32ef0c0390202c2a34dd (patch) | |
| tree | 75d128a78e478041ef13c2289be306d46f2da122 /tests/test_client.py | |
| parent | Ignore .venv (diff) | |
| parent | Clarify readme (diff) | |
| download | lirc-21d9993eef8c68ad0f6e32ef0c0390202c2a34dd.zip | |
Merge branch 'dev' for 0.2.0 release
Diffstat (limited to 'tests/test_client.py')
| -rw-r--r-- | tests/test_client.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 0000000..523119b --- /dev/null +++ b/tests/test_client.py @@ -0,0 +1,68 @@ +import pytest + +from lirc import Client, LircdConnection + + +def test_that_custom_connections_can_be_used(mock_socket): + connection = LircdConnection(socket=mock_socket) + client = Client(connection=connection) + + 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()) + + assert "must be an instance of `LircdConnection`" in str(error) + + +def test_that_close_closes_the_socket(mock_client_and_connection): + client, connection = mock_client_and_connection + + client.close() + + connection.socket.close.assert_called() + + +@pytest.mark.parametrize( + "client_command, args, lircd_command", + [ + ("send", {"remote": "REMOTE", "key": "KEY"}, "SEND_ONCE REMOTE KEY 1"), + ( + "send", + {"remote": "REMOTE", "key": "KEY", "repeat_count": 5}, + "SEND_ONCE REMOTE KEY 5", + ), + ("start_repeat", {"remote": "REMOTE", "key": "KEY"}, "SEND_START REMOTE KEY"), + ("stop_repeat", {}, "SEND_STOP "), + ("stop_repeat", {"remote": "REMOTE", "key": "KEY"}, "SEND_STOP REMOTE KEY"), + ("list_remotes", {}, "LIST"), + ("list_remote_keys", {"remote": "REMOTE"}, "LIST REMOTE"), + ("start_logging", {"path": "PATH"}, "SET_INPUTLOG PATH"), + ("stop_logging", {}, "SET_INPUTLOG"), + ("version", {}, "VERSION"), + ("driver_option", {"key": "KEY", "value": "VALUE"}, "DRV_OPTION KEY VALUE"), + ( + "simulate", + {"remote": "REMOTE", "key": "KEY"}, + "SIMULATE 0000000000000000 01 KEY REMOTE", + ), + ( + "simulate", + {"remote": "REMOTE", "key": "KEY", "repeat_count": 4, "keycode": 53}, + "SIMULATE 0000000000000053 04 KEY REMOTE", + ), + ("set_transmitters", {"transmitters": 5}, "SET_TRANSMITTERS 5"), + ("set_transmitters", {"transmitters": [10, 1, 1]}, "SET_TRANSMITTERS 513"), + ], +) +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" + + getattr(client, client_command)(**args) + + connection.socket.sendall.assert_called_with((lircd_command + "\n").encode("utf-8")) |