mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Add unit tests of decide_user_install()
This commit is contained in:
parent
16174f4ad0
commit
fbc0588c01
2 changed files with 39 additions and 5 deletions
|
@ -602,10 +602,10 @@ def site_packages_writable(**kwargs):
|
||||||
|
|
||||||
def decide_user_install(
|
def decide_user_install(
|
||||||
use_user_site, # type: Optional[bool]
|
use_user_site, # type: Optional[bool]
|
||||||
prefix_path, # type: Optional[str]
|
prefix_path=None, # type: Optional[str]
|
||||||
target_dir, # type: Optional[str]
|
target_dir=None, # type: Optional[str]
|
||||||
root_path, # type: Optional[str]
|
root_path=None, # type: Optional[str]
|
||||||
isolated_mode, # type: bool
|
isolated_mode=False, # type: bool
|
||||||
):
|
):
|
||||||
# type: (...) -> bool
|
# type: (...) -> bool
|
||||||
"""Determine whether to do a user install based on the input options.
|
"""Determine whether to do a user install based on the input options.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from mock import Mock, call, patch
|
from mock import Mock, call, patch
|
||||||
|
|
||||||
from pip._internal.commands.install import build_wheels
|
from pip._internal.commands.install import build_wheels, decide_user_install
|
||||||
|
|
||||||
|
|
||||||
class TestWheelCache:
|
class TestWheelCache:
|
||||||
|
@ -61,3 +61,37 @@ class TestWheelCache:
|
||||||
]
|
]
|
||||||
|
|
||||||
assert build_failures == ['a']
|
assert build_failures == ['a']
|
||||||
|
|
||||||
|
|
||||||
|
class TestDecideUserInstall:
|
||||||
|
@patch('site.ENABLE_USER_SITE', True)
|
||||||
|
@patch('pip._internal.commands.install.site_packages_writable')
|
||||||
|
def test_prefix_and_target(self, sp_writable):
|
||||||
|
sp_writable.return_value = False
|
||||||
|
|
||||||
|
assert decide_user_install(
|
||||||
|
use_user_site=None, prefix_path='foo'
|
||||||
|
) is False
|
||||||
|
|
||||||
|
assert decide_user_install(
|
||||||
|
use_user_site=None, target_dir='bar'
|
||||||
|
) is False
|
||||||
|
|
||||||
|
@patch('pip._internal.commands.install.site_packages_writable')
|
||||||
|
def test_user_site_enabled(self, sp_writable):
|
||||||
|
sp_writable.return_value = False
|
||||||
|
|
||||||
|
with patch('site.ENABLE_USER_SITE', True):
|
||||||
|
assert decide_user_install(use_user_site=None) is True
|
||||||
|
|
||||||
|
with patch('site.ENABLE_USER_SITE', False):
|
||||||
|
assert decide_user_install(use_user_site=None) is False
|
||||||
|
|
||||||
|
@patch('site.ENABLE_USER_SITE', True)
|
||||||
|
@patch('pip._internal.commands.install.site_packages_writable')
|
||||||
|
def test_site_packages_access(self, sp_writable):
|
||||||
|
sp_writable.return_value = True
|
||||||
|
assert decide_user_install(use_user_site=None) is False
|
||||||
|
|
||||||
|
sp_writable.return_value = False
|
||||||
|
assert decide_user_install(use_user_site=None) is True
|
||||||
|
|
Loading…
Reference in a new issue