Skip to content

Commit

Permalink
Use package.pretty_name in poetry version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit-K committed Jan 4, 2024
1 parent 022308e commit 55b2d8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/console/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def handle(self) -> int:
self.line(self.poetry.package.pretty_version)
else:
self.line(
f"<comment>{self.poetry.package.name}</>"
f"<comment>{self.poetry.package.pretty_name}</>"
f" <info>{self.poetry.package.pretty_version}</>"
)

Expand Down
23 changes: 23 additions & 0 deletions tests/console/commands/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester

from poetry.poetry import Poetry
from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
from tests.types import ProjectFactory


@pytest.fixture()
Expand All @@ -23,6 +26,18 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("version")


@pytest.fixture
def poetry_with_underscore(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
) -> Poetry:
source = fixture_dir("simple_project")
pyproject_content = (source / "pyproject.toml").read_text(encoding="utf-8")
pyproject_content = pyproject_content.replace("simple-project", "simple_project")
return project_factory(
"project_with_underscore", pyproject_content=pyproject_content
)


@pytest.mark.parametrize(
"version, rule, expected",
[
Expand Down Expand Up @@ -79,6 +94,14 @@ def test_version_show(tester: CommandTester) -> None:
assert tester.io.fetch_output() == "simple-project 1.2.3\n"


def test_version_show_with_underscore(
command_tester_factory: CommandTesterFactory, poetry_with_underscore: Poetry
) -> None:
tester = command_tester_factory("version", poetry=poetry_with_underscore)
tester.execute()
assert tester.io.fetch_output() == "simple_project 1.2.3\n"


def test_short_version_show(tester: CommandTester) -> None:
tester.execute("--short")
assert tester.io.fetch_output() == "1.2.3\n"
Expand Down

0 comments on commit 55b2d8b

Please sign in to comment.