Skip to content

Commit

Permalink
add test to verify lock is changed on install failure
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnerluis1982 committed Feb 11, 2023
1 parent 8558f0c commit 3e67146
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,25 @@

@pytest.fixture
def poetry_with_up_to_date_lockfile(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
project_factory: ProjectFactory,
fixture_dir: FixtureDirGetter,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
) -> Poetry:
source = fixture_dir("up_to_date_lock")

return project_factory(
poetry = project_factory(
name="foobar",
pyproject_content=(source / "pyproject.toml").read_text(encoding="utf-8"),
poetry_lock_content=(source / "poetry.lock").read_text(encoding="utf-8"),
)

# ensure poetry.lock with updated syntax
repo.add_package(get_package("docker", "4.3.1"))
command_tester_factory("lock", poetry=poetry).execute()

return poetry


@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
Expand Down Expand Up @@ -2199,3 +2208,23 @@ def test_add_with_dry_run_keep_files_intact(
assert (
poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content
)


def test_add_should_not_change_lock_file_when_dependency_installation_fail(
poetry_with_up_to_date_lockfile: Poetry,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
mocker: MockerFixture,
):
tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile)

repo.add_package(get_package("cachy", "0.2.0"))

original_pyproject_content = poetry_with_up_to_date_lockfile.file.read()
original_lockfile_content = poetry_with_up_to_date_lockfile.locker.lock_data

mocker.patch("poetry.installation.installer.Installer._execute", return_value=1)
tester.execute("cachy")

assert poetry_with_up_to_date_lockfile.file.read() == original_pyproject_content
assert poetry_with_up_to_date_lockfile.locker.lock_data == original_lockfile_content

0 comments on commit 3e67146

Please sign in to comment.