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
|
break
|
||||||
return cmdLine
|
return cmdLine
|
||||||
|
|
||||||
def commaAndify(seq, And='and'):
|
def commaAndify(seq, comma=',', And='and'):
|
||||||
"""Given a a sequence, returns an english clause for that sequence.
|
"""Given a a sequence, returns an english clause for that sequence.
|
||||||
|
|
||||||
I.e., given [1, 2, 3], returns '1, 2, and 3'
|
I.e., given [1, 2, 3], returns '1, 2, and 3'
|
||||||
@ -282,7 +282,8 @@ def commaAndify(seq, And='and'):
|
|||||||
return ' '.join(L)
|
return ' '.join(L)
|
||||||
else:
|
else:
|
||||||
L[-1] = '%s %s' % (And, L[-1])
|
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)
|
_unCommaTheRe = re.compile(r'(.*),\s*(the)$', re.I)
|
||||||
def unCommaThe(s):
|
def unCommaThe(s):
|
||||||
|
@ -192,17 +192,20 @@ class UtilsTest(SupyTestCase):
|
|||||||
L = ['foo']
|
L = ['foo']
|
||||||
original = L[:]
|
original = L[:]
|
||||||
self.assertEqual(utils.commaAndify(L), 'foo')
|
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)
|
self.assertEqual(L, original)
|
||||||
L.append('bar')
|
L.append('bar')
|
||||||
original = L[:]
|
original = L[:]
|
||||||
self.assertEqual(utils.commaAndify(L), 'foo and bar')
|
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)
|
self.assertEqual(L, original)
|
||||||
L.append('baz')
|
L.append('baz')
|
||||||
original = L[:]
|
original = L[:]
|
||||||
self.assertEqual(utils.commaAndify(L), 'foo, bar, and baz')
|
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.assertEqual(L, original)
|
||||||
self.failUnless(utils.commaAndify(sets.Set(L)))
|
self.failUnless(utils.commaAndify(sets.Set(L)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user