Fixed bug (no __delitem__) in IrcDict and added test.

This commit is contained in:
Jeremy Fincher 2003-04-11 20:44:29 +00:00
parent 6aa1e8a7ed
commit d596752a5f
2 changed files with 19 additions and 3 deletions

View File

@ -222,11 +222,17 @@ class nick(str):
class IrcDict(dict):
def __contains__(self, s):
return dict.__contains__(self, toLower(s))
has_key = __contains__
def __setitem__(self, s, v):
dict.__setitem__(self, toLower(s), v)
def __getitem__(self, s):
return dict.__getitem__(self, toLower(s))
has_key = __contains__
def __delitem__(self, s):
dict.__delitem__(self, toLower(s))
if __name__ == '__main__':
import sys, doctest

View File

@ -137,9 +137,19 @@ class FunctionsTestCase(unittest.TestCase):
modes = [plusB, plusE, minusL]
self.assertEqual(ircutils.joinModes(modes),
['+be-l', plusB[1], plusE[1]])
class IrcDictTestCase(unittest.TestCase):
def test(self):
d = ircutils.IrcDict()
d['#FOO'] = 'bar'
self.assertEqual(d['#FOO'], 'bar')
self.assertEqual(d['#Foo'], 'bar')
self.assertEqual(d['#foo'], 'bar')
del d['#fOO']
d['jemfinch{}'] = 'bar'
self.assertEqual(d['jemfinch{}'], 'bar')
self.assertEqual(d['jemfinch[]'], 'bar')
self.assertEqual(d['JEMFINCH[]'], 'bar')
def testContains(self):
d = ircutils.IrcDict()
d['#FOO'] = None