-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure --dry-run
option doesn't update poetry.lock
for add
, update
and remove
#5718
Merged
neersighted
merged 3 commits into
python-poetry:master
from
mkniewallner:fix-dry-run-option-add-update-remove
May 29, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,21 @@ | |
from tests.helpers import PoetryTestApplication | ||
from tests.helpers import TestRepository | ||
from tests.types import CommandTesterFactory | ||
from tests.types import FixtureDirGetter | ||
from tests.types import ProjectFactory | ||
|
||
|
||
@pytest.fixture | ||
def poetry_with_up_to_date_lockfile( | ||
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter | ||
) -> Poetry: | ||
source = fixture_dir("up_to_date_lock") | ||
|
||
return 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"), | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
|
@@ -1999,34 +2014,54 @@ def test_add_with_lock_old_installer( | |
|
||
|
||
def test_add_keyboard_interrupt_restore_content( | ||
app: PoetryTestApplication, | ||
poetry_with_up_to_date_lockfile: Poetry, | ||
repo: TestRepository, | ||
installer: NoopInstaller, | ||
tester: CommandTester, | ||
command_tester_factory: CommandTesterFactory, | ||
mocker: MockerFixture, | ||
): | ||
tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) | ||
|
||
mocker.patch( | ||
"poetry.installation.installer.Installer.run", side_effect=KeyboardInterrupt() | ||
) | ||
original_content = app.poetry.file.read() | ||
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read() | ||
original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data | ||
|
||
repo.add_package(get_package("cachy", "0.2.0")) | ||
repo.add_package(get_package("docker", "4.3.1")) | ||
|
||
tester.execute("cachy --dry-run") | ||
tester.execute("cachy") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the test here because since we're testing a keyboard interrupt, it may be nice to test that the non-dry-run variant prevents updates on the files. |
||
|
||
assert original_content == app.poetry.file.read() | ||
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 | ||
) | ||
|
||
|
||
def test_dry_run_restore_original_content( | ||
app: PoetryTestApplication, | ||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
"cachy --dry-run", | ||
"cachy --lock --dry-run", | ||
], | ||
) | ||
def test_add_with_dry_run_keep_files_intact( | ||
command: str, | ||
poetry_with_up_to_date_lockfile: Poetry, | ||
repo: TestRepository, | ||
installer: NoopInstaller, | ||
tester: CommandTester, | ||
command_tester_factory: CommandTesterFactory, | ||
): | ||
original_content = app.poetry.file.read() | ||
tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile) | ||
|
||
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read() | ||
original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data | ||
|
||
repo.add_package(get_package("cachy", "0.2.0")) | ||
repo.add_package(get_package("docker", "4.3.1")) | ||
|
||
tester.execute("cachy --dry-run") | ||
tester.execute(command) | ||
|
||
assert original_content == app.poetry.file.read() | ||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from tests.helpers import get_package | ||
|
||
|
||
if TYPE_CHECKING: | ||
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 | ||
def poetry_with_up_to_date_lockfile( | ||
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter | ||
) -> Poetry: | ||
source = fixture_dir("outdated_lock") | ||
|
||
return 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"), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
"--dry-run", | ||
"docker --dry-run", | ||
], | ||
) | ||
def test_update_with_dry_run_keep_files_intact( | ||
command: str, | ||
poetry_with_up_to_date_lockfile: Poetry, | ||
repo: TestRepository, | ||
command_tester_factory: CommandTesterFactory, | ||
): | ||
tester = command_tester_factory("update", poetry=poetry_with_up_to_date_lockfile) | ||
|
||
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read() | ||
original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data | ||
|
||
repo.add_package(get_package("docker", "4.3.0")) | ||
repo.add_package(get_package("docker", "4.3.1")) | ||
|
||
tester.execute(command) | ||
|
||
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 | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a suggestion from @radoering here, and looking at the usage of the method, it does seem that the only place where we use
force
leaves_write_lock
toTrue
, so this seems to make sense.