Add an .extend method for ODicts
This commit is contained in:
parent
6db5e0a4a1
commit
d739882bf2
|
@ -108,6 +108,12 @@ class ODict(object):
|
|||
lst = copy.deepcopy(self.lst)
|
||||
return self.__class__(lst)
|
||||
|
||||
def extend(self, other):
|
||||
"""
|
||||
Add the contents of other, preserving any duplicates.
|
||||
"""
|
||||
self.lst.extend(other.lst)
|
||||
|
||||
def __repr__(self):
|
||||
elements = []
|
||||
for itm in self.lst:
|
||||
|
|
|
@ -109,6 +109,12 @@ class TestODict:
|
|||
assert self.od.get_first("one") == "two"
|
||||
assert self.od.get_first("two") == None
|
||||
|
||||
def test_extend(self):
|
||||
a = odict.ODict([["a", "b"], ["c", "d"]])
|
||||
b = odict.ODict([["a", "b"], ["e", "f"]])
|
||||
a.extend(b)
|
||||
assert len(a) == 4
|
||||
assert a["a"] == ["b", "b"]
|
||||
|
||||
class TestODictCaseless:
|
||||
def setUp(self):
|
||||
|
@ -144,4 +150,3 @@ class TestODictCaseless:
|
|||
assert self.od.keys() == ["foo"]
|
||||
self.od.add("bar", 2)
|
||||
assert len(self.od.keys()) == 2
|
||||
|
||||
|
|
Loading…
Reference in New Issue