mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-22 18:14:41 +01:00
Add comma argument to commaAndify
This commit is contained in:
parent
a0e7bd2bd1
commit
481dd5111a
@ -267,7 +267,7 @@ def findBinaryInPath(s):
|
||||
break
|
||||
return cmdLine
|
||||
|
||||
def commaAndify(seq, And='and'):
|
||||
def commaAndify(seq, comma=',', And='and'):
|
||||
"""Given a a sequence, returns an english clause for that sequence.
|
||||
|
||||
I.e., given [1, 2, 3], returns '1, 2, and 3'
|
||||
@ -282,7 +282,8 @@ def commaAndify(seq, And='and'):
|
||||
return ' '.join(L)
|
||||
else:
|
||||
L[-1] = '%s %s' % (And, L[-1])
|
||||
return ', '.join(L)
|
||||
sep = '%s ' % comma
|
||||
return sep.join(L)
|
||||
|
||||
_unCommaTheRe = re.compile(r'(.*),\s*(the)$', re.I)
|
||||
def unCommaThe(s):
|
||||
|
@ -192,17 +192,20 @@ class UtilsTest(SupyTestCase):
|
||||
L = ['foo']
|
||||
original = L[:]
|
||||
self.assertEqual(utils.commaAndify(L), 'foo')
|
||||
self.assertEqual(utils.commaAndify(L, 'or'), 'foo')
|
||||
self.assertEqual(utils.commaAndify(L, And='or'), 'foo')
|
||||
self.assertEqual(L, original)
|
||||
L.append('bar')
|
||||
original = L[:]
|
||||
self.assertEqual(utils.commaAndify(L), 'foo and bar')
|
||||
self.assertEqual(utils.commaAndify(L, 'or'), 'foo or bar')
|
||||
self.assertEqual(utils.commaAndify(L, And='or'), 'foo or bar')
|
||||
self.assertEqual(L, original)
|
||||
L.append('baz')
|
||||
original = L[:]
|
||||
self.assertEqual(utils.commaAndify(L), 'foo, bar, and baz')
|
||||
self.assertEqual(utils.commaAndify(L, 'or'), 'foo, bar, or baz')
|
||||
self.assertEqual(utils.commaAndify(L, And='or'), 'foo, bar, or baz')
|
||||
self.assertEqual(utils.commaAndify(L, comma=';'), 'foo; bar; and baz')
|
||||
self.assertEqual(utils.commaAndify(L, comma=';', And='or'),
|
||||
'foo; bar; or baz')
|
||||
self.assertEqual(L, original)
|
||||
self.failUnless(utils.commaAndify(sets.Set(L)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user