From 0fa63519654db2567995f3c3ac6e464796de66a3 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 28 Feb 2013 09:28:48 +1300 Subject: [PATCH] ODict.keys --- netlib/odict.py | 3 +++ test/test_odict.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/netlib/odict.py b/netlib/odict.py index bddb38773..0759a5bf1 100644 --- a/netlib/odict.py +++ b/netlib/odict.py @@ -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 = [] diff --git a/test/test_odict.py b/test/test_odict.py index d59ed67ef..26bff3574 100644 --- a/test/test_odict.py +++ b/test/test_odict.py @@ -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 +