Skip to content
Open
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
7 changes: 3 additions & 4 deletions bowtie/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
NoSuchImage,
StartupFailed,
)
from bowtie._utils import pluralize
from bowtie.exceptions import (
_ProtocolError, # type: ignore[reportPrivateUsage]
)
Expand Down Expand Up @@ -207,14 +208,13 @@ def _failure_table(
summary: _report._Summary, # type: ignore[reportPrivateUsage]
results: list[tuple[tuple[str, str], _report.Count]],
):
test = "tests" if summary.total_tests != 1 else "test"
table = Table(
"Implementation",
"Skips",
"Errors",
"Failures",
title="Bowtie",
caption=f"{summary.total_tests} {test} ran\n",
caption=f"{pluralize(summary.total_tests, 'test')} ran\n",
)
for (implementation, language), counts in results:
table.add_row(
Expand Down Expand Up @@ -252,12 +252,11 @@ def _validation_results_table(
summary: _report._Summary, # type: ignore[reportPrivateUsage]
results: Iterable[tuple[Any, Iterable[tuple[Any, dict[str, str]]]]],
):
test = "tests" if summary.total_tests != 1 else "test"
table = Table(
Column(header="Schema", vertical="middle"),
"",
title="Bowtie",
caption=f"{summary.total_tests} {test} ran",
caption=f"{pluralize(summary.total_tests, 'test')} ran",
)

for schema, case_results in results:
Expand Down
22 changes: 22 additions & 0 deletions bowtie/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Small, generic helpers shared across Bowtie's modules.
"""
from __future__ import annotations


def pluralize(count: int, noun: str, plural: str | None = None) -> str:
"""
Combine a count with the singular or plural form of a noun.

>>> pluralize(1, "test")
'1 test'
>>> pluralize(0, "test")
'0 tests'
>>> pluralize(2, "test")
'2 tests'
>>> pluralize(2, "story", plural="stories")
'2 stories'
"""
plural = plural or f"{noun}s"
word = noun if count == 1 else plural
return f"{count} {word}"
25 changes: 25 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from bowtie._utils import pluralize


def test_pluralize_singular():
assert pluralize(1, "test") == "1 test"


def test_pluralize_plural():
assert pluralize(2, "test") == "2 tests"


def test_pluralize_zero():
assert pluralize(0, "test") == "0 tests"


def test_pluralize_negative():
assert pluralize(-1, "test") == "-1 tests"


def test_pluralize_custom_plural():
assert pluralize(2, "story", plural="stories") == "2 stories"


def test_pluralize_custom_plural_singular_unaffected():
assert pluralize(1, "story", plural="stories") == "1 story"
Loading