Skip to content

Commit 27d8daa

Browse files
committed
refactor: plural does more
1 parent a2f248c commit 27d8daa

5 files changed

Lines changed: 12 additions & 13 deletions

File tree

coverage/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ def debug_data_file(filename: str) -> None:
241241
summary = line_counts(data, fullpath=True)
242242
filenames = human_sorted(summary.keys())
243243
nfiles = len(filenames)
244-
print(f"{nfiles} file{plural(nfiles)}:")
244+
print(f"{plural(nfiles, 'file')}:")
245245
for f in filenames:
246-
line = f"{f}: {summary[f]} line{plural(summary[f])}"
246+
line = f"{f}: {plural(summary[f], 'line')}"
247247
plugin = data.file_tracer(f)
248248
if plugin:
249249
line += f" [{plugin}]"

coverage/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __init__(self, strs: list[str], name: str, caption: str, debug: DebugFn) ->
231231

232232
def __str__(self) -> str:
233233
n = len(self.strs)
234-
return f"{self.__class__.__name__} {self.name!r} {n} {plural(n, 'item')}"
234+
return f"{self.__class__.__name__} {self.name!r} {plural(n, 'item')}"
235235

236236
def __repr__(self) -> str:
237237
return f"<{self.__class__.__name__} {self.name} {self.strs!r}>"

coverage/html.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,11 @@ def write_index_page(self, index_page: IndexPage, **kwargs: str) -> str:
638638
"""
639639
skipped_covered_msg = skipped_empty_msg = ""
640640
if n := index_page.skipped_covered_count:
641-
word = plural(n, index_page.noun, index_page.plural)
642-
skipped_covered_msg = f"{n} {word} skipped due to complete coverage."
641+
things = plural(n, index_page.noun, index_page.plural)
642+
skipped_covered_msg = f"{things} skipped due to complete coverage."
643643
if n := index_page.skipped_empty_count:
644-
word = plural(n, index_page.noun, index_page.plural)
645-
skipped_empty_msg = f"{n} empty {word} skipped."
644+
things = plural(n, "empty " + index_page.noun, "empty " + index_page.plural)
645+
skipped_empty_msg = f"{things} skipped."
646646

647647
index_buttons = [
648648
{

coverage/misc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,10 @@ def plural(n: int, thing: str = "", things: str = "") -> str:
364364
If n is 1, return thing. Otherwise return things, or thing+s.
365365
"""
366366
if n == 1:
367-
return thing
367+
noun = thing
368368
else:
369-
return things or (thing + "s")
369+
noun = things or (thing + "s")
370+
return f"{n} {noun}"
370371

371372

372373
def stdout_link(text: str, url: str) -> str:

coverage/report.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,11 @@ def tabular_report(self) -> None:
267267
# Create other final lines.
268268
end_lines = []
269269
if self.config.skip_covered and self.skipped_count:
270-
files = plural(self.skipped_count, "file")
271270
end_lines.append(
272-
f"\n{self.skipped_count} {files} skipped due to complete coverage.",
271+
f"\n{plural(self.skipped_count, 'file')} skipped due to complete coverage.",
273272
)
274273
if self.config.skip_empty and self.empty_count:
275-
files = plural(self.empty_count, "file")
276-
end_lines.append(f"\n{self.empty_count} empty {files} skipped.")
274+
end_lines.append(f"\n{plural(self.empty_count, 'empty file')} skipped.")
277275

278276
if self.output_format == "markdown":
279277
formatter = self.report_markdown

0 commit comments

Comments
 (0)