"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/installation/test_installer_old.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_old.py  (poetry-1.1.15):test_installer_old.py  (poetry-1.2.0)
from __future__ import unicode_literals from __future__ import annotations
import sys import itertools
import pytest from pathlib import Path
from typing import TYPE_CHECKING
from clikit.io import NullIO import pytest
from poetry.core.packages import ProjectPackage from cleo.io.null_io import NullIO
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.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 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.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 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 = data self._written_data = 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,
):
return Installer(NullIO(), env, package, locker, pool, config, installed=ins talled) return Installer(NullIO(), env, package, locker, pool, config, installed=ins talled)
def fixture(name): def fixture(name: str) -> str:
file = TOMLFile(Path(__file__).parent / "fixtures" / "{}.test".format(name)) file = TOMLFile(Path(__file__).parent / "fixtures" / f"{name}.test")
return file.read() return 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 219 skipping to change at line 235
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 0 assert len(installs) == 0
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 0 assert len(updates) == 0
removals = installer.installer.removals removals = installer.installer.removals
assert len(removals) == 1 assert len(removals) == 1
def test_run_install_no_dev(installer, locker, repo, package, installed): def test_run_install_no_group(
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 273 skipping to change at line 295
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) 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)
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" )) package.add_dependency(Factory.create_dependency("C", "~1.2", groups=["dev"] ))
installer.dev_mode(False) installer.only_groups([])
installer.run() installer.run()
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 0 assert len(installs) == 0
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 0 assert len(updates) == 0
removals = installer.installer.removals removals = installer.installer.removals
assert len(removals) == 1 assert len(removals) == 0
@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")
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))
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": pkg.name,
"version": "1.0", "version": pkg.version,
"category": "main", "category": "main",
"optional": False, "optional": False,
"platform": "*", "platform": "*",
"python-versions": "*", "python-versions": "*",
"checksum": [], "checksum": [],
} }
for pkg in locked_packages
], ],
"metadata": { "metadata": {
"python-versions": "*", "python-versions": "*",
"platform": "*", "platform": "*",
"content-hash": "123456789", "content-hash": "123456789",
"hashes": {"a": []}, "hashes": {pkg.name: [] for pkg in locked_packages},
}, },
} }
) )
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")
repo.add_package(package_a)
repo.add_package(package_b)
repo.add_package(package_c)
repo.add_package(package_pip)
installed.add_package(package_a) installer.requires_synchronization(True)
installed.add_package(package_b)
installed.add_package(package_c)
installed.add_package(package_pip) # Always required and never removed.
installed.add_package(package) # Root package never removed.
package.add_dependency(Factory.create_dependency("A", "~1.0"))
installer.dev_mode(True).remove_untracked(True)
installer.run() installer.run()
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 0 assert len(installs) == 0
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 0 assert len(updates) == 0
removals = installer.installer.removals removals = installer.installer.removals
assert set(r.name for r in removals) == {"b", "c"}
def test_run_whitelist_add(installer, locker, repo, package): expected_removals = {
package_b.name,
package_c.name,
*managed_reserved_package_names,
}
assert {r.name for r in 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 380 skipping to change at line 440
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 431 skipping to change at line 497
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 len(installer.installer.installs) == 1 assert len(installer.installer.installs) == 1
assert len(installer.installer.updates) == 0 assert len(installer.installer.updates) == 0
assert len(installer.installer.removals) == 1 assert len(installer.installer.removals) == 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 477 skipping to change at line 547
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 519 skipping to change at line 589
installer = installer.installer installer = installer.installer
# 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 len(installer.installs) == 2 assert len(installer.installs) == 2
assert installer.installs[0].name == "d" assert installer.installs[0].name == "d"
assert installer.installs[1].name == "c" assert installer.installs[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 560 skipping to change at line 634
assert locker.written_data == expected assert locker.written_data == expected
installer = installer.installer installer = installer.installer
# 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 len(installer.installs) == 2 assert len(installer.installs) == 2
assert installer.installs[0].name == "d" assert installer.installs[0].name == "d"
assert installer.installs[1].name == "c" assert installer.installs[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 584 skipping to change at line 660
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_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 613 skipping to change at line 691
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
installer = installer.installer installer = installer.installer
assert len(installer.installs) == 3 # A, B, C assert len(installer.installs) == 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 643 skipping to change at line 723
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
installer = installer.installer installer = installer.installer
assert len(installer.installs) == 4 # A, B, C, D assert len(installer.installs) == 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 675 skipping to change at line 757
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
installer = installer.installer installer = installer.installer
assert len(installer.installs) == 4 # A, B, C, D assert len(installer.installs) == 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 705 skipping to change at line 787
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
installer = installer.installer installer = installer.installer
assert len(installer.installs) == 4 # A, B, C, D assert len(installer.installs) == 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,
):
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 ath)})) package.add_dependency(Factory.create_dependency("demo", {"file": str(file_p ath)}))
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 len(installer.installer.installs) == 2 assert len(installer.installer.installs) == 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,
): ):
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 ath)})) package.add_dependency(Factory.create_dependency("demo", {"file": str(file_p ath)}))
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 len(installer.installer.installs) == 1 assert len(installer.installer.installs) == 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,
): ):
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), "extras": ["extras_a "]}
) )
) )
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 len(installer.installer.installs) == 2 assert len(installer.installer.installs) == 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 797 skipping to change at line 904
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 len(installer.installer.installs) == 6 assert len(installer.installer.installs) == 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: 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_file_dependencies") directory = root_dir.joinpath("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",
{"path": str(directory.relative_to(fixture_dir("directory")))}, {"path": str(directory.relative_to(fixture_dir("directory")))},
root_dir=root_dir, root_dir=root_dir,
skipping to change at line 823 skipping to change at line 935
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 len(installer.installer.installs) == 4 assert len(installer.installer.installs) == 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,
): ):
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)} )
) )
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 len(installer.installer.installs) == 3 assert len(installer.installer.installs) == 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 882 skipping to change at line 1001
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 913 skipping to change at line 1034
} }
) )
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 962 skipping to change at line 1085
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 1011 skipping to change at line 1136
"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 1077 skipping to change at line 1202
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
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 0 assert len(updates) == 0
removals = installer.installer.removals removals = installer.installer.removals
assert len(removals) == 0 assert len(removals) == 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 1186 skipping to change at line 1311
assert locker.written_data == expected assert locker.written_data == expected
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 3 assert len(installs) == 3
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 0 assert len(updates) == 0
removals = installer.installer.removals removals = installer.installer.removals
assert len(removals) == 0 assert len(removals) == 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 1246 skipping to change at line 1375
installer.run() installer.run()
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 0 assert len(installs) == 0
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 0 assert len(updates) == 0
removals = installer.installer.removals removals = installer.installer.removals
assert len(removals) == 1 assert len(removals) == 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 1355 skipping to change at line 1488
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 2 assert len(installs) == 2
updates = installer.installer.updates updates = installer.installer.updates
assert len(updates) == 1 assert len(updates) == 1
removals = installer.installer.removals removals = installer.installer.removals
assert len(removals) == 0 assert len(removals) == 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")
skipping to change at line 1378 skipping to change at line 1515
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
installs = installer.installer.installs installs = installer.installer.installs
assert len(installs) == 1
if sys.version_info >= (3, 5, 0): def test_installer_required_extras_should_not_be_removed_when_updating_single_de
assert len(installs) == 1 pendency( # noqa: E501
else: installer: Installer,
assert len(installs) == 0 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 1435 skipping to change at line 1575
) )
installer.update(True) installer.update(True)
installer.whitelist(["D"]) installer.whitelist(["D"])
installer.run() installer.run()
assert len(installer.installer.installs) == 1 assert len(installer.installer.installs) == 1
assert len(installer.installer.updates) == 0 assert len(installer.installer.updates) == 0
assert len(installer.installer.removals) == 0 assert len(installer.installer.removals) == 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(), env, package, locker, pool, config, installed=installed NullIO(), env, package, locker, pool, config, installed=installed
) )
skipping to change at line 1472 skipping to change at line 1618
installed.add_package(pkg) installed.add_package(pkg)
installer = Installer( installer = Installer(
NullIO(), env, package, locker, pool, config, installed=installed NullIO(), env, package, locker, pool, config, installed=installed
) )
installer.update(True) installer.update(True)
installer.whitelist(["pytest"]) installer.whitelist(["pytest"])
installer.run() installer.run()
assert len(installer.installer.installs) == 6 if not PY2 else 7 assert len(installer.installer.installs) == 7
assert len(installer.installer.updates) == 0 assert len(installer.installer.updates) == 0
assert len(installer.installer.removals) == 0 assert len(installer.installer.removals) == 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(), env, package, locker, pool, config, installed=installed NullIO(), env, package, locker, pool, config, installed=installed
) )
package.add_dependency( package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
skipping to change at line 1514 skipping to change at line 1665
) )
installer.update(True) installer.update(True)
installer.run() installer.run()
assert len(installer.installer.installs) == 2 assert len(installer.installer.installs) == 2
assert len(installer.installer.updates) == 0 assert len(installer.installer.updates) == 0
assert len(installer.installer.removals) == 0 assert len(installer.installer.removals) == 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 1575 skipping to change at line 1726
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: ProjectPackage,
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 1614 skipping to change at line 1769
NullIO(), env, package, locker, pool, config, installed=installed NullIO(), env, package, locker, pool, config, installed=installed
) )
installer.update(True) installer.update(True)
installer.run() installer.run()
assert len(installer.installer.installs) == 1 assert len(installer.installer.installs) == 1
assert len(installer.installer.updates) == 0 assert len(installer.installer.updates) == 0
assert len(installer.installer.removals) == 0 assert len(installer.installer.removals) == 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 len(installer.installer.installs) == 2 assert len(installer.installer.installs) == 2
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 1658 skipping to change at line 1815
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 len(installer.installer.installs) == 2 assert len(installer.installer.installs) == 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(), MockEnv(), package, locker, pool, config, installed=installed NullIO(), MockEnv(), package, locker, pool, config, installed=installed
) )
installer.run() installer.run()
assert 6 == len(installer.installer.installs) assert len(installer.installer.installs) == 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,
) )
installer.run() installer.run()
# funcsigs will be added # funcsigs will be added
assert 7 == len(installer.installer.installs) assert len(installer.installer.installs) == 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,
) )
installer.run() installer.run()
# colorama will be added # colorama will be added
assert 8 == len(installer.installer.installs) assert len(installer.installer.installs) == 8
 End of changes. 90 change blocks. 
129 lines changed or deleted 302 lines changed or added

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