diff --git a/humanfriendly/tests.py b/humanfriendly/tests.py index 72dad99..e83727e 100644 --- a/humanfriendly/tests.py +++ b/humanfriendly/tests.py @@ -733,6 +733,10 @@ def test_concatenate(self): # Test the 'conjunction' option. assert concatenate(['one', 'two', 'three'], conjunction='or') == 'one, two or three' # Test the 'serial_comma' option. + assert concatenate([], serial_comma=True) == '' + assert concatenate(['one'], serial_comma=True) == 'one' + assert concatenate(['one', 'two'], serial_comma=True) == 'one and two' + assert concatenate(iter(['one', 'two']), conjunction='or', serial_comma=True) == 'one or two' assert concatenate(['one', 'two', 'three'], serial_comma=True) == 'one, two, and three' def test_split(self): diff --git a/humanfriendly/text.py b/humanfriendly/text.py index a257a6a..2f30efe 100644 --- a/humanfriendly/text.py +++ b/humanfriendly/text.py @@ -125,7 +125,7 @@ def concatenate(items, conjunction='and', serial_comma=False): if len(items) > 1: final_item = items.pop() formatted = ', '.join(items) - if serial_comma: + if serial_comma and len(items) > 1: formatted += ',' return ' '.join([formatted, conjunction, final_item]) elif items: