summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_lirc.py35
1 files changed, 25 insertions, 10 deletions
diff --git a/tests/test_lirc.py b/tests/test_lirc.py
index 655eb31..348e785 100644
--- a/tests/test_lirc.py
+++ b/tests/test_lirc.py
@@ -2,12 +2,27 @@ import os
import pytest
-from lirc import Lirc, LircResponse, LircSocketTimeoutError
+from lirc import (
+ InvalidReplyPacketFormatError,
+ Lirc,
+ LircResponse,
+ LircSocketTimeoutError,
+)
+
+
+def test_default_lirc_init(mock_socket):
+ TIMEOUT = 5
+ mock_lirc = Lirc(socket=mock_socket, socket_timeout=TIMEOUT)
+
+ mock_socket.connect.assert_called_with(mock_lirc.DEFAULT_SOCKET_PATH)
+ mock_socket.settimeout.assert_called_with(TIMEOUT)
+
+def test_lirc_custom_path(mock_socket):
+ CUSTOM_PATH = "CUSTOM"
+ Lirc(socket=mock_socket, socket_path=CUSTOM_PATH)
-def test_default_lirc_init(mock_lirc):
- mock_lirc.socket.connect.assert_called_with(mock_lirc.DEFAULT_SOCKET_PATH)
- mock_lirc.socket.settimeout.assert_called_with(mock_lirc.socket_timeout)
+ mock_socket.connect.assert_called_with(CUSTOM_PATH)
def test_custom_path_lirc_init(mock_socket):
@@ -20,9 +35,9 @@ def test_custom_path_lirc_init(mock_socket):
"reply_packet", [b"BEGIN\nSEND_ONCE remote key\nSUCCESS\nEND\n"]
)
def test_read_reply_packet(mock_lirc, reply_packet):
- mock_lirc.socket.recv.return_value = reply_packet
+ mock_lirc._Lirc__socket.recv.return_value = reply_packet
retrieved_packet = mock_lirc._Lirc__read_reply_packet()
- mock_lirc.socket.recv.assert_called_with(256)
+ mock_lirc._Lirc__socket.recv.assert_called_with(256)
assert reply_packet == retrieved_packet.encode(mock_lirc.ENCODING)
@@ -32,7 +47,7 @@ def test_read_reply_packet(mock_lirc, reply_packet):
@pytest.mark.parametrize("reply_packet", [b"INVALID PACKET"])
def test_read_reply_packet_socket_timeout(mock_lirc, reply_packet):
with pytest.raises(LircSocketTimeoutError):
- mock_lirc.socket.recv.return_value = reply_packet
+ mock_lirc._Lirc__socket.recv.return_value = reply_packet
mock_lirc._Lirc__read_reply_packet()
@@ -52,7 +67,7 @@ def test_read_reply_packet_socket_timeout(mock_lirc, reply_packet):
"SEND_ONCE remote key",
False,
[],
- ValueError,
+ InvalidReplyPacketFormatError,
),
(
"BEGIN\nSEND_ONCE remote key\nERROR\nDATA\n1\nunknown remote: remote\n",
@@ -95,9 +110,9 @@ def test_send_once(mock_lirc, reply_packet, repeat_count):
COMMAND = f"SEND_ONCE {REMOTE} {KEY}"
SUCCESS = True if "SUCCESS" in reply_packet.decode(mock_lirc.ENCODING) else False
- mock_lirc.socket.recv.return_value = reply_packet
+ mock_lirc._Lirc__socket.recv.return_value = reply_packet
response = mock_lirc.send_once(KEY, REMOTE, repeat_count=repeat_count)
- mock_lirc.socket.sendall.assert_called_with(
+ mock_lirc._Lirc__socket.sendall.assert_called_with(
(COMMAND + "\n").encode(mock_lirc.ENCODING)
)