[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Added a __del__ method to
fsIndex.
Jim Fulton
jim at zope.com
Thu May 15 10:20:27 EDT 2008
Log message for revision 86772:
Added a __del__ method to fsIndex.
Changed:
U ZODB/trunk/src/ZODB/fsIndex.py
U ZODB/trunk/src/ZODB/tests/testfsIndex.py
-=-
Modified: ZODB/trunk/src/ZODB/fsIndex.py
===================================================================
--- ZODB/trunk/src/ZODB/fsIndex.py 2008-05-15 12:49:51 UTC (rev 86771)
+++ ZODB/trunk/src/ZODB/fsIndex.py 2008-05-15 14:20:25 UTC (rev 86772)
@@ -86,6 +86,15 @@
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():
Modified: ZODB/trunk/src/ZODB/tests/testfsIndex.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testfsIndex.py 2008-05-15 12:49:51 UTC (rev 86771)
+++ ZODB/trunk/src/ZODB/tests/testfsIndex.py 2008-05-15 14:20:25 UTC (rev 86772)
@@ -26,6 +26,24 @@
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
More information about the Zodb-checkins
mailing list