From 988a87fc8c1e1c197bd87ef124e85aaa6e47a6aa Mon Sep 17 00:00:00 2001 From: Koen van Eijk Date: Sun, 9 Jun 2024 14:58:56 +0200 Subject: [PATCH] =?UTF-8?q?Added=20first=20unit=20tests=20with=20pytest=20?= =?UTF-8?q?=F0=9F=A7=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_config.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_config.py diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..6d4bafe --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,30 @@ +import pytest +from unittest import mock +from openrecall.config import get_appdata_folder + +def test_get_appdata_folder_windows(tmp_path): + with mock.patch('sys.platform', 'win32'): + with mock.patch.dict('os.environ', {'APPDATA': str(tmp_path)}): + expected_path = tmp_path / 'openrecall' + assert get_appdata_folder() == str(expected_path) + assert expected_path.exists() + +def test_get_appdata_folder_windows_no_appdata(): + with mock.patch('sys.platform', 'win32'): + with mock.patch.dict('os.environ', {}, clear=True): + with pytest.raises(EnvironmentError, match="APPDATA environment variable is not set."): + get_appdata_folder() + +def test_get_appdata_folder_darwin(tmp_path): + with mock.patch('sys.platform', 'darwin'): + with mock.patch('os.path.expanduser', return_value=str(tmp_path)): + expected_path = tmp_path / 'Library' / 'Application Support' / 'openrecall' + assert get_appdata_folder() == str(expected_path) + assert expected_path.exists() + +def test_get_appdata_folder_linux(tmp_path): + with mock.patch('sys.platform', 'linux'): + with mock.patch('os.path.expanduser', return_value=str(tmp_path)): + expected_path = tmp_path / '.local' / 'share' / 'openrecall' + assert get_appdata_folder() == str(expected_path) + assert expected_path.exists()