mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 04:39:26 +01:00
Added setdefault and get to IrcDict.
This commit is contained in:
parent
0081c27812
commit
fd132f20ad
@ -406,6 +406,12 @@ class IrcDict(dict):
|
||||
def __reduce__(self):
|
||||
return (self.__class__, (dict(self),))
|
||||
|
||||
def setdefault(self, s, v):
|
||||
return self.__parent.setdefault(IrcString(s), v)
|
||||
|
||||
def get(self, s, d=None):
|
||||
return self.__parent.get(IrcString(s), d)
|
||||
|
||||
class IrcSet(sets.Set):
|
||||
"""A sets.Set using IrcStrings instead of regular strings."""
|
||||
def __init__(self, seq=()):
|
||||
|
@ -212,6 +212,19 @@ class IrcDictTestCase(unittest.TestCase):
|
||||
self.assertEqual(d['jemfinch[]'], 'bar')
|
||||
self.assertEqual(d['JEMFINCH[]'], 'bar')
|
||||
|
||||
def testSetdefault(self):
|
||||
d = ircutils.IrcDict()
|
||||
d.setdefault('#FOO', []).append(1)
|
||||
self.assertEqual(d['#foo'], [1])
|
||||
self.assertEqual(d['#fOO'], [1])
|
||||
self.assertEqual(d['#FOO'], [1])
|
||||
|
||||
def testGet(self):
|
||||
d = ircutils.IrcDict()
|
||||
self.assertEqual(d.get('#FOO'), None)
|
||||
d['#foo'] = 1
|
||||
self.assertEqual(d.get('#FOO'), 1)
|
||||
|
||||
def testContains(self):
|
||||
d = ircutils.IrcDict()
|
||||
d['#FOO'] = None
|
||||
|
Loading…
Reference in New Issue
Block a user