diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-06-11 20:22:50 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-06-11 20:22:50 +0300 |
commit | e8343e237347ce3fbdf739deb6ac1844d9eba944 (patch) | |
tree | f947c21d37fc566ea8c4a694658d625939eb939d | |
parent | 195a1297550726eb3194ea980cbac984cf51fa25 (diff) | |
download | obnam-e8343e237347ce3fbdf739deb6ac1844d9eba944.tar.gz |
Add: removal of keys from leaves
-rw-r--r-- | obnamlib/fmt_ga/leaf.py | 4 | ||||
-rw-r--r-- | obnamlib/fmt_ga/leaf_tests.py | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/obnamlib/fmt_ga/leaf.py b/obnamlib/fmt_ga/leaf.py index 6522a6a9..3e5c0b2b 100644 --- a/obnamlib/fmt_ga/leaf.py +++ b/obnamlib/fmt_ga/leaf.py @@ -36,6 +36,10 @@ class CowLeaf(object): def insert(self, key, value): self._dict[key] = value + def remove(self, key): + if key in self._dict: + del self._dict[key] + def as_dict(self): return copy.deepcopy(self._dict) diff --git a/obnamlib/fmt_ga/leaf_tests.py b/obnamlib/fmt_ga/leaf_tests.py index 6c5f2903..bb035c9c 100644 --- a/obnamlib/fmt_ga/leaf_tests.py +++ b/obnamlib/fmt_ga/leaf_tests.py @@ -52,6 +52,12 @@ class CowLeafTests(unittest.TestCase): leaf.insert('foo', 'bar') self.assertEqual(leaf.keys(), ['foo']) + def test_removes_key(self): + leaf = obnamlib.CowLeaf() + leaf.insert('foo', 'bar') + leaf.remove('foo') + self.assertEqual(leaf.keys(), []) + def test_dict_round_trip(self): leaf = obnamlib.CowLeaf() leaf.insert('foo', 'bar') |