ODict.keys

This commit is contained in:
Aldo Cortesi 2013-02-28 09:28:48 +13:00
parent f30df13384
commit 0fa6351965
2 changed files with 22 additions and 0 deletions

View File

@ -36,6 +36,9 @@ class ODict:
ret.append(i[1])
return ret
def keys(self):
return list(set([self._kconv(i[0]) for i in self.lst]))
def _filter_lst(self, k, lst):
k = self._kconv(k)
new = []

View File

@ -63,6 +63,15 @@ class TestODict:
self.od.add("foo", 1)
assert [i for i in self.od]
def test_keys(self):
assert not self.od.keys()
self.od.add("foo", 1)
assert self.od.keys() == ["foo"]
self.od.add("foo", 2)
assert self.od.keys() == ["foo"]
self.od.add("bar", 2)
assert len(self.od.keys()) == 2
def test_copy(self):
self.od.add("foo", 1)
self.od.add("foo", 2)
@ -122,3 +131,13 @@ class TestODictCaseless:
self.od.add("bar", 3)
del self.od["foo"]
assert len(self.od) == 1
def test_keys(self):
assert not self.od.keys()
self.od.add("foo", 1)
assert self.od.keys() == ["foo"]
self.od.add("Foo", 2)
assert self.od.keys() == ["foo"]
self.od.add("bar", 2)
assert len(self.od.keys()) == 2