From b97f739d35697cd3944d2d5b5f91170b3f71104f Mon Sep 17 00:00:00 2001 From: Simi Date: Sun, 12 Feb 2023 21:50:07 +1100 Subject: [PATCH 1/2] Add flag to check for FreeBSD as OS add warning in case no supported OS was foud --- plex_auto_languages/utils/configuration.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plex_auto_languages/utils/configuration.py b/plex_auto_languages/utils/configuration.py index aee85a9..51c3cb2 100644 --- a/plex_auto_languages/utils/configuration.py +++ b/plex_auto_languages/utils/configuration.py @@ -5,6 +5,7 @@ import logging from collections.abc import Mapping import yaml +import warnings from plex_auto_languages.utils.logger import get_logger from plex_auto_languages.exceptions import InvalidConfiguration @@ -51,6 +52,9 @@ def get_data_directory(app_name: str): return str(home / f".local/share/{app_name}") if sys.platform == "darwin": return str(home / f"Library/Application Support/{app_name}") + if os.uname()[0] == "FreeBSD": + return str(home / f".local/share/{app_name}") + warnings.warn("Warning: Unsupported Operating System!") return None From b0f420e8c024e8a057b427da73822b0041771aed Mon Sep 17 00:00:00 2001 From: RemiRigal Date: Mon, 20 Feb 2023 10:58:53 +0100 Subject: [PATCH 2/2] Add tests for FreeBSD support --- tests/test_configuration.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 985b607..c7a26c0 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -5,6 +5,7 @@ import pytest import logging import tempfile +import warnings from unittest.mock import patch from plex_auto_languages.exceptions import InvalidConfiguration @@ -29,8 +30,14 @@ def test_get_data_directory(): sys.platform = "darwin" assert get_data_directory("test") == os.path.expanduser("~/Library/Application Support/test") + sys.platform = "freebsdxx" + with patch("os.uname", return_value=["FreeBSD"]): + assert get_data_directory("test") == os.path.expanduser("~/.local/share/test") + sys.platform = "unknown_platform" - assert get_data_directory("test") is None + with patch.object(warnings, "warn") as mocked_warn: + assert get_data_directory("test") is None + mocked_warn.assert_called_once() with patch("plex_auto_languages.utils.configuration.is_docker", return_value=True): sys.platform = "win32" @@ -42,6 +49,10 @@ def test_get_data_directory(): sys.platform = "darwin" assert get_data_directory("test") == "/config" + sys.platform = "freebsdxx" + with patch("os.uname", return_value=["FreeBSD"]): + assert get_data_directory("test") == "/config" + sys.platform = "unknown_platform" assert get_data_directory("test") == "/config" sys.platform = initial_platform