2015-11-30 23:30:39 +01:00
|
|
|
import ntpath
|
|
|
|
import os
|
|
|
|
import posixpath
|
2014-04-24 13:29:57 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import pretend
|
2017-06-13 14:17:00 +02:00
|
|
|
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.utils import appdirs
|
2014-04-24 13:29:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestUserCacheDir:
|
|
|
|
|
|
|
|
def test_user_cache_dir_win(self, monkeypatch):
|
|
|
|
@pretend.call_recorder
|
|
|
|
def _get_win_folder(base):
|
|
|
|
return "C:\\Users\\test\\AppData\\Local"
|
|
|
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
appdirs,
|
|
|
|
"_get_win_folder",
|
|
|
|
_get_win_folder,
|
|
|
|
raising=False,
|
|
|
|
)
|
2014-08-12 03:04:55 +02:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", True)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", ntpath)
|
2014-04-24 13:29:57 +02:00
|
|
|
|
2015-11-30 23:30:39 +01:00
|
|
|
assert (appdirs.user_cache_dir("pip") ==
|
2015-02-24 13:46:10 +01:00
|
|
|
"C:\\Users\\test\\AppData\\Local\\pip\\Cache")
|
2014-04-24 13:29:57 +02:00
|
|
|
assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
|
|
|
|
|
|
|
|
def test_user_cache_dir_osx(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-04-24 13:29:57 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "darwin")
|
|
|
|
|
|
|
|
assert appdirs.user_cache_dir("pip") == "/home/test/Library/Caches/pip"
|
|
|
|
|
|
|
|
def test_user_cache_dir_linux(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_CACHE_HOME", raising=False)
|
2014-04-24 13:29:57 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_cache_dir("pip") == "/home/test/.cache/pip"
|
|
|
|
|
|
|
|
def test_user_cache_dir_linux_override(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-04-24 13:29:57 +02:00
|
|
|
monkeypatch.setenv("XDG_CACHE_HOME", "/home/test/.other-cache")
|
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_cache_dir("pip") == "/home/test/.other-cache/pip"
|
2014-08-15 09:23:46 +02:00
|
|
|
|
2015-09-24 05:05:13 +02:00
|
|
|
def test_user_cache_dir_linux_home_slash(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2018-06-10 17:35:00 +02:00
|
|
|
# Verify that we are not affected by https://bugs.python.org/issue14768
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_CACHE_HOME", raising=False)
|
2015-09-24 05:05:13 +02:00
|
|
|
monkeypatch.setenv("HOME", "/")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_cache_dir("pip") == "/.cache/pip"
|
|
|
|
|
2016-10-05 23:45:21 +02:00
|
|
|
def test_user_cache_dir_unicode(self, monkeypatch):
|
|
|
|
if sys.platform != 'win32':
|
|
|
|
return
|
|
|
|
|
|
|
|
def my_get_win_folder(csidl_name):
|
|
|
|
return u"\u00DF\u00E4\u03B1\u20AC"
|
|
|
|
|
|
|
|
monkeypatch.setattr(appdirs, "_get_win_folder", my_get_win_folder)
|
|
|
|
|
|
|
|
# Do not use the isinstance expression directly in the
|
|
|
|
# assert statement, as the Unicode characters in the result
|
|
|
|
# cause pytest to fail with an internal error on Python 2.7
|
|
|
|
result_is_str = isinstance(appdirs.user_cache_dir('test'), str)
|
|
|
|
assert result_is_str, "user_cache_dir did not return a str"
|
|
|
|
|
|
|
|
# Test against regression #3463
|
2018-08-05 16:09:58 +02:00
|
|
|
from pip._internal.cli.main_parser import create_main_parser
|
2016-10-05 23:45:21 +02:00
|
|
|
create_main_parser().print_help() # This should not crash
|
2014-09-10 16:42:23 +02:00
|
|
|
|
2016-10-06 00:11:37 +02:00
|
|
|
|
2014-09-10 16:42:23 +02:00
|
|
|
class TestSiteConfigDirs:
|
|
|
|
|
2014-08-15 09:23:46 +02:00
|
|
|
def test_site_config_dirs_win(self, monkeypatch):
|
|
|
|
@pretend.call_recorder
|
|
|
|
def _get_win_folder(base):
|
|
|
|
return "C:\\ProgramData"
|
|
|
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
appdirs,
|
|
|
|
"_get_win_folder",
|
|
|
|
_get_win_folder,
|
|
|
|
raising=False,
|
|
|
|
)
|
2014-08-30 19:51:36 +02:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", True)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", ntpath)
|
2014-08-15 09:23:46 +02:00
|
|
|
|
2015-11-30 23:30:39 +01:00
|
|
|
assert appdirs.site_config_dirs("pip") == ["C:\\ProgramData\\pip"]
|
2014-08-15 09:23:46 +02:00
|
|
|
assert _get_win_folder.calls == [pretend.call("CSIDL_COMMON_APPDATA")]
|
|
|
|
|
|
|
|
def test_site_config_dirs_osx(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-08-15 09:23:46 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "darwin")
|
|
|
|
|
|
|
|
assert appdirs.site_config_dirs("pip") == \
|
|
|
|
["/Library/Application Support/pip"]
|
|
|
|
|
|
|
|
def test_site_config_dirs_linux(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_CONFIG_DIRS", raising=False)
|
2014-08-15 09:23:46 +02:00
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.site_config_dirs("pip") == [
|
|
|
|
'/etc/xdg/pip',
|
|
|
|
'/etc'
|
|
|
|
]
|
|
|
|
|
|
|
|
def test_site_config_dirs_linux_override(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2015-12-01 00:01:49 +01:00
|
|
|
monkeypatch.setattr(os, "pathsep", ':')
|
2014-08-15 09:23:46 +02:00
|
|
|
monkeypatch.setenv("XDG_CONFIG_DIRS", "/spam:/etc:/etc/xdg")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.site_config_dirs("pip") == [
|
|
|
|
'/spam/pip',
|
|
|
|
'/etc/pip',
|
|
|
|
'/etc/xdg/pip',
|
|
|
|
'/etc'
|
|
|
|
]
|
2014-08-31 01:52:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestUserDataDir:
|
|
|
|
|
|
|
|
def test_user_data_dir_win_no_roaming(self, monkeypatch):
|
|
|
|
@pretend.call_recorder
|
|
|
|
def _get_win_folder(base):
|
|
|
|
return "C:\\Users\\test\\AppData\\Local"
|
|
|
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
appdirs,
|
|
|
|
"_get_win_folder",
|
|
|
|
_get_win_folder,
|
|
|
|
raising=False,
|
|
|
|
)
|
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", True)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", ntpath)
|
2014-08-31 01:52:28 +02:00
|
|
|
|
2015-11-30 23:30:39 +01:00
|
|
|
assert (appdirs.user_data_dir("pip") ==
|
2015-02-24 13:46:10 +01:00
|
|
|
"C:\\Users\\test\\AppData\\Local\\pip")
|
2014-08-31 01:52:28 +02:00
|
|
|
assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
|
|
|
|
|
|
|
|
def test_user_data_dir_win_yes_roaming(self, monkeypatch):
|
|
|
|
@pretend.call_recorder
|
|
|
|
def _get_win_folder(base):
|
|
|
|
return "C:\\Users\\test\\AppData\\Roaming"
|
|
|
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
appdirs,
|
|
|
|
"_get_win_folder",
|
|
|
|
_get_win_folder,
|
|
|
|
raising=False,
|
|
|
|
)
|
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", True)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", ntpath)
|
2014-08-31 01:52:28 +02:00
|
|
|
|
2015-02-24 13:46:10 +01:00
|
|
|
assert (
|
2015-11-30 23:30:39 +01:00
|
|
|
appdirs.user_data_dir("pip", roaming=True) ==
|
2015-02-24 13:46:10 +01:00
|
|
|
"C:\\Users\\test\\AppData\\Roaming\\pip"
|
|
|
|
)
|
2014-08-31 01:52:28 +02:00
|
|
|
assert _get_win_folder.calls == [pretend.call("CSIDL_APPDATA")]
|
|
|
|
|
|
|
|
def test_user_data_dir_osx(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-08-31 01:52:28 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "darwin")
|
|
|
|
|
2016-11-19 15:01:38 +01:00
|
|
|
if os.path.isdir('/home/test/Library/Application Support/'):
|
2019-02-22 12:06:08 +01:00
|
|
|
assert (appdirs.user_data_dir("pip") ==
|
|
|
|
"/home/test/Library/Application Support/pip")
|
2016-11-19 15:01:38 +01:00
|
|
|
else:
|
2019-02-22 12:06:08 +01:00
|
|
|
assert (appdirs.user_data_dir("pip") ==
|
|
|
|
"/home/test/.config/pip")
|
2014-08-31 01:52:28 +02:00
|
|
|
|
|
|
|
def test_user_data_dir_linux(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_DATA_HOME", raising=False)
|
2014-08-31 01:52:28 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_data_dir("pip") == "/home/test/.local/share/pip"
|
|
|
|
|
|
|
|
def test_user_data_dir_linux_override(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-08-31 01:52:28 +02:00
|
|
|
monkeypatch.setenv("XDG_DATA_HOME", "/home/test/.other-share")
|
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_data_dir("pip") == "/home/test/.other-share/pip"
|
|
|
|
|
2015-09-24 05:05:13 +02:00
|
|
|
def test_user_data_dir_linux_home_slash(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2018-06-10 17:35:00 +02:00
|
|
|
# Verify that we are not affected by https://bugs.python.org/issue14768
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_DATA_HOME", raising=False)
|
2015-09-24 05:05:13 +02:00
|
|
|
monkeypatch.setenv("HOME", "/")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_data_dir("pip") == "/.local/share/pip"
|
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
|
2014-09-10 17:15:09 +02:00
|
|
|
class TestUserConfigDir:
|
|
|
|
|
|
|
|
def test_user_config_dir_win_no_roaming(self, monkeypatch):
|
|
|
|
@pretend.call_recorder
|
|
|
|
def _get_win_folder(base):
|
|
|
|
return "C:\\Users\\test\\AppData\\Local"
|
|
|
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
appdirs,
|
|
|
|
"_get_win_folder",
|
|
|
|
_get_win_folder,
|
|
|
|
raising=False,
|
|
|
|
)
|
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", True)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", ntpath)
|
2014-09-10 17:15:09 +02:00
|
|
|
|
|
|
|
assert (
|
2015-11-30 23:30:39 +01:00
|
|
|
appdirs.user_config_dir("pip", roaming=False) ==
|
2015-02-24 13:46:10 +01:00
|
|
|
"C:\\Users\\test\\AppData\\Local\\pip"
|
2014-09-10 17:15:09 +02:00
|
|
|
)
|
|
|
|
assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
|
|
|
|
|
|
|
|
def test_user_config_dir_win_yes_roaming(self, monkeypatch):
|
|
|
|
@pretend.call_recorder
|
|
|
|
def _get_win_folder(base):
|
|
|
|
return "C:\\Users\\test\\AppData\\Roaming"
|
|
|
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
appdirs,
|
|
|
|
"_get_win_folder",
|
|
|
|
_get_win_folder,
|
|
|
|
raising=False,
|
|
|
|
)
|
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", True)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", ntpath)
|
2014-09-10 17:15:09 +02:00
|
|
|
|
2015-11-30 23:30:39 +01:00
|
|
|
assert (appdirs.user_config_dir("pip") ==
|
2015-02-24 13:46:10 +01:00
|
|
|
"C:\\Users\\test\\AppData\\Roaming\\pip")
|
2014-09-10 17:15:09 +02:00
|
|
|
assert _get_win_folder.calls == [pretend.call("CSIDL_APPDATA")]
|
|
|
|
|
|
|
|
def test_user_config_dir_osx(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-09-10 17:15:09 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "darwin")
|
|
|
|
|
2016-11-19 15:01:38 +01:00
|
|
|
if os.path.isdir('/home/test/Library/Application Support/'):
|
2019-02-22 12:06:08 +01:00
|
|
|
assert (appdirs.user_data_dir("pip") ==
|
|
|
|
"/home/test/Library/Application Support/pip")
|
2016-11-19 15:01:38 +01:00
|
|
|
else:
|
2019-02-22 12:06:08 +01:00
|
|
|
assert (appdirs.user_data_dir("pip") ==
|
|
|
|
"/home/test/.config/pip")
|
2014-09-10 17:15:09 +02:00
|
|
|
|
|
|
|
def test_user_config_dir_linux(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
|
2014-09-10 17:15:09 +02:00
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_config_dir("pip") == "/home/test/.config/pip"
|
|
|
|
|
|
|
|
def test_user_config_dir_linux_override(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2014-09-10 17:15:09 +02:00
|
|
|
monkeypatch.setenv("XDG_CONFIG_HOME", "/home/test/.other-config")
|
|
|
|
monkeypatch.setenv("HOME", "/home/test")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_config_dir("pip") == "/home/test/.other-config/pip"
|
2015-09-24 05:05:13 +02:00
|
|
|
|
|
|
|
def test_user_config_dir_linux_home_slash(self, monkeypatch):
|
2015-11-30 22:50:15 +01:00
|
|
|
monkeypatch.setattr(appdirs, "WINDOWS", False)
|
2015-11-30 23:30:39 +01:00
|
|
|
monkeypatch.setattr(os, "path", posixpath)
|
2018-06-10 17:35:00 +02:00
|
|
|
# Verify that we are not affected by https://bugs.python.org/issue14768
|
2017-10-06 21:51:42 +02:00
|
|
|
monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
|
2015-09-24 05:05:13 +02:00
|
|
|
monkeypatch.setenv("HOME", "/")
|
|
|
|
monkeypatch.setattr(sys, "platform", "linux2")
|
|
|
|
|
|
|
|
assert appdirs.user_config_dir("pip") == "/.config/pip"
|