Ew, modified the original argument in utils.commaAndify.

This commit is contained in:
Jeremy Fincher 2003-08-21 11:47:43 +00:00
parent 89e4a3ea59
commit 4858770ee7
2 changed files with 11 additions and 1 deletions

View File

@ -267,7 +267,11 @@ def commaAndify(L):
elif len(L) == 2:
return '%s and %s' % (L[0], L[1])
else:
# Not technically threadsafe. But we'll see if that matters.
originalLastElement = L[-1]
L[-1] = 'and %s' % L[-1]
return ', '.join(L)
s = ', '.join(L)
L[-1] = originalLastElement
return s
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -134,11 +134,17 @@ class UtilsTest(unittest.TestCase):
def testCommaAndify(self):
L = ['foo']
original = L[:]
self.assertEqual(utils.commaAndify(L), 'foo')
self.assertEqual(L, original)
L.append('bar')
original = L[:]
self.assertEqual(utils.commaAndify(L), 'foo and bar')
self.assertEqual(L, original)
L.append('baz')
original = L[:]
self.assertEqual(utils.commaAndify(L), 'foo, bar, and baz')
self.assertEqual(L, original)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: