summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-12-26 13:06:50 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-12-26 13:06:50 -0600
commitc7e2f571d7984d44baa42aeabef482e2bf22ad3e (patch)
tree14a85df4afb6019a9c9683415b10276721ecc9d5 /tests
parentAdd pypi OS classifiers (diff)
downloadlirc-c7e2f571d7984d44baa42aeabef482e2bf22ad3e.zip
Raise an unsupported os error in default connection
Diffstat (limited to 'tests')
-rw-r--r--tests/test_default_connection.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_default_connection.py b/tests/test_default_connection.py
new file mode 100644
index 0000000..bc4fa09
--- /dev/null
+++ b/tests/test_default_connection.py
@@ -0,0 +1,62 @@
+from unittest.mock import patch
+import socket
+
+from lirc.connection.default_connection import DefaultConnection
+from lirc.exceptions import UnsupportedOperatingSystemError
+
+import pytest
+
+
+@pytest.mark.parametrize("os, expected_socket, expected_address", [
+ (
+ "Windows",
+ socket.socket(socket.AF_INET, socket.SOCK_STREAM),
+ ("localhost", 8765)
+ ),
+ (
+ "Linux",
+ socket.socket(socket.AF_UNIX, socket.SOCK_STREAM),
+ "/var/run/lirc/lircd"
+ ),
+ (
+ "Darwin",
+ socket.socket(socket.AF_UNIX, socket.SOCK_STREAM),
+ "/opt/run/var/run/lirc/lircd"
+ )
+])
+@patch("platform.system")
+def test_default_connection_has_correct_os_specific_socket_and_address(
+ patched_system, os, expected_socket, expected_address
+):
+ """
+ lirc.connection.default_connection.DefaultConnection
+
+ Ensure that the DefaultConnection retrieves the correct socket
+ and address for each support operating system.
+ """
+ patched_system.return_value = os
+
+ default_conn = DefaultConnection() # SUT
+
+ assert default_conn.socket.family == expected_socket.family
+ assert default_conn.socket.type == expected_socket.type
+ assert default_conn.address == expected_address
+
+
+@pytest.mark.parametrize("prop", ["socket", "address"])
+@patch("platform.system")
+def test_default_connection_raises_error_on_unsupported_os(patched_system, prop):
+ """
+ lirc.connection.default_connection.DefaultConnection.socket
+ lirc.connection.default_connection.DefaultConnection.address
+
+ Ensure that trying to retrieve the socket or address on an unsupported
+ OS raises an UnsupportedOperatingSystemError.
+ """
+ patched_system.return_value = "FreeBSD"
+
+ with pytest.raises(UnsupportedOperatingSystemError) as error:
+ default_conn = DefaultConnection()
+ getattr(default_conn, prop) # SUT
+
+ assert "FreeBSD is not supported" in str(error)