[Zope3-checkins] CVS: Zope3/src/zodb/btrees/tests - test_btrees.py:1.9

Jeremy Hylton jeremy@zope.com
Fri, 7 Mar 2003 15:13:22 -0500


Update of /cvs-repository/Zope3/src/zodb/btrees/tests
In directory cvs.zope.org:/tmp/cvs-serv25729

Modified Files:
	test_btrees.py 
Log Message:
Get these tests working for cases where the cache actually removes things.

The comparisons and LoadAndStore and GhostUnghost depended on being
able to read objects from a closed database.  That only works if the
object cache doesn't remove the objects, which can't be guaranteed
(nor should be).  Don't close the database until the end.

Also, use a MappingStorage instead of a FileStorage so that cleanup is
easier.


=== Zope3/src/zodb/btrees/tests/test_btrees.py 1.8 => 1.9 ===
--- Zope3/src/zodb/btrees/tests/test_btrees.py:1.8	Fri Mar  7 15:06:32 2003
+++ Zope3/src/zodb/btrees/tests/test_btrees.py	Fri Mar  7 15:13:20 2003
@@ -18,90 +18,69 @@
 
 from zodb.btrees.check import check
 from zodb.db import DB
-from zodb.storage.file import FileStorage
+from zodb.storage.mapping import MappingStorage
 
 from transaction import get_transaction
 
-from glob import glob
 import os
 import random
 from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
 
 class Base(TestCase):
     """ Tests common to all types: sets, buckets, and BTrees """
+
+    db = None
+
     def tearDown(self):
+        if self.db is not None:
+            self.db.close()
         self.t = None
         del self.t
 
     def _getRoot(self):
-        n = 'fs_tmp__%s' % os.getpid()
-        db = DB(FileStorage(n), cache_size=1)
-        root = db.open().root()
-        return root
-
-    def _closeDB(self, root):
-        if root is not None:
-            root._p_jar._db.close()
-
-    def _delDB(self):
-        for file in glob('fs_tmp__*'):
-            os.remove(file)
+        if self.db is None:
+            self.db = DB(MappingStorage(), cache_size=1)
+        return self.db.open().root()
+
+    def _closeRoot(self, root):
+        root._p_jar.close()
 
     def testLoadAndStore(self):
         for i in 0, 10, 1000:
             t = self.t.__class__()
             self._populate(t, i)
             root = None
-            try:
-                root = self._getRoot()
-                root[i] = t
-                get_transaction().commit()
-            except:
-                self._closeDB(root)
-                self._delDB()
-                raise
-
-            self._closeDB(root)
-
-            try:
-                root = self._getRoot()
-                #XXX BTree stuff doesn't implement comparison
-                if hasattr(t, 'items'):
-                    self.assertEqual(list(root[i].items()) , list(t.items()))
-                else:
-                    self.assertEqual(list(root[i].keys()) , list(t.keys()))
-            finally:
-                self._closeDB(root)
-                self._delDB()
-
+            root = self._getRoot()
+            root[i] = t
+            get_transaction().commit()
+
+            root2 = self._getRoot()
+            if hasattr(t, 'items'):
+                self.assertEqual(list(root2[i].items()) , list(t.items()))
+            else:
+                self.assertEqual(list(root2[i].keys()) , list(t.keys()))
+
+            self._closeRoot(root)
+            self._closeRoot(root2)
+            
     def testGhostUnghost(self):
         for i in 0, 10, 1000:
             t = self.t.__class__()
             self._populate(t, i)
-            root = None
-            try:
-                root = self._getRoot()
-                root[i] = t
-                get_transaction().commit()
-            except:
-                self._closeDB(root)
-                self._delDB()
-                raise
-
-            self._closeDB(root)
-
-            root = None
-            try:
-                root = self._getRoot()
-                root[i]._p_deactivate()
-                get_transaction().commit()
-                if hasattr(t, 'items'):
-                    self.assertEqual(list(root[i].items()) , list(t.items()))
-                else:
-                    self.assertEqual(list(root[i].keys()) , list(t.keys()))
-            finally:
-                self._closeDB(root)
-                self._delDB()
+            root = self._getRoot()
+            root[i] = t
+            get_transaction().commit()
+
+            root2 = self._getRoot()
+            root2[i]._p_deactivate()
+            get_transaction().commit()
+            if hasattr(t, 'items'):
+                self.assertEqual(list(root2[i].items()) , list(t.items()))
+            else:
+                self.assertEqual(list(root2[i].keys()) , list(t.keys()))
+                
+            self._closeRoot(root)
+            self._closeRoot(root2)
 
     def testSimpleExclusiveKeyRange(self):
         t = self.t.__class__()