"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/console/commands/test_lock.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_lock.py  (poetry-1.1.15):test_lock.py  (poetry-1.2.0)
import shutil from __future__ import annotations
import sys
from pathlib import Path
from typing import TYPE_CHECKING
import pytest import pytest
from poetry.factory import Factory
from poetry.packages import Locker from poetry.packages import Locker
from poetry.utils._compat import Path from tests.helpers import get_package
if TYPE_CHECKING:
import httpretty
from cleo.testers.command_tester import CommandTester
from poetry.poetry import Poetry
from tests.helpers import TestRepository
from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
from tests.types import ProjectFactory
@pytest.fixture @pytest.fixture
def source_dir(tmp_path): # type: (Path) -> Path def source_dir(tmp_path: Path) -> Path:
yield Path(tmp_path.as_posix()) return Path(tmp_path.as_posix())
@pytest.fixture @pytest.fixture
def tester(command_tester_factory): def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("lock") return command_tester_factory("lock")
def _project_factory(
fixture_name: str,
project_factory: ProjectFactory,
fixture_dir: FixtureDirGetter,
) -> Poetry:
source = fixture_dir(fixture_name)
pyproject_content = (source / "pyproject.toml").read_text(encoding="utf-8")
poetry_lock_content = (source / "poetry.lock").read_text(encoding="utf-8")
return project_factory(
name="foobar",
pyproject_content=pyproject_content,
poetry_lock_content=poetry_lock_content,
)
@pytest.fixture @pytest.fixture
def poetry_with_old_lockfile(fixture_dir, source_dir): def poetry_with_outdated_lockfile(
project_dir = source_dir / "project" project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
shutil.copytree(str(fixture_dir("old_lock")), str(project_dir)) ) -> Poetry:
poetry = Factory().create_poetry(cwd=project_dir) return _project_factory("outdated_lock", project_factory, fixture_dir)
return poetry
@pytest.fixture
@pytest.mark.skipif( def poetry_with_up_to_date_lockfile(
sys.platform == "win32", reason="does not work on windows under ci environme project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
nts" ) -> Poetry:
) return _project_factory("up_to_date_lock", project_factory, fixture_dir)
def test_lock_no_update(command_tester_factory, poetry_with_old_lockfile, http):
@pytest.fixture
def poetry_with_old_lockfile(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
) -> Poetry:
return _project_factory("old_lock", project_factory, fixture_dir)
def test_lock_check_outdated(
command_tester_factory: CommandTesterFactory,
poetry_with_outdated_lockfile: Poetry,
http: type[httpretty.httpretty],
):
http.disable()
locker = Locker(
lock=poetry_with_outdated_lockfile.pyproject.file.path.parent / "poetry.
lock",
local_config=poetry_with_outdated_lockfile.locker._local_config,
)
poetry_with_outdated_lockfile.set_locker(locker)
tester = command_tester_factory("lock", poetry=poetry_with_outdated_lockfile
)
status_code = tester.execute("--check")
expected = (
"Error: poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it.\n"
)
assert tester.io.fetch_error() == expected
# exit with an error
assert status_code == 1
def test_lock_check_up_to_date(
command_tester_factory: CommandTesterFactory,
poetry_with_up_to_date_lockfile: Poetry,
http: type[httpretty.httpretty],
):
http.disable() http.disable()
locked_repository = poetry_with_old_lockfile.locker.locked_repository( locker = Locker(
with_dev_reqs=True lock=poetry_with_up_to_date_lockfile.pyproject.file.path.parent / "poetr
y.lock",
local_config=poetry_with_up_to_date_lockfile.locker._local_config,
) )
poetry_with_up_to_date_lockfile.set_locker(locker)
tester = command_tester_factory("lock", poetry=poetry_with_up_to_date_lockfi
le)
status_code = tester.execute("--check")
expected = "poetry.lock is consistent with pyproject.toml.\n"
assert tester.io.fetch_output() == expected
# exit with an error
assert status_code == 0
def test_lock_no_update(
command_tester_factory: CommandTesterFactory,
poetry_with_old_lockfile: Poetry,
repo: TestRepository,
):
repo.add_package(get_package("sampleproject", "1.3.1"))
repo.add_package(get_package("sampleproject", "2.0.0"))
locker = Locker(
lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock"
,
local_config=poetry_with_old_lockfile.locker._local_config,
)
poetry_with_old_lockfile.set_locker(locker)
locked_repository = poetry_with_old_lockfile.locker.locked_repository()
assert ( assert (
poetry_with_old_lockfile.locker.lock_data["metadata"].get("lock-version" ) poetry_with_old_lockfile.locker.lock_data["metadata"].get("lock-version" )
== "1.0" == "1.0"
) )
tester = command_tester_factory("lock", poetry=poetry_with_old_lockfile) tester = command_tester_factory("lock", poetry=poetry_with_old_lockfile)
tester.execute("--no-update") tester.execute("--no-update")
locker = Locker( locker = Locker(
lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock" , lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock" ,
local_config={}, local_config={},
) )
packages = locker.locked_repository(True).packages packages = locker.locked_repository().packages
assert len(packages) == len(locked_repository.packages) assert len(packages) == len(locked_repository.packages)
assert locker.lock_data["metadata"].get("lock-version") == "1.1" assert locker.lock_data["metadata"].get("lock-version") == "1.1"
for package in packages: for package in packages:
assert locked_repository.find_packages(package.to_dependency()) assert locked_repository.find_packages(package.to_dependency())
 End of changes. 10 change blocks. 
21 lines changed or deleted 114 lines changed or added

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