[Zope3-checkins] CVS: Zope3/src/zodb/storage/tests - base.py:1.6.4.1 packable.py:1.4.4.2

Jeremy Hylton jeremy@zope.com
Mon, 10 Mar 2003 18:06:13 -0500


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

Modified Files:
      Tag: opaque-pickles-branch
	base.py packable.py 
Log Message:
Move root + reachable object creation code into base.


=== Zope3/src/zodb/storage/tests/base.py 1.6 => 1.6.4.1 ===
--- Zope3/src/zodb/storage/tests/base.py:1.6	Wed Feb  5 18:28:27 2003
+++ Zope3/src/zodb/storage/tests/base.py	Mon Mar 10 18:06:10 2003
@@ -27,6 +27,7 @@
 import shutil
 import unittest
 
+from persistence import Persistent
 from transaction import get_transaction
 
 from zodb.db import DB
@@ -94,6 +95,20 @@
             if err[0] != errno.ENOENT:
                 raise
 
+class C(Persistent):
+    pass
+
+
+class Jar:
+    def __init__(self, storage):
+        self._storage = storage
+        
+    def newObjectId(self):
+        return self._storage.newObjectId()
+
+    def register(self, obj):
+        obj._p_oid = self.newObjectId()
+
 
 class StorageTestBase(unittest.TestCase):
 
@@ -193,6 +208,44 @@
         self._storage.tpcFinish(t)
         return oids
 
+    # some helper functions for setting up a valid root so that
+    # the storage can be packed
+
+    def _initroot(self):
+        self._jar = jar = Jar(self._storage)
+        self._reader = ConnectionObjectReader(jar, {})
+        try:
+            self._storage.load(ZERO, '')
+        except KeyError:
+            root = self._newobj()
+            t = Transaction()
+            t.note("initial database creation")
+            self._storage.tpcBegin(t)
+            self._storage.store(ZERO, None, zodb_pickle(root), '', t)
+            self._storage.tpcVote(t)
+            self._storage.tpcFinish(t)
+
+    def _newobj(self):
+        obj = C()
+        obj._p_jar = self._jar
+        return obj
+
+    def _linked_newobj(self):
+        # Create a new object and make sure the root has a reference to it.
+        # Returns the object, the root, and the revid of the root.
+        data, revid0 = self._storage.load(ZERO, '')
+        root = self._reader.getObject(data)
+        obj = self._newobj()
+        # Link the root object to the persistent object, in order to keep the
+        # persistent object alive.  XXX Order here is important: an attribute
+        # on the root object must be set first, so that it gets oid 0, /then/
+        # the attribute on the obj can be set.
+        root.obj = obj
+        obj.value = 0
+        root.value = 0
+        root._p_jar = self._jar
+        revid0 = self._dostore(ZERO, revid=revid0, data=root)
+        return obj, root, revid0
 
 
 class BerkeleyTestBase(StorageTestBase):


=== Zope3/src/zodb/storage/tests/packable.py 1.4.4.1 => 1.4.4.2 ===
--- Zope3/src/zodb/storage/tests/packable.py:1.4.4.1	Mon Feb 10 18:20:30 2003
+++ Zope3/src/zodb/storage/tests/packable.py	Mon Mar 10 18:06:10 2003
@@ -15,7 +15,6 @@
 
 import time
 
-from persistence import Persistent
 from transaction import get_transaction
 
 from zodb.db import DB
@@ -24,45 +23,11 @@
 from zodb.ztransaction import Transaction
 from zodb.storage.tests.minpo import MinPO
 from zodb.storage.tests.base import zodb_pickle, zodb_unpickle
-
-
-class C(Persistent):
-    pass
-
-
-class Jar:
-    def __init__(self, storage):
-        self._storage = storage
-        
-    def newObjectId(self):
-        return self._storage.newObjectId()
-
-    def register(self, obj):
-        obj._p_oid = self.newObjectId()
+from zodb.storage.fsdump import dump
 
 
 
 class PackableStorage:
-    def _initroot(self):
-        self._jar = jar = Jar(self._storage)
-        self._reader = ConnectionObjectReader(jar, {})
-        try:
-            self._storage.load(ZERO, '')
-        except KeyError:
-            root = C()
-            root._p_jar = jar
-            t = Transaction()
-            t.note("initial database creation")
-            self._storage.tpcBegin(t)
-            self._storage.store(ZERO, None, zodb_pickle(root), '', t)
-            self._storage.tpcVote(t)
-            self._storage.tpcFinish(t)
-
-    def _newobj(self):
-        obj = C()
-        obj._p_jar = self._jar
-        return obj
-
     def checkPackEmptyStorage(self):
         self._storage.pack(time.time())
 
@@ -115,18 +80,7 @@
         raises = self.assertRaises
         # Create a root object
         self._initroot()
-        data, revid0 = self._storage.load(ZERO, '')
-        root = self._reader.getObject(data)
-        obj = self._newobj()
-        # Link the root object to the persistent object, in order to keep the
-        # persistent object alive.  XXX Order here is important: an attribute
-        # on the root object must be set first, so that it gets oid 0, /then/
-        # the attribute on the obj can be set.
-        root.obj = obj
-        obj.value = 0
-        root.value = 0
-        root._p_jar = self._jar
-        revid0 = self._dostore(ZERO, revid=revid0, data=root)
+        obj, root, revid0 = self._linked_newobj()
         # Make sure the root can be retrieved
         data, revid = self._storage.load(ZERO, '')
         eq(revid, revid0)