Skip to content

Commit

Permalink
Incorporating suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
samypr100 committed Jun 4, 2023
1 parent e0fab00 commit 6125b6a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ poetry check

### Options

* `--lock`: Verify that `poetry.lock` is consistent with `pyproject.toml`.
* `--lock`: Verifies that `poetry.lock` exists for the current `pyproject.toml`.

## search

Expand Down
23 changes: 10 additions & 13 deletions src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CheckCommand(Command):
"lock",
None,
(
"Check that the <comment>poetry.lock</> file corresponds to the current"
"Checks that <comment>poetry.lock</> exists for the current"
" version of <comment>pyproject.toml</>."
),
),
Expand Down Expand Up @@ -74,18 +74,6 @@ def validate_classifiers(
return errors, warnings

def handle(self) -> int:
if self.option("lock"):
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh():
self.line("poetry.lock is consistent with pyproject.toml.")
return 0
self.line_error(
"<error>"
"Error: poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it."
"</error>"
)
return 1

from poetry.factory import Factory
from poetry.pyproject.toml import PyProjectTOML

Expand All @@ -100,6 +88,15 @@ def handle(self) -> int:
check_result["errors"].extend(errors)
check_result["warnings"].extend(warnings)

# Verify that lock file is consistent
if self.option("lock") and not self.poetry.locker.is_locked():
check_result["errors"] += ["poetry.lock was not found."]
if self.poetry.locker.is_locked() and not self.poetry.locker.is_fresh():
check_result["errors"] += [
"poetry.lock is not consistent with pyproject.toml. Run `poetry"
" lock [--no-update]` to fix it."
]

if not check_result["errors"] and not check_result["warnings"]:
self.info("All set!")

Expand Down
9 changes: 5 additions & 4 deletions tests/console/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ def test_check_invalid(
new_callable=mocker.PropertyMock,
)

tester.execute()
tester.execute("--lock")

expected = """\
Error: 'description' is a required property
Error: Project name (invalid) is same as one of its dependencies
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
Error: poetry.lock was not found.
Warning: A wildcard Python dependency is ambiguous.\
Consider specifying a more explicit one.
Warning: The "pendulum" dependency specifies the "allows-prereleases" property,\
Expand Down Expand Up @@ -112,7 +113,7 @@ def test_check_private(
assert tester.io.fetch_output() == expected


def test_lock_check_outdated(
def test_check_lock_outdated(
command_tester_factory: CommandTesterFactory,
poetry_with_outdated_lockfile: Poetry,
http: type[httpretty.httpretty],
Expand All @@ -138,7 +139,7 @@ def test_lock_check_outdated(
assert status_code == 1


def test_lock_check_up_to_date(
def test_check_lock_up_to_date(
command_tester_factory: CommandTesterFactory,
poetry_with_up_to_date_lockfile: Poetry,
http: type[httpretty.httpretty],
Expand All @@ -153,7 +154,7 @@ def test_lock_check_up_to_date(

tester = command_tester_factory("check", poetry=poetry_with_up_to_date_lockfile)
status_code = tester.execute("--lock")
expected = "poetry.lock is consistent with pyproject.toml.\n"
expected = "All set!\n"
assert tester.io.fetch_output() == expected

# exit with an error
Expand Down

0 comments on commit 6125b6a

Please sign in to comment.