diff --git a/monkey/common/utils/file_utils.py b/monkey/common/utils/file_utils.py index 225fb8732..6110cd020 100644 --- a/monkey/common/utils/file_utils.py +++ b/monkey/common/utils/file_utils.py @@ -1,5 +1,11 @@ import os +class InvalidPath(Exception): + pass + + def expand_path(path: str) -> str: + if not path: + raise InvalidPath("Empty path provided") return os.path.expandvars(os.path.expanduser(path)) diff --git a/monkey/tests/unit_tests/common/utils/test_common_file_utils.py b/monkey/tests/unit_tests/common/utils/test_common_file_utils.py index 226a403b8..b67341cfe 100644 --- a/monkey/tests/unit_tests/common/utils/test_common_file_utils.py +++ b/monkey/tests/unit_tests/common/utils/test_common_file_utils.py @@ -1,6 +1,8 @@ import os -from common.utils.file_utils import expand_path +import pytest + +from common.utils.file_utils import InvalidPath, expand_path def test_expand_user(patched_home_env): @@ -15,3 +17,8 @@ def test_expand_vars(patched_home_env): expected_path = os.path.join(patched_home_env, "test") assert expand_path(input_path) == expected_path + + +def test_expand_path__empty_path_provided(): + with pytest.raises(InvalidPath): + expand_path("")