Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows appdirs tests #3275

Merged
merged 6 commits into from
Dec 1, 2015
Merged
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
2 changes: 1 addition & 1 deletion pip/utils/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def site_config_dirs(appname):
xdg_config_dirs = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
if xdg_config_dirs:
pathlist = [
os.sep.join([expanduser(x), appname])
os.path.join(expanduser(x), appname)
for x in xdg_config_dirs.split(os.pathsep)
]
else:
Expand Down
56 changes: 46 additions & 10 deletions tests/unit/test_appdirs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import ntpath
import os
import posixpath
import sys

import pretend
Expand All @@ -19,32 +22,41 @@ def _get_win_folder(base):
raising=False,
)
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

assert (appdirs.user_cache_dir("pip").replace("/", "\\") ==
assert (appdirs.user_cache_dir("pip") ==
"C:\\Users\\test\\AppData\\Local\\pip\\Cache")
assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]

def test_user_cache_dir_osx(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
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):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.delenv("XDG_CACHE_HOME")
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):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
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"

def test_user_cache_dir_linux_home_slash(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
# Verify that we are not affected by http://bugs.python.org/issue14768
monkeypatch.delenv("XDG_CACHE_HOME")
monkeypatch.setenv("HOME", "/")
Expand All @@ -67,22 +79,23 @@ def _get_win_folder(base):
raising=False,
)
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

result = [
e.replace("/", "\\")
for e in appdirs.site_config_dirs("pip")
]
assert result == ["C:\\ProgramData\\pip"]
assert appdirs.site_config_dirs("pip") == ["C:\\ProgramData\\pip"]
assert _get_win_folder.calls == [pretend.call("CSIDL_COMMON_APPDATA")]

def test_site_config_dirs_osx(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
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):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.delenv("XDG_CONFIG_DIRS")
monkeypatch.setattr(sys, "platform", "linux2")

Expand All @@ -92,6 +105,9 @@ def test_site_config_dirs_linux(self, monkeypatch):
]

def test_site_config_dirs_linux_override(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.setattr(os, "pathsep", ':')
monkeypatch.setenv("XDG_CONFIG_DIRS", "/spam:/etc:/etc/xdg")
monkeypatch.setattr(sys, "platform", "linux2")

Expand All @@ -117,8 +133,9 @@ def _get_win_folder(base):
raising=False,
)
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

assert (appdirs.user_data_dir("pip").replace("/", "\\") ==
assert (appdirs.user_data_dir("pip") ==
"C:\\Users\\test\\AppData\\Local\\pip")
assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]

Expand All @@ -134,35 +151,44 @@ def _get_win_folder(base):
raising=False,
)
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

assert (
appdirs.user_data_dir("pip", roaming=True).replace("/", "\\") ==
appdirs.user_data_dir("pip", roaming=True) ==
"C:\\Users\\test\\AppData\\Roaming\\pip"
)
assert _get_win_folder.calls == [pretend.call("CSIDL_APPDATA")]

def test_user_data_dir_osx(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.setenv("HOME", "/home/test")
monkeypatch.setattr(sys, "platform", "darwin")

assert (appdirs.user_data_dir("pip") ==
"/home/test/Library/Application Support/pip")

def test_user_data_dir_linux(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.delenv("XDG_DATA_HOME")
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):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
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"

def test_user_data_dir_linux_home_slash(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
# Verify that we are not affected by http://bugs.python.org/issue14768
monkeypatch.delenv("XDG_DATA_HOME")
monkeypatch.setenv("HOME", "/")
Expand All @@ -185,9 +211,10 @@ def _get_win_folder(base):
raising=False,
)
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

assert (
appdirs.user_config_dir("pip", roaming=False).replace("/", "\\") ==
appdirs.user_config_dir("pip", roaming=False) ==
"C:\\Users\\test\\AppData\\Local\\pip"
)
assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
Expand All @@ -204,33 +231,42 @@ def _get_win_folder(base):
raising=False,
)
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

assert (appdirs.user_config_dir("pip").replace("/", "\\") ==
assert (appdirs.user_config_dir("pip") ==
"C:\\Users\\test\\AppData\\Roaming\\pip")
assert _get_win_folder.calls == [pretend.call("CSIDL_APPDATA")]

def test_user_config_dir_osx(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.setenv("HOME", "/home/test")
monkeypatch.setattr(sys, "platform", "darwin")

assert (appdirs.user_config_dir("pip") ==
"/home/test/Library/Application Support/pip")

def test_user_config_dir_linux(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
monkeypatch.delenv("XDG_CONFIG_HOME")
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):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
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"

def test_user_config_dir_linux_home_slash(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
monkeypatch.setattr(os, "path", posixpath)
# Verify that we are not affected by http://bugs.python.org/issue14768
monkeypatch.delenv("XDG_CONFIG_HOME")
monkeypatch.setenv("HOME", "/")
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def test_unsupported_hashes(self, data):
'file',
2))[0])
finder = PackageFinder([data.find_links], [], session=PipSession())
sep = os.path.sep
if sep == '\\':
sep = '\\\\' # This needs to be escaped for the regex
assert_raises_regexp(
HashErrors,
r"Can't verify hashes for these requirements because we don't "
Expand All @@ -169,7 +172,8 @@ def test_unsupported_hashes(self, data):
r"\(line 1\)\)\n"
r"Can't verify hashes for these file:// requirements because they "
r"point to directories:\n"
r" file:///.*/data/packages/FSPkg \(from -r file \(line 2\)\)",
r" file://.*{sep}data{sep}packages{sep}FSPkg "
"\(from -r file \(line 2\)\)".format(sep=sep),
reqset.prepare_files,
finder)

Expand Down Expand Up @@ -448,7 +452,8 @@ def test_extras_for_editable_url_requirement(self):

def test_unexisting_path(self):
with pytest.raises(InstallationError) as e:
InstallRequirement.from_line('/this/path/does/not/exist')
InstallRequirement.from_line(
os.path.join('this', 'path', 'does', 'not', 'exist'))
err_msg = e.value.args[0]
assert "Invalid requirement" in err_msg
assert "It looks like a path. Does it exist ?" in err_msg
Expand Down