mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-18 08:02:49 +01:00
Moved eachSubstring to be a nested function; we don't use it anywhere else.
This commit is contained in:
parent
6d02564965
commit
74b9a3c702
10
src/utils.py
10
src/utils.py
@ -31,8 +31,6 @@
|
|||||||
Simple utility functions.
|
Simple utility functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import supybot.fix as fix
|
import supybot.fix as fix
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -94,13 +92,11 @@ def htmlToText(s, tagReplace=' '):
|
|||||||
x.feed(s)
|
x.feed(s)
|
||||||
return x.getText()
|
return x.getText()
|
||||||
|
|
||||||
def eachSubstring(s):
|
|
||||||
"""Returns every substring starting at the first index until the last."""
|
|
||||||
for i in xrange(1, len(s)+1):
|
|
||||||
yield s[:i]
|
|
||||||
|
|
||||||
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."""
|
||||||
|
def eachSubstring(s):
|
||||||
|
for i in xrange(1, len(s)+1):
|
||||||
|
yield s[:i]
|
||||||
if len(strings) != len(set(strings)):
|
if len(strings) != len(set(strings)):
|
||||||
raise ValueError, \
|
raise ValueError, \
|
||||||
'strings given to utils.abbrev have duplicates: %r' % strings
|
'strings given to utils.abbrev have duplicates: %r' % strings
|
||||||
|
@ -101,11 +101,6 @@ class UtilsTest(SupyTestCase):
|
|||||||
def timeElapsedShort(self):
|
def timeElapsedShort(self):
|
||||||
self.assertEqual(utils.timeElapsed(123, short=True), '2m 3s')
|
self.assertEqual(utils.timeElapsed(123, short=True), '2m 3s')
|
||||||
|
|
||||||
def testEachSubstring(self):
|
|
||||||
s = 'foobar'
|
|
||||||
L = ['f', 'fo', 'foo', 'foob', 'fooba', 'foobar']
|
|
||||||
self.assertEqual(list(utils.eachSubstring(s)), L)
|
|
||||||
|
|
||||||
def testDistance(self):
|
def testDistance(self):
|
||||||
self.assertEqual(utils.distance('', ''), 0)
|
self.assertEqual(utils.distance('', ''), 0)
|
||||||
self.assertEqual(utils.distance('a', 'b'), 1)
|
self.assertEqual(utils.distance('a', 'b'), 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user