Commit 0d1f0cfa authored by Jim Fulton's avatar Jim Fulton

Added a __del__ method to fsIndex.

parent 616d4350
......@@ -86,6 +86,15 @@ class fsIndex(object):
self._data[treekey] = tree
tree[key[6:]] = value
def __delitem__(self, key):
treekey = key[:6]
tree = self._data.get(treekey)
if tree is None:
raise KeyError, key
del tree[key[6:]]
if not tree:
del self._data[treekey]
def __len__(self):
r = 0
for tree in self._data.itervalues():
......
......@@ -26,6 +26,24 @@ class Test(unittest.TestCase):
for i in range(200):
self.index[p64(i * 1000)] = (i * 1000L + 1)
def test__del__(self):
index = self.index
self.assert_(p64(1000) in index)
self.assert_(p64(100*1000) in index)
del self.index[p64(1000)]
del self.index[p64(100*1000)]
self.assert_(p64(1000) not in index)
self.assert_(p64(100*1000) not in index)
for key in list(self.index):
del index[key]
self.assert_(not index)
# Whitebox. Make sure empty buckets are removed
self.assert_(not index._data)
def testInserts(self):
index = self.index
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment