forked from p15670423/monkey
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:
parent
6282cd0de3
commit
bd60bef35f
|
@ -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))
|
||||
|
|
|
@ -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("")
|
||||
|
|
Loading…
Reference in New Issue