mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Better error-checking.
This commit is contained in:
parent
4c22000f79
commit
fdeae5c022
@ -101,6 +101,9 @@ def eachSubstring(s):
|
|||||||
|
|
||||||
def abbrev(strings, d=None):
|
def abbrev(strings, d=None):
|
||||||
"""Returns a dictionary mapping unambiguous abbreviations to full forms."""
|
"""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:
|
if d is None:
|
||||||
d = {}
|
d = {}
|
||||||
for s in strings:
|
for s in strings:
|
||||||
|
@ -132,6 +132,10 @@ class UtilsTest(SupyTestCase):
|
|||||||
self.assertEqual(d['fool'], 'fool')
|
self.assertEqual(d['fool'], 'fool')
|
||||||
self.assertEqual(d['foo'], 'foo')
|
self.assertEqual(d['foo'], 'foo')
|
||||||
|
|
||||||
|
def testAbbrevFailsWithDups(self):
|
||||||
|
L = ['english', 'english']
|
||||||
|
self.assertRaises(ValueError, utils.abbrev, L)
|
||||||
|
|
||||||
def testSoundex(self):
|
def testSoundex(self):
|
||||||
L = [('Euler', 'E460'),
|
L = [('Euler', 'E460'),
|
||||||
('Ellery', 'E460'),
|
('Ellery', 'E460'),
|
||||||
|
Loading…
Reference in New Issue
Block a user