Better error-checking.

This commit is contained in:
Jeremy Fincher 2005-01-13 17:48:47 +00:00
parent 4c22000f79
commit fdeae5c022
2 changed files with 7 additions and 0 deletions

View File

@ -101,6 +101,9 @@ def eachSubstring(s):
def abbrev(strings, d=None):
"""Returns a dictionary mapping unambiguous abbreviations to full forms."""
if len(strings) != len(set(strings)):
raise ValueError, \
'strings given to utils.abbrev have duplicates: %r' % strings
if d is None:
d = {}
for s in strings:

View File

@ -132,6 +132,10 @@ class UtilsTest(SupyTestCase):
self.assertEqual(d['fool'], 'fool')
self.assertEqual(d['foo'], 'foo')
def testAbbrevFailsWithDups(self):
L = ['english', 'english']
self.assertRaises(ValueError, utils.abbrev, L)
def testSoundex(self):
L = [('Euler', 'E460'),
('Ellery', 'E460'),