-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: Pluralize as "1.5 seconds" instead of "1.5 second" (#43)
- Loading branch information
Showing
2 changed files
with
5 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# Tests for the `humanfriendly' package. | ||
# | ||
# Author: Peter Odding <[email protected]> | ||
# Last Change: April 19, 2020 | ||
# Last Change: November 30, 2020 | ||
# URL: https://humanfriendly.readthedocs.io | ||
|
||
"""Test suite for the `humanfriendly` package.""" | ||
|
@@ -441,7 +441,7 @@ def test_format_timespan(self): | |
# Make sure milliseconds are never shown separately when detailed=False. | ||
# https://github.com/xolox/python-humanfriendly/issues/10 | ||
assert '1 minute, 1 second and 100 milliseconds' == format_timespan(61.10, detailed=True) | ||
assert '1 minute and 1.1 second' == format_timespan(61.10, detailed=False) | ||
assert '1 minute and 1.1 seconds' == format_timespan(61.10, detailed=False) | ||
# Test for loss of precision as reported in issue 11: | ||
# https://github.com/xolox/python-humanfriendly/issues/11 | ||
assert '1 minute and 0.3 seconds' == format_timespan(60.300) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Human friendly input/output in Python. | ||
# | ||
# Author: Peter Odding <[email protected]> | ||
# Last Change: March 1, 2020 | ||
# Last Change: November 30, 2020 | ||
# URL: https://humanfriendly.readthedocs.io | ||
|
||
""" | ||
|
@@ -20,7 +20,6 @@ | |
""" | ||
|
||
# Standard library modules. | ||
import math | ||
import numbers | ||
import random | ||
import re | ||
|
@@ -284,11 +283,11 @@ def pluralize(count, singular, plural=None): | |
:param count: The count (a number). | ||
:param singular: The singular form of the word (a string). | ||
:param plural: The plural form of the word (a string or :data:`None`). | ||
:returns: The count and singular/plural word concatenated (a string). | ||
:returns: The count and singular or plural word concatenated (a string). | ||
""" | ||
if not plural: | ||
plural = singular + 's' | ||
return '%s %s' % (count, singular if math.floor(float(count)) == 1 else plural) | ||
return '%s %s' % (count, singular if float(count) == 1.0 else plural) | ||
|
||
|
||
def random_string(length=(25, 100), characters=string.ascii_letters): | ||
|