Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_root(monkeypatch):
monkeypatch.setattr("os.getenv", lambda _variable: None)
monkeypatch.setattr("os.path.expanduser", lambda _path: "/")

cache_path = get_default_user_home_cache_path()
Expand All @@ -14,13 +15,22 @@ def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_root(monkeyp


def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_unresolved(monkeypatch):
monkeypatch.setattr("os.getenv", lambda _variable: None)
monkeypatch.setattr("os.path.expanduser", lambda _path: "~")

cache_path = get_default_user_home_cache_path()

assert cache_path == os.path.join(tempfile.gettempdir(), ROOT_FOLDER_NAME)


def test_default_user_home_cache_path_with_xdg_cache_home_set(monkeypatch):
monkeypatch.setattr("os.getenv", lambda _variable: "/home/user/.cache")

cache_path = get_default_user_home_cache_path()

assert cache_path == os.path.join("/home/user/.cache", ROOT_FOLDER_NAME[1:])


def test_default_project_root_cache_path_uses_cwd_for_frozen_app(monkeypatch):
monkeypatch.setattr("sys.path", ["C:/app/base_library.zip"])
monkeypatch.setattr("sys.frozen", True, raising=False)
Expand Down
4 changes: 4 additions & 0 deletions webdriver_manager/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def get_default_project_root_cache_path():


def get_default_user_home_cache_path():
home = os.getenv('XDG_CACHE_HOME')
if home is not None:
return os.path.join(home, ROOT_FOLDER_NAME[1:])

home = os.path.expanduser("~")
if not home or home in (os.path.sep, "/") or home.startswith("~"):
home = tempfile.gettempdir()
Expand Down