-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use PROJECT_HOME if available instead of XDG_*_HOME variables in unix systems
- Loading branch information
Showing
2 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from __future__ import annotations | ||
|
||
from os import environ | ||
from os import path | ||
from sys import platform | ||
|
||
from poetry.utils.appdirs import WINDOWS | ||
from poetry.utils.appdirs import expanduser | ||
from poetry.utils.appdirs import user_cache_dir | ||
from poetry.utils.appdirs import user_config_dir | ||
from poetry.utils.appdirs import user_data_dir | ||
|
||
|
||
def test_user_cache_dir(): | ||
if WINDOWS or (platform == "darwin"): | ||
return | ||
|
||
environ["PROJECT_HOME"] = "/poetry" | ||
environ["XDG_CACHE_HOME"] = "/xdg/.cache" | ||
appname = "pypoetry" | ||
default_user_cache_dir = path.join(expanduser("~/.cache"), appname) | ||
|
||
assert user_cache_dir(appname) == path.join( | ||
environ["PROJECT_HOME"], ".cache", appname | ||
) | ||
|
||
del environ["PROJECT_HOME"] | ||
assert user_cache_dir(appname) == path.join(environ["XDG_CACHE_HOME"], appname) | ||
|
||
del environ["XDG_CACHE_HOME"] | ||
assert user_cache_dir(appname) == default_user_cache_dir | ||
|
||
|
||
def test_user_config_dir(): | ||
if WINDOWS or (platform == "darwin"): | ||
return | ||
|
||
environ["PROJECT_HOME"] = "/poetry" | ||
environ["XDG_CONFIG_HOME"] = "/xdg/.config" | ||
appname = "pypoetry" | ||
default_user_config_dir = path.join(expanduser("~/.config"), appname) | ||
|
||
assert user_config_dir(appname) == path.join( | ||
environ["PROJECT_HOME"], ".config", appname | ||
) | ||
|
||
del environ["PROJECT_HOME"] | ||
assert user_config_dir(appname) == path.join(environ["XDG_CONFIG_HOME"], appname) | ||
|
||
del environ["XDG_CONFIG_HOME"] | ||
assert user_config_dir(appname) == default_user_config_dir | ||
|
||
|
||
def test_user_data_dir(): | ||
if WINDOWS or (platform == "darwin"): | ||
return | ||
|
||
environ["PROJECT_HOME"] = "/poetry" | ||
environ["XDG_DATA_HOME"] = "/xdg/.local/share" | ||
appname = "pypoetry" | ||
default_user_data_dir = path.join(expanduser("~/.local/share"), appname) | ||
|
||
assert user_data_dir(appname) == path.join( | ||
environ["PROJECT_HOME"], ".local/share", appname | ||
) | ||
|
||
del environ["PROJECT_HOME"] | ||
assert user_data_dir(appname) == path.join(environ["XDG_DATA_HOME"], appname) | ||
|
||
del environ["XDG_DATA_HOME"] | ||
assert user_data_dir(appname) == default_user_data_dir |