Change the expand_path method in file_utils.py to throw an error if an empty file path is provided instead of expanding it to current working directory

This commit is contained in:
VakarisZ 2021-07-07 11:23:10 +03:00
parent 6282cd0de3
commit bd60bef35f
2 changed files with 14 additions and 1 deletions

View File

@ -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))

View File

@ -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("")