From c7e2f571d7984d44baa42aeabef482e2bf22ad3e Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 26 Dec 2020 13:06:50 -0600 Subject: Raise an unsupported os error in default connection --- tests/test_default_connection.py | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/test_default_connection.py (limited to 'tests/test_default_connection.py') 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) -- cgit v1.2.3