Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ poetry self show
* `--tree`: List the dependencies as a tree.
* `--latest (-l)`: Show the latest version.
* `--outdated (-o)`: Show the latest version but only for packages that are outdated.
* `--format (-f)`: Specify the output format (`json` or `text`). Default is `text`. `json` cannot be combined with the `--tree` option.

### self show plugins

Expand Down
6 changes: 5 additions & 1 deletion src/poetry/console/commands/self/show/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class SelfShowCommand(SelfCommand, ShowCommand):
name = "self show"
options: ClassVar[list[Option]] = [
option("addons", None, "List only add-on packages installed."),
*[o for o in ShowCommand.options if o.name in {"tree", "latest", "outdated"}],
*[
o
for o in ShowCommand.options
if o.name in {"tree", "latest", "outdated", "format"}
],
]
description = "Show packages from Poetry's runtime environment."
help = f"""\
Expand Down
72 changes: 72 additions & 0 deletions tests/console/commands/self/test_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from __future__ import annotations

import json

from typing import TYPE_CHECKING

import pytest
import tomlkit

from poetry.__version__ import __version__
from poetry.console.commands.self.self_command import SelfCommand


if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester

from tests.types import CommandTesterFactory


@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("self show")


@pytest.mark.parametrize("options", ["", "--format json", "--format text"])
def test_show_format(tester: CommandTester, options: str) -> None:
pyproject_content = {
"tool": {
"poetry": {
"name": "poetry-instance",
"version": __version__,
"dependencies": {"python": "^3.9", "poetry": __version__},
}
}
}
lock_content = {
"package": [
{
"name": "poetry",
"version": __version__,
"optional": False,
"platform": "*",
"python-versions": "*",
"files": [],
},
],
"metadata": {
"lock-version": "2.0",
"python-versions": "^3.9",
"content-hash": "123456789",
},
}
if "json" in options:
expected = json.dumps(
[
{
"name": "poetry",
"installed_status": "installed",
"version": __version__,
"description": "",
}
]
)
else:
expected = f"poetry {__version__}"
system_pyproject_file = SelfCommand.get_default_system_pyproject_file()
system_pyproject_file.write_text(tomlkit.dumps(pyproject_content), encoding="utf-8")
system_pyproject_file.parent.joinpath("poetry.lock").write_text(
tomlkit.dumps(lock_content), encoding="utf-8"
)
assert tester.execute(options) == 0
assert tester.io.fetch_output().strip() == expected