mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Made sure commaAndify raises TypeError when it's given lists of non-strings.
This commit is contained in:
parent
5750480714
commit
eaa15860d8
@ -256,9 +256,10 @@ def commaAndify(seq, And='and'):
|
|||||||
if len(L) == 0:
|
if len(L) == 0:
|
||||||
return ''
|
return ''
|
||||||
elif len(L) == 1:
|
elif len(L) == 1:
|
||||||
return L[0]
|
return ''.join(L) # We need this because it raises TypeError.
|
||||||
elif len(L) == 2:
|
elif len(L) == 2:
|
||||||
return '%s %s %s' % (L[0], And, L[1])
|
L.insert(1, And)
|
||||||
|
return ' '.join(L)
|
||||||
else:
|
else:
|
||||||
L[-1] = '%s %s' % (And, L[-1])
|
L[-1] = '%s %s' % (And, L[-1])
|
||||||
return ', '.join(L)
|
return ', '.join(L)
|
||||||
|
@ -180,6 +180,12 @@ class UtilsTest(unittest.TestCase):
|
|||||||
self.assertEqual(L, original)
|
self.assertEqual(L, original)
|
||||||
self.failUnless(utils.commaAndify(sets.Set(L)))
|
self.failUnless(utils.commaAndify(sets.Set(L)))
|
||||||
|
|
||||||
|
def testCommaAndifyRaisesTypeError(self):
|
||||||
|
L = [(2,)]
|
||||||
|
self.assertRaises(TypeError, utils.commaAndify, L)
|
||||||
|
L.append((3,))
|
||||||
|
self.assertRaises(TypeError, utils.commaAndify, L)
|
||||||
|
|
||||||
def testUnCommaThe(self):
|
def testUnCommaThe(self):
|
||||||
self.assertEqual(utils.unCommaThe('foo bar'), 'foo bar')
|
self.assertEqual(utils.unCommaThe('foo bar'), 'foo bar')
|
||||||
self.assertEqual(utils.unCommaThe('foo bar, the'), 'the foo bar')
|
self.assertEqual(utils.unCommaThe('foo bar, the'), 'the foo bar')
|
||||||
|
Loading…
Reference in New Issue
Block a user