"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/installation/test_installer.py" between
poetry-1.1.15.tar.gz and poetry-1.2.0.tar.gz

About: Poetry is a tool for dependency management and packaging in Python.

test_installer.py  (poetry-1.1.15):test_installer.py  (poetry-1.2.0)
from __future__ import unicode_literals from __future__ import annotations
import itertools
import json import json
import sys
import pytest from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from clikit.io import NullIO import pytest
from poetry.core.packages import ProjectPackage from cleo.io.inputs.input import Input
from cleo.io.io import IO
from cleo.io.null_io import NullIO
from cleo.io.outputs.buffered_output import BufferedOutput
from cleo.io.outputs.output import Verbosity
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.packages.dependency_group import DependencyGroup
from poetry.core.packages.package import Package from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.toml.file import TOMLFile from poetry.core.toml.file import TOMLFile
from poetry.factory import Factory from poetry.factory import Factory
from poetry.installation import Installer as BaseInstaller from poetry.installation import Installer as BaseInstaller
from poetry.installation.executor import Executor as BaseExecutor from poetry.installation.executor import Executor as BaseExecutor
from poetry.installation.noop_installer import NoopInstaller from poetry.installation.noop_installer import NoopInstaller
from poetry.packages import Locker as BaseLocker from poetry.packages import Locker as BaseLocker
from poetry.repositories import Pool from poetry.repositories import Pool
from poetry.repositories import Repository from poetry.repositories import Repository
from poetry.repositories.installed_repository import InstalledRepository from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils._compat import PY2
from poetry.utils._compat import Path
from poetry.utils.env import MockEnv from poetry.utils.env import MockEnv
from poetry.utils.env import NullEnv from poetry.utils.env import NullEnv
from tests.helpers import MOCK_DEFAULT_GIT_REVISION
from tests.helpers import get_dependency from tests.helpers import get_dependency
from tests.helpers import get_package from tests.helpers import get_package
from tests.repositories.test_legacy_repository import ( from tests.repositories.test_legacy_repository import (
MockRepository as MockLegacyRepository, MockRepository as MockLegacyRepository,
) )
from tests.repositories.test_pypi_repository import MockRepository from tests.repositories.test_pypi_repository import MockRepository
if TYPE_CHECKING:
from pytest_mock import MockerFixture
from poetry.installation.operations.operation import Operation
from poetry.packages import DependencyPackage
from poetry.utils.env import Env
from tests.conftest import Config
from tests.types import FixtureDirGetter
RESERVED_PACKAGES = ("pip", "setuptools", "wheel")
class Installer(BaseInstaller): class Installer(BaseInstaller):
def _get_installer(self): def _get_installer(self) -> NoopInstaller:
return NoopInstaller() return NoopInstaller()
class Executor(BaseExecutor): class Executor(BaseExecutor):
def __init__(self, *args, **kwargs): def __init__(self, *args: Any, **kwargs: Any) -> None:
super(Executor, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._installs = [] self._installs: list[DependencyPackage] = []
self._updates = [] self._updates: list[DependencyPackage] = []
self._uninstalls = [] self._uninstalls: list[DependencyPackage] = []
@property @property
def installations(self): def installations(self) -> list[DependencyPackage]:
return self._installs return self._installs
@property @property
def updates(self): def updates(self) -> list[DependencyPackage]:
return self._updates return self._updates
@property @property
def removals(self): def removals(self) -> list[DependencyPackage]:
return self._uninstalls return self._uninstalls
def _do_execute_operation(self, operation): def _do_execute_operation(self, operation: Operation) -> None:
super(Executor, self)._do_execute_operation(operation) super()._do_execute_operation(operation)
if not operation.skipped: if not operation.skipped:
getattr(self, "_{}s".format(operation.job_type)).append(operation.pa ckage) getattr(self, f"_{operation.job_type}s").append(operation.package)
def _execute_install(self, operation): def _execute_install(self, operation: Operation) -> int:
return 0 return 0
def _execute_update(self, operation): def _execute_update(self, operation: Operation) -> int:
return 0 return 0
def _execute_uninstall(self, operation): def _execute_uninstall(self, operation: Operation) -> int:
return 0 return 0
class CustomInstalledRepository(InstalledRepository): class CustomInstalledRepository(InstalledRepository):
@classmethod @classmethod
def load(cls, env): def load(
cls, env: Env, with_dependencies: bool = False
) -> CustomInstalledRepository:
return cls() return cls()
class Locker(BaseLocker): class Locker(BaseLocker):
def __init__(self): def __init__(self, lock_path: str | Path) -> None:
self._lock = TOMLFile(Path.cwd().joinpath("poetry.lock")) self._lock = TOMLFile(Path(lock_path).joinpath("poetry.lock"))
self._written_data = None self._written_data = None
self._locked = False self._locked = False
self._content_hash = self._get_content_hash() self._content_hash = self._get_content_hash()
@property @property
def written_data(self): def written_data(self) -> dict | None:
return self._written_data return self._written_data
def set_lock_path(self, lock): def set_lock_path(self, lock: str | Path) -> Locker:
self._lock = TOMLFile(Path(lock).joinpath("poetry.lock")) self._lock = TOMLFile(Path(lock).joinpath("poetry.lock"))
return self return self
def locked(self, is_locked=True): def locked(self, is_locked: bool = True) -> Locker:
self._locked = is_locked self._locked = is_locked
return self return self
def mock_lock_data(self, data): def mock_lock_data(self, data: dict) -> None:
self._lock_data = data self._lock_data = data
def is_locked(self): def is_locked(self) -> bool:
return self._locked return self._locked
def is_fresh(self): def is_fresh(self) -> bool:
return True return True
def _get_content_hash(self): def _get_content_hash(self) -> str:
return "123456789" return "123456789"
def _write_lock_data(self, data): def _write_lock_data(self, data: dict) -> None:
for package in data["package"]: for package in data["package"]:
python_versions = str(package["python-versions"]) python_versions = str(package["python-versions"])
if PY2:
python_versions = python_versions.decode()
if "requirements" in package:
requirements = {}
for key, value in package["requirements"].items():
requirements[key.decode()] = value.decode()
package["requirements"] = requirements
package["python-versions"] = python_versions package["python-versions"] = python_versions
self._written_data = json.loads(json.dumps(data)) self._written_data = json.loads(json.dumps(data))
self._lock_data = data self._lock_data = data
@pytest.fixture() @pytest.fixture()
def package(): def package() -> ProjectPackage:
p = ProjectPackage("root", "1.0") p = ProjectPackage("root", "1.0")
p.root_dir = Path.cwd() p.root_dir = Path.cwd()
return p return p
@pytest.fixture() @pytest.fixture()
def repo(): def repo() -> Repository:
return Repository() return Repository("repo")
@pytest.fixture() @pytest.fixture()
def pool(repo): def pool(repo: Repository) -> Pool:
pool = Pool() pool = Pool()
pool.add_repository(repo) pool.add_repository(repo)
return pool return pool
@pytest.fixture() @pytest.fixture()
def installed(): def installed() -> CustomInstalledRepository:
return CustomInstalledRepository() return CustomInstalledRepository()
@pytest.fixture() @pytest.fixture()
def locker(): def locker(project_root: Path) -> Locker:
return Locker() return Locker(lock_path=project_root)
@pytest.fixture() @pytest.fixture()
def env(): def env() -> NullEnv:
return NullEnv() return NullEnv()
@pytest.fixture() @pytest.fixture()
def installer(package, pool, locker, env, installed, config): def installer(
package: ProjectPackage,
pool: Pool,
locker: Locker,
env: NullEnv,
installed: CustomInstalledRepository,
config: Config,
) -> Installer:
installer = Installer( installer = Installer(
NullIO(), NullIO(),
env, env,
package, package,
locker, locker,
pool, pool,
config, config,
installed=installed, installed=installed,
executor=Executor(env, pool, config, NullIO()), executor=Executor(env, pool, config, NullIO()),
) )
installer.use_executor(True) installer.use_executor(True)
return installer return installer
def fixture(name): def fixture(name: str) -> dict:
file = TOMLFile(Path(__file__).parent / "fixtures" / "{}.test".format(name)) file = TOMLFile(Path(__file__).parent / "fixtures" / f"{name}.test")
return json.loads(json.dumps(file.read())) return json.loads(json.dumps(file.read()))
def test_run_no_dependencies(installer, locker): def test_run_no_dependencies(installer: Installer, locker: Locker):
installer.run() installer.run()
expected = fixture("no-dependencies") expected = fixture("no-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_with_dependencies(installer, locker, repo, package): def test_run_with_dependencies(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0"))
package.add_dependency(Factory.create_dependency("B", "^1.0")) package.add_dependency(Factory.create_dependency("B", "^1.0"))
installer.run() installer.run()
expected = fixture("with-dependencies") expected = fixture("with-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_update_after_removing_dependencies( def test_run_update_after_removing_dependencies(
installer, locker, repo, package, installed installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
skipping to change at line 260 skipping to change at line 286
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0"))
package.add_dependency(Factory.create_dependency("B", "~1.1")) package.add_dependency(Factory.create_dependency("B", "~1.1"))
installer.update(True) installer.update(True)
installer.run() installer.run()
expected = fixture("with-dependencies") expected = fixture("with-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
assert 0 == installer.executor.installations_count assert installer.executor.installations_count == 0
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 1 == installer.executor.removals_count assert installer.executor.removals_count == 1
def test_run_install_no_dev(installer, locker, repo, package, installed): def _configure_run_install_dev(
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
with_optional_group: bool = False,
with_packages_installed: bool = False,
) -> None:
"""
Perform common test setup for `test_run_install_*dev*()` methods.
"""
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
skipping to change at line 312 skipping to change at line 348
}, },
} }
) )
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
package_c = get_package("C", "1.2") package_c = get_package("C", "1.2")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
installed.add_package(package_a) if with_packages_installed:
installed.add_package(package_b) installed.add_package(package_a)
installed.add_package(package_c) installed.add_package(package_b)
installed.add_package(package_c)
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0"))
package.add_dependency(Factory.create_dependency("B", "~1.1")) package.add_dependency(Factory.create_dependency("B", "~1.1"))
package.add_dependency(Factory.create_dependency("C", "~1.2", category="dev" ))
installer.dev_mode(False) group = DependencyGroup("dev", optional=with_optional_group)
group.add_dependency(Factory.create_dependency("C", "~1.2", groups=["dev"]))
package.add_dependency_group(group)
@pytest.mark.parametrize(
("groups", "installs", "updates", "removals", "with_packages_installed"),
[
(None, 2, 0, 0, False),
(None, 0, 0, 1, True),
([], 0, 0, 0, False),
([], 0, 0, 3, True),
(["dev"], 1, 0, 0, False),
(["dev"], 0, 0, 2, True),
([MAIN_GROUP], 2, 0, 0, False),
([MAIN_GROUP], 0, 0, 1, True),
([MAIN_GROUP, "dev"], 3, 0, 0, False),
([MAIN_GROUP, "dev"], 0, 0, 0, True),
],
)
def test_run_install_with_dependency_groups(
groups: list[str] | None,
installs: int,
updates: int,
removals: int,
with_packages_installed: bool,
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
):
_configure_run_install_dev(
locker,
repo,
package,
installed,
with_optional_group=True,
with_packages_installed=with_packages_installed,
)
if groups is not None:
installer.only_groups(groups)
installer.requires_synchronization(True)
installer.run() installer.run()
assert 0 == installer.executor.installations_count assert installer.executor.installations_count == installs
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == updates
assert 1 == installer.executor.removals_count assert installer.executor.removals_count == removals
def test_run_install_does_not_remove_locked_packages_if_installed_but_not_requir
ed(
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
):
package_a = get_package("a", "1.0")
package_b = get_package("b", "1.1")
package_c = get_package("c", "1.2")
repo.add_package(package_a)
installed.add_package(package_a)
repo.add_package(package_b)
installed.add_package(package_b)
repo.add_package(package_c)
installed.add_package(package_c)
installed.add_package(package) # Root package never removed.
package.add_dependency(Factory.create_dependency(package_a.name, package_a.v
ersion))
def test_run_install_remove_untracked(installer, locker, repo, package, installe d):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "a", "name": package_a.name,
"version": "1.0", "version": package_a.version.text,
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
"python-versions": "*", "python-versions": "*",
"checksum": [], "checksum": [],
} },
{
"name": package_b.name,
"version": package_b.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
{
"name": package_c.name,
"version": package_c.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
], ],
"metadata": { "metadata": {
"python-versions": "*", "python-versions": "*",
"platform": "*", "platform": "*",
"content-hash": "123456789", "content-hash": "123456789",
"hashes": {"a": []}, "hashes": {package_a.name: [], package_b.name: [], package_c.nam e: []},
}, },
} }
) )
installer.run()
assert installer.executor.installations_count == 0
assert installer.executor.updates_count == 0
assert installer.executor.removals_count == 0
def test_run_install_removes_locked_packages_if_installed_and_synchronization_is
_required( # noqa: E501
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
):
package_a = get_package("a", "1.0") package_a = get_package("a", "1.0")
package_b = get_package("b", "1.1") package_b = get_package("b", "1.1")
package_c = get_package("c", "1.2") package_c = get_package("c", "1.2")
package_pip = get_package("pip", "20.0.0")
repo.add_package(package_a) repo.add_package(package_a)
installed.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
installed.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
repo.add_package(package_pip) installed.add_package(package_c)
installed.add_package(package) # Root package never removed.
package.add_dependency(Factory.create_dependency(package_a.name, package_a.v
ersion))
locker.locked(True)
locker.mock_lock_data(
{
"package": [
{
"name": package_a.name,
"version": package_a.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
{
"name": package_b.name,
"version": package_b.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
{
"name": package_c.name,
"version": package_c.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
"hashes": {package_a.name: [], package_b.name: [], package_c.nam
e: []},
},
}
)
installer.requires_synchronization(True)
installer.run()
assert installer.executor.installations_count == 0
assert installer.executor.updates_count == 0
assert installer.executor.removals_count == 2
def test_run_install_removes_no_longer_locked_packages_if_installed(
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
):
package_a = get_package("a", "1.0")
package_b = get_package("b", "1.1")
package_c = get_package("c", "1.2")
repo.add_package(package_a)
installed.add_package(package_a) installed.add_package(package_a)
repo.add_package(package_b)
installed.add_package(package_b) installed.add_package(package_b)
repo.add_package(package_c)
installed.add_package(package_c) installed.add_package(package_c)
installed.add_package(package_pip) # Always required and never removed.
installed.add_package(package) # Root package never removed. installed.add_package(package) # Root package never removed.
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency(package_a.name, package_a.v ersion))
installer.dev_mode(True).remove_untracked(True) locker.locked(True)
locker.mock_lock_data(
{
"package": [
{
"name": package_a.name,
"version": package_a.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
{
"name": package_b.name,
"version": package_b.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
{
"name": package_c.name,
"version": package_c.version.text,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
"hashes": {package_a.name: [], package_b.name: [], package_c.nam
e: []},
},
}
)
installer.update(True)
installer.run() installer.run()
assert 0 == installer.executor.installations_count assert installer.executor.installations_count == 0
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 2 == installer.executor.removals_count assert installer.executor.removals_count == 2
assert {"b", "c"} == set(r.name for r in installer.executor.removals)
@pytest.mark.parametrize(
"managed_reserved_package_names",
itertools.chain(
[()],
itertools.permutations(RESERVED_PACKAGES, 1),
itertools.permutations(RESERVED_PACKAGES, 2),
[RESERVED_PACKAGES],
),
)
def test_run_install_with_synchronization(
managed_reserved_package_names: tuple[str, ...],
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
):
package_a = get_package("a", "1.0")
package_b = get_package("b", "1.1")
package_c = get_package("c", "1.2")
package_pip = get_package("pip", "20.0.0")
package_setuptools = get_package("setuptools", "20.0.0")
package_wheel = get_package("wheel", "20.0.0")
def test_run_whitelist_add(installer, locker, repo, package): all_packages = [
package_a,
package_b,
package_c,
package_pip,
package_setuptools,
package_wheel,
]
managed_reserved_packages = [
pkg for pkg in all_packages if pkg.name in managed_reserved_package_name
s
]
locked_packages = [package_a, *managed_reserved_packages]
for pkg in all_packages:
repo.add_package(pkg)
installed.add_package(pkg)
installed.add_package(package) # Root package never removed.
package.add_dependency(Factory.create_dependency(package_a.name, package_a.v
ersion))
locker.locked(True)
locker.mock_lock_data(
{
"package": [
{
"name": pkg.name,
"version": pkg.version,
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
}
for pkg in locked_packages
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
"hashes": {pkg.name: [] for pkg in locked_packages},
},
}
)
installer.requires_synchronization(True)
installer.run()
assert installer.executor.installations_count == 0
assert installer.executor.updates_count == 0
assert 2 + len(managed_reserved_packages) == installer.executor.removals_cou
nt
expected_removals = {
package_b.name,
package_c.name,
*managed_reserved_package_names,
}
assert {r.name for r in installer.executor.removals} == expected_removals
def test_run_whitelist_add(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
skipping to change at line 416 skipping to change at line 743
package.add_dependency(Factory.create_dependency("B", "^1.0")) package.add_dependency(Factory.create_dependency("B", "^1.0"))
installer.update(True) installer.update(True)
installer.whitelist(["B"]) installer.whitelist(["B"])
installer.run() installer.run()
expected = fixture("with-dependencies") expected = fixture("with-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_whitelist_remove(installer, locker, repo, package, installed): def test_run_whitelist_remove(
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
skipping to change at line 463 skipping to change at line 796
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0"))
installer.update(True) installer.update(True)
installer.whitelist(["B"]) installer.whitelist(["B"])
installer.run() installer.run()
expected = fixture("remove") expected = fixture("remove")
assert locker.written_data == expected assert locker.written_data == expected
assert 1 == installer.executor.installations_count assert installer.executor.installations_count == 1
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 1 == installer.executor.removals_count assert installer.executor.removals_count == 1
def test_add_with_sub_dependencies(installer, locker, repo, package): def test_add_with_sub_dependencies(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
package_c = get_package("C", "1.2") package_c = get_package("C", "1.2")
package_d = get_package("D", "1.3") package_d = get_package("D", "1.3")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
repo.add_package(package_d) repo.add_package(package_d)
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0"))
package.add_dependency(Factory.create_dependency("B", "^1.0")) package.add_dependency(Factory.create_dependency("B", "^1.0"))
package_a.add_dependency(Factory.create_dependency("D", "^1.0")) package_a.add_dependency(Factory.create_dependency("D", "^1.0"))
package_b.add_dependency(Factory.create_dependency("C", "~1.2")) package_b.add_dependency(Factory.create_dependency("C", "~1.2"))
installer.run() installer.run()
expected = fixture("with-sub-dependencies") expected = fixture("with-sub-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_with_python_versions(installer, locker, repo, package): def test_run_with_python_versions(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package.python_versions = "~2.7 || ^3.4" package.python_versions = "~2.7 || ^3.4"
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
package_c12 = get_package("C", "1.2") package_c12 = get_package("C", "1.2")
package_c12.python_versions = "~2.7 || ^3.3" package_c12.python_versions = "~2.7 || ^3.3"
package_c13 = get_package("C", "1.3") package_c13 = get_package("C", "1.3")
package_c13.python_versions = "~3.3" package_c13.python_versions = "~3.3"
repo.add_package(package_a) repo.add_package(package_a)
skipping to change at line 513 skipping to change at line 850
package.add_dependency(Factory.create_dependency("A", "~1.0")) package.add_dependency(Factory.create_dependency("A", "~1.0"))
package.add_dependency(Factory.create_dependency("B", "^1.0")) package.add_dependency(Factory.create_dependency("B", "^1.0"))
package.add_dependency(Factory.create_dependency("C", "^1.0")) package.add_dependency(Factory.create_dependency("C", "^1.0"))
installer.run() installer.run()
expected = fixture("with-python-versions") expected = fixture("with-python-versions")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_with_optional_and_python_restricted_dependencies( def test_run_with_optional_and_python_restricted_dependencies(
installer, locker, repo, package installer: Installer, locker: Locker, repo: Repository, package: ProjectPack age
): ):
package.python_versions = "~2.7 || ^3.4" package.python_versions = "~2.7 || ^3.4"
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
package_c12 = get_package("C", "1.2") package_c12 = get_package("C", "1.2")
package_c13 = get_package("C", "1.3") package_c13 = get_package("C", "1.3")
package_d = get_package("D", "1.4") package_d = get_package("D", "1.4")
package_c13.add_dependency(Factory.create_dependency("D", "^1.2")) package_c13.add_dependency(Factory.create_dependency("D", "^1.2"))
skipping to change at line 549 skipping to change at line 886
) )
installer.run() installer.run()
expected = fixture("with-optional-dependencies") expected = fixture("with-optional-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
# We should only have 2 installs: # We should only have 2 installs:
# C,D since python version is not compatible # C,D since python version is not compatible
# with B's python constraint and A is optional # with B's python constraint and A is optional
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
assert "d" == installer.executor.installations[0].name assert installer.executor.installations[0].name == "d"
assert "c" == installer.executor.installations[1].name assert installer.executor.installations[1].name == "c"
def test_run_with_optional_and_platform_restricted_dependencies( def test_run_with_optional_and_platform_restricted_dependencies(
installer, locker, repo, package, mocker installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
mocker: MockerFixture,
): ):
mocker.patch("sys.platform", "darwin") mocker.patch("sys.platform", "darwin")
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
package_c12 = get_package("C", "1.2") package_c12 = get_package("C", "1.2")
package_c13 = get_package("C", "1.3") package_c13 = get_package("C", "1.3")
package_d = get_package("D", "1.4") package_d = get_package("D", "1.4")
package_c13.add_dependency(Factory.create_dependency("D", "^1.2")) package_c13.add_dependency(Factory.create_dependency("D", "^1.2"))
skipping to change at line 590 skipping to change at line 931
) )
installer.run() installer.run()
expected = fixture("with-platform-dependencies") expected = fixture("with-platform-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
# We should only have 2 installs: # We should only have 2 installs:
# C,D since the mocked python version is not compatible # C,D since the mocked python version is not compatible
# with B's python constraint and A is optional # with B's python constraint and A is optional
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
assert "d" == installer.executor.installations[0].name assert installer.executor.installations[0].name == "d"
assert "c" == installer.executor.installations[1].name assert installer.executor.installations[1].name == "c"
def test_run_with_dependencies_extras(installer, locker, repo, package): def test_run_with_dependencies_extras(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0") package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0") package_c = get_package("C", "1.0")
package_b.extras = {"foo": [get_dependency("C", "^1.0")]} package_b.extras = {"foo": [get_dependency("C", "^1.0")]}
package_b.add_dependency( package_b.add_dependency(
Factory.create_dependency("C", {"version": "^1.0", "optional": True}) Factory.create_dependency("C", {"version": "^1.0", "optional": True})
) )
repo.add_package(package_a) repo.add_package(package_a)
skipping to change at line 618 skipping to change at line 961
package.add_dependency(Factory.create_dependency("A", "^1.0")) package.add_dependency(Factory.create_dependency("A", "^1.0"))
package.add_dependency( package.add_dependency(
Factory.create_dependency("B", {"version": "^1.0", "extras": ["foo"]}) Factory.create_dependency("B", {"version": "^1.0", "extras": ["foo"]})
) )
installer.run() installer.run()
expected = fixture("with-dependencies-extras") expected = fixture("with-dependencies-extras")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_with_dependencies_nested_extras(installer, locker, repo, package): def test_run_with_dependencies_nested_extras(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0") package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0") package_c = get_package("C", "1.0")
dependency_c = Factory.create_dependency("C", {"version": "^1.0", "optional" : True}) dependency_c = Factory.create_dependency("C", {"version": "^1.0", "optional" : True})
dependency_b = Factory.create_dependency( dependency_b = Factory.create_dependency(
"B", {"version": "^1.0", "optional": True, "extras": ["C"]} "B", {"version": "^1.0", "optional": True, "extras": ["C"]}
) )
dependency_a = Factory.create_dependency("A", {"version": "^1.0", "extras": ["B"]}) dependency_a = Factory.create_dependency("A", {"version": "^1.0", "extras": ["B"]})
package_b.extras = {"C": [dependency_c]} package_b.extras = {"c": [dependency_c]}
package_b.add_dependency(dependency_c) package_b.add_dependency(dependency_c)
package_a.add_dependency(dependency_b) package_a.add_dependency(dependency_b)
package_a.extras = {"B": [dependency_b]} package_a.extras = {"b": [dependency_b]}
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
package.add_dependency(dependency_a) package.add_dependency(dependency_a)
installer.run() installer.run()
expected = fixture("with-dependencies-nested-extras") expected = fixture("with-dependencies-nested-extras")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_does_not_install_extras_if_not_requested(installer, locker, repo, p def test_run_does_not_install_extras_if_not_requested(
ackage): installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package.extras["foo"] = [get_dependency("D")] package.extras["foo"] = [get_dependency("D")]
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0") package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0") package_c = get_package("C", "1.0")
package_d = get_package("D", "1.1") package_d = get_package("D", "1.1")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
repo.add_package(package_d) repo.add_package(package_d)
skipping to change at line 672 skipping to change at line 1019
Factory.create_dependency("D", {"version": "^1.0", "optional": True}) Factory.create_dependency("D", {"version": "^1.0", "optional": True})
) )
installer.run() installer.run()
expected = fixture("extras") expected = fixture("extras")
# Extras are pinned in lock # Extras are pinned in lock
assert locker.written_data == expected assert locker.written_data == expected
# But should not be installed # But should not be installed
assert 3 == installer.executor.installations_count # A, B, C assert installer.executor.installations_count == 3 # A, B, C
def test_run_installs_extras_if_requested(installer, locker, repo, package): def test_run_installs_extras_if_requested(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package.extras["foo"] = [get_dependency("D")] package.extras["foo"] = [get_dependency("D")]
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0") package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0") package_c = get_package("C", "1.0")
package_d = get_package("D", "1.1") package_d = get_package("D", "1.1")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
repo.add_package(package_d) repo.add_package(package_d)
skipping to change at line 701 skipping to change at line 1050
) )
installer.extras(["foo"]) installer.extras(["foo"])
installer.run() installer.run()
expected = fixture("extras") expected = fixture("extras")
# Extras are pinned in lock # Extras are pinned in lock
assert locker.written_data == expected assert locker.written_data == expected
# But should not be installed # But should not be installed
assert 4 == installer.executor.installations_count # A, B, C, D assert installer.executor.installations_count == 4 # A, B, C, D
def test_run_installs_extras_with_deps_if_requested(installer, locker, repo, pac def test_run_installs_extras_with_deps_if_requested(
kage): installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
package.extras["foo"] = [get_dependency("C")] package.extras["foo"] = [get_dependency("C")]
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0") package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0") package_c = get_package("C", "1.0")
package_d = get_package("D", "1.1") package_d = get_package("D", "1.1")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
repo.add_package(package_d) repo.add_package(package_d)
skipping to change at line 731 skipping to change at line 1082
package_c.add_dependency(Factory.create_dependency("D", "^1.0")) package_c.add_dependency(Factory.create_dependency("D", "^1.0"))
installer.extras(["foo"]) installer.extras(["foo"])
installer.run() installer.run()
expected = fixture("extras-with-dependencies") expected = fixture("extras-with-dependencies")
# Extras are pinned in lock # Extras are pinned in lock
assert locker.written_data == expected assert locker.written_data == expected
# But should not be installed # But should not be installed
assert 4 == installer.executor.installations_count # A, B, C, D assert installer.executor.installations_count == 4 # A, B, C, D
def test_run_installs_extras_with_deps_if_requested_locked( def test_run_installs_extras_with_deps_if_requested_locked(
installer, locker, repo, package installer: Installer, locker: Locker, repo: Repository, package: ProjectPack age
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data(fixture("extras-with-dependencies")) locker.mock_lock_data(fixture("extras-with-dependencies"))
package.extras["foo"] = [get_dependency("C")] package.extras["foo"] = [get_dependency("C")]
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.0") package_b = get_package("B", "1.0")
package_c = get_package("C", "1.0") package_c = get_package("C", "1.0")
package_d = get_package("D", "1.1") package_d = get_package("D", "1.1")
repo.add_package(package_a) repo.add_package(package_a)
skipping to change at line 761 skipping to change at line 1112
package.add_dependency( package.add_dependency(
Factory.create_dependency("C", {"version": "^1.0", "optional": True}) Factory.create_dependency("C", {"version": "^1.0", "optional": True})
) )
package_c.add_dependency(Factory.create_dependency("D", "^1.0")) package_c.add_dependency(Factory.create_dependency("D", "^1.0"))
installer.extras(["foo"]) installer.extras(["foo"])
installer.run() installer.run()
# But should not be installed # But should not be installed
assert 4 == installer.executor.installations_count # A, B, C, D assert installer.executor.installations_count == 4 # A, B, C, D
def test_installer_with_pypi_repository(package, locker, installed, config): def test_installer_with_pypi_repository(
package: ProjectPackage,
locker: Locker,
installed: CustomInstalledRepository,
config: Config,
):
pool = Pool() pool = Pool()
pool.add_repository(MockRepository()) pool.add_repository(MockRepository())
installer = Installer( installer = Installer(
NullIO(), NullEnv(), package, locker, pool, config, installed=installed NullIO(), NullEnv(), package, locker, pool, config, installed=installed
) )
package.add_dependency(Factory.create_dependency("pytest", "^3.5", category= "dev")) package.add_dependency(Factory.create_dependency("pytest", "^3.5", groups=[" dev"]))
installer.run() installer.run()
expected = fixture("with-pypi-repository") expected = fixture("with-pypi-repository")
assert locker.written_data == expected assert expected == locker.written_data
def test_run_installs_with_local_file(installer, locker, repo, package, fixture_ def test_run_installs_with_local_file(
dir): installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
fixture_dir: FixtureDirGetter,
):
root_dir = Path(__file__).parent.parent.parent
package.root_dir = root_dir
locker.set_lock_path(root_dir)
file_path = fixture_dir("distributions/demo-0.1.0-py2.py3-none-any.whl") file_path = fixture_dir("distributions/demo-0.1.0-py2.py3-none-any.whl")
package.add_dependency(Factory.create_dependency("demo", {"file": str(file_p package.add_dependency(
ath)})) Factory.create_dependency(
"demo", {"file": str(file_path.relative_to(root_dir))}, root_dir=roo
t_dir
)
)
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
installer.run() installer.run()
expected = fixture("with-file-dependency") expected = fixture("with-file-dependency")
assert locker.written_data == expected assert locker.written_data == expected
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
def test_run_installs_wheel_with_no_requires_dist( def test_run_installs_wheel_with_no_requires_dist(
installer, locker, repo, package, fixture_dir installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
fixture_dir: FixtureDirGetter,
): ):
root_dir = Path(__file__).parent.parent.parent
package.root_dir = root_dir
locker.set_lock_path(root_dir)
file_path = fixture_dir( file_path = fixture_dir(
"wheel_with_no_requires_dist/demo-0.1.0-py2.py3-none-any.whl" "wheel_with_no_requires_dist/demo-0.1.0-py2.py3-none-any.whl"
) )
package.add_dependency(Factory.create_dependency("demo", {"file": str(file_p package.add_dependency(
ath)})) Factory.create_dependency(
"demo", {"file": str(file_path.relative_to(root_dir))}, root_dir=roo
t_dir
)
)
installer.run() installer.run()
expected = fixture("with-wheel-dependency-no-requires-dist") expected = fixture("with-wheel-dependency-no-requires-dist")
assert locker.written_data == expected assert locker.written_data == expected
assert 1 == installer.executor.installations_count assert installer.executor.installations_count == 1
def test_run_installs_with_local_poetry_directory_and_extras( def test_run_installs_with_local_poetry_directory_and_extras(
installer, locker, repo, package, tmpdir, fixture_dir installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
tmpdir: Path,
fixture_dir: FixtureDirGetter,
): ):
root_dir = Path(__file__).parent.parent.parent
package.root_dir = root_dir
locker.set_lock_path(root_dir)
file_path = fixture_dir("project_with_extras") file_path = fixture_dir("project_with_extras")
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"project-with-extras", {"path": str(file_path), "extras": ["extras_a "project-with-extras",
"]} {"path": str(file_path.relative_to(root_dir)), "extras": ["extras_a"
]},
root_dir=root_dir,
) )
) )
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
installer.run() installer.run()
expected = fixture("with-directory-dependency-poetry") expected = fixture("with-directory-dependency-poetry")
assert locker.written_data == expected assert locker.written_data == expected
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
def test_run_installs_with_local_poetry_directory_transitive( def test_run_installs_with_local_poetry_directory_transitive(
installer, locker, repo, package, tmpdir, fixture_dir installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
tmpdir: Path,
fixture_dir: FixtureDirGetter,
): ):
root_dir = fixture_dir("directory") root_dir = fixture_dir("directory")
package.root_dir = root_dir package.root_dir = root_dir
locker.set_lock_path(root_dir) locker.set_lock_path(root_dir)
directory = root_dir.joinpath("project_with_transitive_directory_dependencie s") directory = root_dir.joinpath("project_with_transitive_directory_dependencie s")
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"project-with-transitive-directory-dependencies", "project-with-transitive-directory-dependencies",
{"path": str(directory.relative_to(root_dir))}, {"path": str(directory.relative_to(root_dir))},
root_dir=root_dir, root_dir=root_dir,
skipping to change at line 850 skipping to change at line 1245
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
repo.add_package(get_package("cachy", "0.2.0")) repo.add_package(get_package("cachy", "0.2.0"))
installer.run() installer.run()
expected = fixture("with-directory-dependency-poetry-transitive") expected = fixture("with-directory-dependency-poetry-transitive")
assert locker.written_data == expected assert locker.written_data == expected
assert 6 == installer.executor.installations_count assert installer.executor.installations_count == 6
def test_run_installs_with_local_poetry_file_transitive( def test_run_installs_with_local_poetry_file_transitive(
installer, locker, repo, package, tmpdir, fixture_dir installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
tmpdir: str,
fixture_dir: FixtureDirGetter,
): ):
root_dir = fixture_dir("directory") root_dir = fixture_dir("directory")
package.root_dir = root_dir package.root_dir = root_dir
locker.set_lock_path(root_dir) locker.set_lock_path(root_dir)
directory = fixture_dir("directory").joinpath( directory = fixture_dir("directory").joinpath(
"project_with_transitive_file_dependencies" "project_with_transitive_file_dependencies"
) )
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"project-with-transitive-file-dependencies", "project-with-transitive-file-dependencies",
skipping to change at line 878 skipping to change at line 1278
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
repo.add_package(get_package("cachy", "0.2.0")) repo.add_package(get_package("cachy", "0.2.0"))
installer.run() installer.run()
expected = fixture("with-file-dependency-transitive") expected = fixture("with-file-dependency-transitive")
assert locker.written_data == expected assert locker.written_data == expected
assert 4 == installer.executor.installations_count assert installer.executor.installations_count == 4
def test_run_installs_with_local_setuptools_directory( def test_run_installs_with_local_setuptools_directory(
installer, locker, repo, package, tmpdir, fixture_dir installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
tmpdir: Path,
fixture_dir: FixtureDirGetter,
): ):
root_dir = Path(__file__).parent.parent.parent
package.root_dir = root_dir
locker.set_lock_path(root_dir)
file_path = fixture_dir("project_with_setup/") file_path = fixture_dir("project_with_setup/")
package.add_dependency( package.add_dependency(
Factory.create_dependency("project-with-setup", {"path": str(file_path)} Factory.create_dependency(
) "project-with-setup",
{"path": str(file_path.relative_to(root_dir))},
root_dir=root_dir,
)
) )
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
repo.add_package(get_package("cachy", "0.2.0")) repo.add_package(get_package("cachy", "0.2.0"))
installer.run() installer.run()
expected = fixture("with-directory-dependency-setuptools") expected = fixture("with-directory-dependency-setuptools")
assert locker.written_data == expected assert locker.written_data == expected
assert 3 == installer.executor.installations_count assert installer.executor.installations_count == 3
def test_run_with_prereleases(installer, locker, repo, package): def test_run_with_prereleases(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0a2", "version": "1.0a2",
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
skipping to change at line 939 skipping to change at line 1353
package.add_dependency(Factory.create_dependency("B", "^1.1")) package.add_dependency(Factory.create_dependency("B", "^1.1"))
installer.update(True) installer.update(True)
installer.whitelist({"B": "^1.1"}) installer.whitelist({"B": "^1.1"})
installer.run() installer.run()
expected = fixture("with-prereleases") expected = fixture("with-prereleases")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_changes_category_if_needed(installer, locker, repo, package): def test_run_changes_category_if_needed(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "dev", "category": "dev",
"optional": True, "optional": True,
"platform": "*", "platform": "*",
skipping to change at line 970 skipping to change at line 1386
} }
) )
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1") package_b = get_package("B", "1.1")
package_b.add_dependency(Factory.create_dependency("A", "^1.0")) package_b.add_dependency(Factory.create_dependency("A", "^1.0"))
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"A", {"version": "^1.0", "optional": True}, category="dev" "A", {"version": "^1.0", "optional": True}, groups=["dev"]
) )
) )
package.add_dependency(Factory.create_dependency("B", "^1.1")) package.add_dependency(Factory.create_dependency("B", "^1.1"))
installer.update(True) installer.update(True)
installer.whitelist(["B"]) installer.whitelist(["B"])
installer.run() installer.run()
expected = fixture("with-category-change") expected = fixture("with-category-change")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_update_all_with_lock(installer, locker, repo, package): def test_run_update_all_with_lock(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "dev", "category": "dev",
"optional": True, "optional": True,
"platform": "*", "platform": "*",
skipping to change at line 1019 skipping to change at line 1437
package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("A", "*"))
installer.update(True) installer.update(True)
installer.run() installer.run()
expected = fixture("update-with-lock") expected = fixture("update-with-lock")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_update_with_locked_extras(installer, locker, repo, package): def test_run_update_with_locked_extras(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
skipping to change at line 1068 skipping to change at line 1488
"hashes": {"A": [], "B": [], "C": []}, "hashes": {"A": [], "B": [], "C": []},
}, },
} }
) )
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_a.extras["foo"] = [get_dependency("B")] package_a.extras["foo"] = [get_dependency("B")]
b_dependency = get_dependency("B", "^1.0", optional=True) b_dependency = get_dependency("B", "^1.0", optional=True)
b_dependency.in_extras.append("foo") b_dependency.in_extras.append("foo")
c_dependency = get_dependency("C", "^1.0") c_dependency = get_dependency("C", "^1.0")
c_dependency.python_versions = "~2.7" c_dependency.python_versions = "~2.7"
package_a.requires.append(b_dependency) package_a.add_dependency(b_dependency)
package_a.requires.append(c_dependency) package_a.add_dependency(c_dependency)
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(get_package("B", "1.0")) repo.add_package(get_package("B", "1.0"))
repo.add_package(get_package("C", "1.1")) repo.add_package(get_package("C", "1.1"))
repo.add_package(get_package("D", "1.1")) repo.add_package(get_package("D", "1.1"))
package.add_dependency( package.add_dependency(
Factory.create_dependency("A", {"version": "^1.0", "extras": ["foo"]}) Factory.create_dependency("A", {"version": "^1.0", "extras": ["foo"]})
) )
package.add_dependency(Factory.create_dependency("D", "^1.0")) package.add_dependency(Factory.create_dependency("D", "^1.0"))
installer.update(True) installer.update(True)
installer.whitelist("D") installer.whitelist("D")
installer.run() installer.run()
expected = fixture("update-with-locked-extras") expected = fixture("update-with-locked-extras")
assert locker.written_data == expected assert locker.written_data == expected
def test_run_install_duplicate_dependencies_different_constraints( def test_run_install_duplicate_dependencies_different_constraints(
installer, locker, repo, package installer: Installer, locker: Locker, repo: Repository, package: ProjectPack age
): ):
package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("A", "*"))
package_a = get_package("A", "1.0") package_a = get_package("A", "1.0")
package_a.add_dependency( package_a.add_dependency(
Factory.create_dependency("B", {"version": "^1.0", "python": "<4.0"}) Factory.create_dependency("B", {"version": "^1.0", "python": "<4.0"})
) )
package_a.add_dependency( package_a.add_dependency(
Factory.create_dependency("B", {"version": "^2.0", "python": ">=4.0"}) Factory.create_dependency("B", {"version": "^2.0", "python": ">=4.0"})
) )
skipping to change at line 1123 skipping to change at line 1543
repo.add_package(package_c12) repo.add_package(package_c12)
repo.add_package(package_c15) repo.add_package(package_c15)
installer.run() installer.run()
expected = fixture("with-duplicate-dependencies") expected = fixture("with-duplicate-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
installs = installer.executor.installations installs = installer.executor.installations
assert 3 == installer.executor.installations_count assert installer.executor.installations_count == 3
assert installs[0] == package_c12 assert installs[0] == package_c12
assert installs[1] == package_b10 assert installs[1] == package_b10
assert installs[2] == package_a assert installs[2] == package_a
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
def test_run_install_duplicate_dependencies_different_constraints_with_lock( def test_run_install_duplicate_dependencies_different_constraints_with_lock(
installer, locker, repo, package installer: Installer, locker: Locker, repo: Repository, package: ProjectPack age
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
skipping to change at line 1233 skipping to change at line 1653
repo.add_package(package_c12) repo.add_package(package_c12)
repo.add_package(package_c15) repo.add_package(package_c15)
installer.update(True) installer.update(True)
installer.run() installer.run()
expected = fixture("with-duplicate-dependencies") expected = fixture("with-duplicate-dependencies")
assert locker.written_data == expected assert locker.written_data == expected
assert 3 == installer.executor.installations_count assert installer.executor.installations_count == 3
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
def test_run_update_uninstalls_after_removal_transient_dependency( def test_run_update_uninstalls_after_removal_transient_dependency(
installer, locker, repo, package, installed installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
skipping to change at line 1290 skipping to change at line 1714
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b10) repo.add_package(package_b10)
installed.add_package(get_package("A", "1.0")) installed.add_package(get_package("A", "1.0"))
installed.add_package(get_package("B", "1.0")) installed.add_package(get_package("B", "1.0"))
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 0 == installer.executor.installations_count assert installer.executor.installations_count == 0
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 1 == installer.executor.removals_count assert installer.executor.removals_count == 1
def test_run_install_duplicate_dependencies_different_constraints_with_lock_upda te( def test_run_install_duplicate_dependencies_different_constraints_with_lock_upda te(
installer, locker, repo, package, installed installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
skipping to change at line 1394 skipping to change at line 1822
installed.add_package(get_package("A", "1.0")) installed.add_package(get_package("A", "1.0"))
installer.update(True) installer.update(True)
installer.whitelist(["A"]) installer.whitelist(["A"])
installer.run() installer.run()
expected = fixture("with-duplicate-dependencies-update") expected = fixture("with-duplicate-dependencies-update")
assert locker.written_data == expected assert locker.written_data == expected
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
assert 1 == installer.executor.updates_count assert installer.executor.updates_count == 1
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
@pytest.mark.skip( @pytest.mark.skip(
"This is not working at the moment due to limitations in the resolver" "This is not working at the moment due to limitations in the resolver"
) )
def test_installer_test_solver_finds_compatible_package_for_dependency_python_no def test_installer_test_solver_finds_compatible_package_for_dependency_python_no
t_fully_compatible_with_package_python( t_fully_compatible_with_package_python( # noqa: E501
installer, locker, repo, package, installed installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
): ):
package.python_versions = "~2.7 || ^3.4" package.python_versions = "~2.7 || ^3.4"
package.add_dependency( package.add_dependency(
Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"}) Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"})
) )
package_a101 = get_package("A", "1.0.1") package_a101 = get_package("A", "1.0.1")
package_a101.python_versions = ">=3.6" package_a101.python_versions = ">=3.6"
package_a100 = get_package("A", "1.0.0") package_a100 = get_package("A", "1.0.0")
package_a100.python_versions = ">=3.5" package_a100.python_versions = ">=3.5"
repo.add_package(package_a100) repo.add_package(package_a100)
repo.add_package(package_a101) repo.add_package(package_a101)
installer.run() installer.run()
expected = fixture("with-conditional-dependency") expected = fixture("with-conditional-dependency")
assert locker.written_data == expected assert locker.written_data == expected
assert installer.executor.installations_count == 1
if sys.version_info >= (3, 5, 0): def test_installer_required_extras_should_not_be_removed_when_updating_single_de
assert 1 == installer.executor.installations_count pendency( # noqa: E501
else: installer: Installer,
assert 0 == installer.executor.installations_count locker: Locker,
repo: Repository,
def test_installer_required_extras_should_not_be_removed_when_updating_single_de package: ProjectPackage,
pendency( installed: CustomInstalledRepository,
installer, locker, repo, package, installed, env, pool, config env: NullEnv,
pool: Pool,
config: Config,
): ):
package.add_dependency(Factory.create_dependency("A", {"version": "^1.0"})) package.add_dependency(Factory.create_dependency("A", {"version": "^1.0"}))
package_a = get_package("A", "1.0.0") package_a = get_package("A", "1.0.0")
package_a.add_dependency( package_a.add_dependency(
Factory.create_dependency("B", {"version": "^1.0", "extras": ["foo"]}) Factory.create_dependency("B", {"version": "^1.0", "extras": ["foo"]})
) )
package_b = get_package("B", "1.0.0") package_b = get_package("B", "1.0.0")
package_b.add_dependency( package_b.add_dependency(
skipping to change at line 1455 skipping to change at line 1890
package_d = get_package("D", "1.0.0") package_d = get_package("D", "1.0.0")
repo.add_package(package_a) repo.add_package(package_a)
repo.add_package(package_b) repo.add_package(package_b)
repo.add_package(package_c) repo.add_package(package_c)
repo.add_package(package_d) repo.add_package(package_d)
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 3 == installer.executor.installations_count assert installer.executor.installations_count == 3
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
package.add_dependency(Factory.create_dependency("D", "^1.0")) package.add_dependency(Factory.create_dependency("D", "^1.0"))
locker.locked(True) locker.locked(True)
locker.mock_lock_data(locker.written_data) locker.mock_lock_data(locker.written_data)
installed.add_package(package_a) installed.add_package(package_a)
installed.add_package(package_b) installed.add_package(package_b)
installed.add_package(package_c) installed.add_package(package_c)
installer = Installer( installer = Installer(
skipping to change at line 1483 skipping to change at line 1918
config, config,
installed=installed, installed=installed,
executor=Executor(env, pool, config, NullIO()), executor=Executor(env, pool, config, NullIO()),
) )
installer.use_executor() installer.use_executor()
installer.update(True) installer.update(True)
installer.whitelist(["D"]) installer.whitelist(["D"])
installer.run() installer.run()
assert 1 == installer.executor.installations_count assert installer.executor.installations_count == 1
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
def test_installer_required_extras_should_not_be_removed_when_updating_single_de def test_installer_required_extras_should_not_be_removed_when_updating_single_de
pendency_pypi_repository( pendency_pypi_repository( # noqa: E501
locker, repo, package, installed, env, mocker, config locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
env: NullEnv,
mocker: MockerFixture,
config: Config,
): ):
mocker.patch("sys.platform", "darwin") mocker.patch("sys.platform", "darwin")
pool = Pool() pool = Pool()
pool.add_repository(MockRepository()) pool.add_repository(MockRepository())
installer = Installer( installer = Installer(
NullIO(), NullIO(),
env, env,
package, package,
skipping to change at line 1512 skipping to change at line 1953
installed=installed, installed=installed,
executor=Executor(env, pool, config, NullIO()), executor=Executor(env, pool, config, NullIO()),
) )
installer.use_executor() installer.use_executor()
package.add_dependency(Factory.create_dependency("poetry", {"version": "^0.1 2.0"})) package.add_dependency(Factory.create_dependency("poetry", {"version": "^0.1 2.0"}))
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 3 == installer.executor.installations_count assert installer.executor.installations_count == 3
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
package.add_dependency(Factory.create_dependency("pytest", "^3.5")) package.add_dependency(Factory.create_dependency("pytest", "^3.5"))
locker.locked(True) locker.locked(True)
locker.mock_lock_data(locker.written_data) locker.mock_lock_data(locker.written_data)
for pkg in installer.executor.installations: for pkg in installer.executor.installations:
installed.add_package(pkg) installed.add_package(pkg)
installer = Installer( installer = Installer(
skipping to change at line 1540 skipping to change at line 1981
config, config,
installed=installed, installed=installed,
executor=Executor(env, pool, config, NullIO()), executor=Executor(env, pool, config, NullIO()),
) )
installer.use_executor() installer.use_executor()
installer.update(True) installer.update(True)
installer.whitelist(["pytest"]) installer.whitelist(["pytest"])
installer.run() installer.run()
assert (6 if not PY2 else 7) == installer.executor.installations_count assert installer.executor.installations_count == 7
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
def test_installer_required_extras_should_be_installed( def test_installer_required_extras_should_be_installed(
locker, repo, package, installed, env, config locker: Locker,
repo: Repository,
package: ProjectPackage,
installed: CustomInstalledRepository,
env: NullEnv,
config: Config,
): ):
pool = Pool() pool = Pool()
pool.add_repository(MockRepository()) pool.add_repository(MockRepository())
installer = Installer( installer = Installer(
NullIO(), NullIO(),
env, env,
package, package,
locker, locker,
pool, pool,
skipping to change at line 1571 skipping to change at line 2017
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"cachecontrol", {"version": "^0.12.5", "extras": ["filecache"]} "cachecontrol", {"version": "^0.12.5", "extras": ["filecache"]}
) )
) )
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
locker.locked(True) locker.locked(True)
locker.mock_lock_data(locker.written_data) locker.mock_lock_data(locker.written_data)
installer = Installer( installer = Installer(
NullIO(), NullIO(),
env, env,
package, package,
locker, locker,
pool, pool,
config, config,
installed=installed, installed=installed,
executor=Executor(env, pool, config, NullIO()), executor=Executor(env, pool, config, NullIO()),
) )
installer.use_executor() installer.use_executor()
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
def test_update_multiple_times_with_split_dependencies_is_idempotent( def test_update_multiple_times_with_split_dependencies_is_idempotent(
installer, locker, repo, package installer: Installer, locker: Locker, repo: Repository, package: ProjectPack age
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "A", "name": "A",
"version": "1.0", "version": "1.0",
"category": "main", "category": "main",
"optional": False, "optional": False,
skipping to change at line 1659 skipping to change at line 2105
repo.add_package(a11) repo.add_package(a11)
repo.add_package(b101) repo.add_package(b101)
repo.add_package(b110) repo.add_package(b110)
repo.add_package(get_package("C", "1.0")) repo.add_package(get_package("C", "1.0"))
repo.add_package(get_package("C", "2.0")) repo.add_package(get_package("C", "2.0"))
expected = fixture("with-multiple-updates") expected = fixture("with-multiple-updates")
installer.update(True) installer.update(True)
installer.run() installer.run()
assert expected == locker.written_data assert locker.written_data == expected
locker.mock_lock_data(locker.written_data) locker.mock_lock_data(locker.written_data)
installer.update(True) installer.update(True)
installer.run() installer.run()
assert expected == locker.written_data assert locker.written_data == expected
locker.mock_lock_data(locker.written_data) locker.mock_lock_data(locker.written_data)
installer.update(True) installer.update(True)
installer.run() installer.run()
assert expected == locker.written_data assert locker.written_data == expected
def test_installer_can_install_dependencies_from_forced_source( def test_installer_can_install_dependencies_from_forced_source(
locker, package, installed, env, config locker: Locker,
package: Package,
installed: CustomInstalledRepository,
env: NullEnv,
config: Config,
): ):
package.python_versions = "^3.7" package.python_versions = "^3.7"
package.add_dependency( package.add_dependency(
Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "lega cy"}) Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "lega cy"})
) )
pool = Pool() pool = Pool()
pool.add_repository(MockLegacyRepository()) pool.add_repository(MockLegacyRepository())
pool.add_repository(MockRepository()) pool.add_repository(MockRepository())
skipping to change at line 1702 skipping to change at line 2152
pool, pool,
config, config,
installed=installed, installed=installed,
executor=Executor(env, pool, config, NullIO()), executor=Executor(env, pool, config, NullIO()),
) )
installer.use_executor() installer.use_executor()
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 1 == installer.executor.installations_count assert installer.executor.installations_count == 1
assert 0 == installer.executor.updates_count assert installer.executor.updates_count == 0
assert 0 == installer.executor.removals_count assert installer.executor.removals_count == 0
def test_run_installs_with_url_file(installer, locker, repo, package): def test_run_installs_with_url_file(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPack
age
):
url = "https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.w hl" url = "https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.w hl"
package.add_dependency(Factory.create_dependency("demo", {"url": url})) package.add_dependency(Factory.create_dependency("demo", {"url": url}))
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
installer.run() installer.run()
expected = fixture("with-url-dependency") expected = fixture("with-url-dependency")
assert locker.written_data == expected assert locker.written_data == expected
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
@pytest.mark.parametrize("env_platform", ["linux", "win32"])
def test_run_installs_with_same_version_url_files(
pool: Pool,
locker: Locker,
installed: CustomInstalledRepository,
config: Config,
repo: Repository,
package: ProjectPackage,
env_platform: str,
) -> None:
urls = {
"linux": "https://python-poetry.org/distributions/demo-0.1.0.tar.gz",
"win32": (
"https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any
.whl"
),
}
for platform, url in urls.items():
package.add_dependency(
Factory.create_dependency(
"demo",
{"url": url, "markers": f"sys_platform == '{platform}'"},
)
)
repo.add_package(get_package("pendulum", "1.4.4"))
installer = Installer(
NullIO(),
MockEnv(platform=env_platform),
package,
locker,
pool,
config,
installed=installed,
executor=Executor(
MockEnv(platform=env_platform),
pool,
config,
NullIO(),
),
)
installer.use_executor(True)
installer.run()
expected = fixture("with-same-version-url-dependencies")
assert locker.written_data == expected
assert installer.executor.installations_count == 2
demo_package = next(p for p in installer.executor.installations if p.name ==
"demo")
assert demo_package.source_url == urls[env_platform]
def test_installer_uses_prereleases_if_they_are_compatible( def test_installer_uses_prereleases_if_they_are_compatible(
installer, locker, package, repo installer: Installer, locker: Locker, package: ProjectPackage, repo: Reposit ory
): ):
package.python_versions = "~2.7 || ^3.4" package.python_versions = "~2.7 || ^3.4"
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"prerelease", {"git": "https://github.com/demo/prerelease.git"} "prerelease", {"git": "https://github.com/demo/prerelease.git"}
) )
) )
package_b = get_package("b", "2.0.0") package_b = get_package("b", "2.0.0")
package_b.add_dependency(Factory.create_dependency("prerelease", ">=0.19")) package_b.add_dependency(Factory.create_dependency("prerelease", ">=0.19"))
skipping to change at line 1747 skipping to change at line 2248
del installer.installer.installs[:] del installer.installer.installs[:]
locker.locked(True) locker.locked(True)
locker.mock_lock_data(locker.written_data) locker.mock_lock_data(locker.written_data)
package.add_dependency(Factory.create_dependency("b", "^2.0.0")) package.add_dependency(Factory.create_dependency("b", "^2.0.0"))
installer.whitelist(["b"]) installer.whitelist(["b"])
installer.update(True) installer.update(True)
installer.run() installer.run()
assert 2 == installer.executor.installations_count assert installer.executor.installations_count == 2
def test_installer_can_handle_old_lock_files( def test_installer_can_handle_old_lock_files(
installer, locker, package, repo, installed, config locker: Locker,
package: ProjectPackage,
repo: Repository,
installed: CustomInstalledRepository,
config: Config,
): ):
pool = Pool() pool = Pool()
pool.add_repository(MockRepository()) pool.add_repository(MockRepository())
package.add_dependency(Factory.create_dependency("pytest", "^3.5", category= "dev")) package.add_dependency(Factory.create_dependency("pytest", "^3.5", groups=[" dev"]))
locker.locked() locker.locked()
locker.mock_lock_data(fixture("old-lock")) locker.mock_lock_data(fixture("old-lock"))
installer = Installer( installer = Installer(
NullIO(), NullIO(),
MockEnv(), MockEnv(),
package, package,
locker, locker,
pool, pool,
config, config,
installed=installed, installed=installed,
executor=Executor(MockEnv(), pool, config, NullIO()), executor=Executor(MockEnv(), pool, config, NullIO()),
) )
installer.use_executor() installer.use_executor()
installer.run() installer.run()
assert 6 == installer.executor.installations_count assert installer.executor.installations_count == 6
installer = Installer( installer = Installer(
NullIO(), NullIO(),
MockEnv(version_info=(2, 7, 18)), MockEnv(version_info=(2, 7, 18)),
package, package,
locker, locker,
pool, pool,
config, config,
installed=installed, installed=installed,
executor=Executor(MockEnv(version_info=(2, 7, 18)), pool, config, NullIO executor=Executor(
(),), MockEnv(version_info=(2, 7, 18)),
pool,
config,
NullIO(),
),
) )
installer.use_executor() installer.use_executor()
installer.run() installer.run()
# funcsigs will be added # funcsigs will be added
assert 7 == installer.executor.installations_count assert installer.executor.installations_count == 7
installer = Installer( installer = Installer(
NullIO(), NullIO(),
MockEnv(version_info=(2, 7, 18), platform="win32"), MockEnv(version_info=(2, 7, 18), platform="win32"),
package, package,
locker, locker,
pool, pool,
config, config,
installed=installed, installed=installed,
executor=Executor( executor=Executor(
MockEnv(version_info=(2, 7, 18), platform="win32"), pool, config, Nu MockEnv(version_info=(2, 7, 18), platform="win32"),
llIO(), pool,
config,
NullIO(),
), ),
) )
installer.use_executor() installer.use_executor()
installer.run() installer.run()
# colorama will be added # colorama will be added
assert 8 == installer.executor.installations_count assert installer.executor.installations_count == 8
@pytest.mark.parametrize("quiet", [True, False])
def test_run_with_dependencies_quiet(
installer: Installer,
locker: Locker,
repo: Repository,
package: ProjectPackage,
quiet: bool,
):
package_a = get_package("A", "1.0")
package_b = get_package("B", "1.1")
repo.add_package(package_a)
repo.add_package(package_b)
installer._io = IO(Input(), BufferedOutput(), BufferedOutput())
installer._io.set_verbosity(Verbosity.QUIET if quiet else Verbosity.NORMAL)
package.add_dependency(Factory.create_dependency("A", "~1.0"))
package.add_dependency(Factory.create_dependency("B", "^1.0"))
installer.run()
expected = fixture("with-dependencies")
assert locker.written_data == expected
installer._io.output._buffer.seek(0)
if quiet:
assert installer._io.output._buffer.read() == ""
else:
assert installer._io.output._buffer.read() != ""
def test_installer_should_use_the_locked_version_of_git_dependencies( def test_installer_should_use_the_locked_version_of_git_dependencies(
installer, locker, package, repo installer: Installer, locker: Locker, package: ProjectPackage, repo: Reposit ory
): ):
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
"package": [ "package": [
{ {
"name": "demo", "name": "demo",
"version": "0.1.1", "version": "0.1.1",
"category": "main", "category": "main",
"optional": False, "optional": False,
skipping to change at line 1873 skipping to change at line 2416
installer.run() installer.run()
assert installer.executor.installations[-1] == Package( assert installer.executor.installations[-1] == Package(
"demo", "demo",
"0.1.1", "0.1.1",
source_type="git", source_type="git",
source_url="https://github.com/demo/demo.git", source_url="https://github.com/demo/demo.git",
source_reference="master", source_reference="master",
source_resolved_reference="123456", source_resolved_reference="123456",
) )
@pytest.mark.parametrize("is_locked", [False, True])
def test_installer_should_use_the_locked_version_of_git_dependencies_with_extras
(
installer: Installer,
locker: Locker,
package: ProjectPackage,
repo: Repository,
is_locked: bool,
):
if is_locked:
locker.locked(True)
locker.mock_lock_data(fixture("with-vcs-dependency-with-extras"))
expected_reference = "123456"
else:
expected_reference = MOCK_DEFAULT_GIT_REVISION
package.add_dependency(
Factory.create_dependency(
"demo",
{
"git": "https://github.com/demo/demo.git",
"branch": "master",
"extras": ["foo"],
},
)
)
repo.add_package(get_package("pendulum", "1.4.4"))
repo.add_package(get_package("cleo", "1.0.0"))
installer.run()
assert len(installer.executor.installations) == 3
assert installer.executor.installations[-1] == Package(
"demo",
"0.1.2",
source_type="git",
source_url="https://github.com/demo/demo.git",
source_reference="master",
source_resolved_reference=expected_reference,
)
@pytest.mark.parametrize("is_locked", [False, True])
def test_installer_should_use_the_locked_version_of_git_dependencies_without_ref
erence(
installer: Installer,
locker: Locker,
package: ProjectPackage,
repo: Repository,
is_locked: bool,
):
"""
If there is no explicit reference (branch or tag or rev) in pyproject.toml,
HEAD is used.
"""
if is_locked:
locker.locked(True)
locker.mock_lock_data(fixture("with-vcs-dependency-without-ref"))
expected_reference = "123456"
else:
expected_reference = MOCK_DEFAULT_GIT_REVISION
package.add_dependency(
Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.
git"})
)
repo.add_package(get_package("pendulum", "1.4.4"))
installer.run()
assert len(installer.executor.installations) == 2
assert installer.executor.installations[-1] == Package(
"demo",
"0.1.2",
source_type="git",
source_url="https://github.com/demo/demo.git",
source_reference="HEAD",
source_resolved_reference=expected_reference,
)
 End of changes. 152 change blocks. 
215 lines changed or deleted 777 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)