Add unit tests of decide_user_install()

This commit is contained in:
Thomas Kluyver 2019-10-20 21:48:18 +01:00
parent 16174f4ad0
commit fbc0588c01
2 changed files with 39 additions and 5 deletions

View File

@ -602,10 +602,10 @@ def site_packages_writable(**kwargs):
def decide_user_install(
use_user_site, # type: Optional[bool]
prefix_path, # type: Optional[str]
target_dir, # type: Optional[str]
root_path, # type: Optional[str]
isolated_mode, # type: bool
prefix_path=None, # type: Optional[str]
target_dir=None, # type: Optional[str]
root_path=None, # type: Optional[str]
isolated_mode=False, # type: bool
):
# type: (...) -> bool
"""Determine whether to do a user install based on the input options.

View File

@ -1,6 +1,6 @@
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:
@ -61,3 +61,37 @@ class TestWheelCache:
]
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