1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/unit/test_command_install.py

97 lines
2.9 KiB
Python
Raw Normal View History

import pytest
2019-02-28 05:30:03 +01:00
from mock import Mock, call, patch
from pip._internal.commands.install import build_wheels, decide_user_install
2019-02-28 05:30:03 +01:00
class TestWheelCache:
def check_build_wheels(
self,
pep517_requirements,
legacy_requirements,
):
"""
Return: (mock_calls, return_value).
"""
def build(reqs, **kwargs):
# Fail the first requirement.
return [reqs[0]]
builder = Mock()
builder.build.side_effect = build
build_failures = build_wheels(
builder=builder,
pep517_requirements=pep517_requirements,
legacy_requirements=legacy_requirements,
)
return (builder.build.mock_calls, build_failures)
@patch('pip._internal.commands.install.is_wheel_installed')
def test_build_wheels__wheel_installed(self, is_wheel_installed):
is_wheel_installed.return_value = True
2019-02-28 05:30:03 +01:00
mock_calls, build_failures = self.check_build_wheels(
pep517_requirements=['a', 'b'],
legacy_requirements=['c', 'd'],
)
# Legacy requirements were built.
assert mock_calls == [
2019-08-13 14:14:23 +02:00
call(['a', 'b'], should_unpack=True),
call(['c', 'd'], should_unpack=True),
2019-02-28 05:30:03 +01:00
]
# Legacy build failures are not included in the return value.
assert build_failures == ['a']
@patch('pip._internal.commands.install.is_wheel_installed')
def test_build_wheels__wheel_not_installed(self, is_wheel_installed):
is_wheel_installed.return_value = False
2019-02-28 05:30:03 +01:00
mock_calls, build_failures = self.check_build_wheels(
pep517_requirements=['a', 'b'],
legacy_requirements=['c', 'd'],
)
# Legacy requirements were not built.
assert mock_calls == [
2019-08-13 14:14:23 +02:00
call(['a', 'b'], should_unpack=True),
2019-02-28 05:30:03 +01:00
]
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
@pytest.mark.parametrize(
"enable_user_site,site_packages_writable,result", [
(True, True, False),
(True, False, True),
(False, True, False),
(False, False, False),
])
def test_most_cases(
self, enable_user_site, site_packages_writable, result, monkeypatch,
):
monkeypatch.setattr('site.ENABLE_USER_SITE', enable_user_site)
monkeypatch.setattr(
'pip._internal.commands.install.site_packages_writable',
lambda **kw: site_packages_writable
)
assert decide_user_install(use_user_site=None) is result