[Zope-Checkins] CVS: Zope/lib/python/ZODB/tests - testFileStorage.py:1.19.6.2 StorageTestBase.py:1.17.6.2

Jeremy Hylton jeremy@zope.com
Wed, 11 Dec 2002 11:31:16 -0500


Update of /cvs-repository/Zope/lib/python/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv20407/tests

Modified Files:
      Tag: Zope-2_6-branch
	testFileStorage.py StorageTestBase.py 
Log Message:
Backport several changes from the ZODB3-3_1-branch.

Fix subtle bug in restore().
Provide much simpler version of getSerial().
Add bogus __len__ to get tests work with Python 2.1.
load_class() returns None on error.

Add some extra tests that cover bugs fixed.







=== Zope/lib/python/ZODB/tests/testFileStorage.py 1.19.6.1 => 1.19.6.2 ===
--- Zope/lib/python/ZODB/tests/testFileStorage.py:1.19.6.1	Fri Nov 15 12:45:02 2002
+++ Zope/lib/python/ZODB/tests/testFileStorage.py	Wed Dec 11 11:30:45 2002
@@ -1,8 +1,11 @@
 from __future__ import nested_scopes
 
-import ZODB.FileStorage
 import sys, os, unittest
+import time
 import errno
+
+import ZODB.FileStorage
+from ZODB.referencesf import referencesf
 from ZODB.Transaction import Transaction
 from ZODB import POSException
 
@@ -13,6 +16,8 @@
      IteratorStorage, Corruption, RevisionStorage, PersistentStorage, \
      MTStorage, ReadOnlyStorage
 from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle
+from PersistentMapping import PersistentMapping
+from ZODB import DB
 
 class FileStorageTests(
     StorageTestBase.StorageTestBase,
@@ -174,7 +179,30 @@
         self._dst = ZODB.FileStorage.FileStorage('Dest.fs')
         self._dst.copyTransactionsFrom(self._storage)
         self.compare(self._storage, self._dst)
-        
+
+    def checkRestoreAcrossPack(self):
+        db = DB(self._storage)
+        c = db.open()
+        r = c.root()
+        obj1 = r["obj1"] = MinPO(1)
+        get_transaction().commit()
+        obj1 = r["obj2"] = MinPO(1)
+        get_transaction().commit()
+
+        self._dst.copyTransactionsFrom(self._storage)
+        self._dst.pack(time.time(), referencesf)
+
+        self._undo(self._storage.undoInfo()[0]['id'])
+
+        # copy the final transaction manually.  even though there
+        # was a pack, the restore() ought to succeed.
+        final = list(self._storage.iterator())[-1]
+        self._dst.tpc_begin(final, final.tid, final.status)
+        for r in final:
+            self._dst.restore(r.oid, r.serial, r.data, r.version, r.data_txn,
+                         final)
+        self._dst.tpc_vote(final)
+        self._dst.tpc_finish(final)
 
 def test_suite():
     suite = unittest.makeSuite(FileStorageTests, 'check')


=== Zope/lib/python/ZODB/tests/StorageTestBase.py 1.17.6.1 => 1.17.6.2 ===
--- Zope/lib/python/ZODB/tests/StorageTestBase.py:1.17.6.1	Fri Nov 15 12:45:03 2002
+++ Zope/lib/python/ZODB/tests/StorageTestBase.py	Wed Dec 11 11:30:45 2002
@@ -184,7 +184,7 @@
 
     # The following methods depend on optional storage features.
 
-    def _undo(self, tid, oid):
+    def _undo(self, tid, oid=None):
         # Undo a tid that affects a single object (oid).
         # XXX This is very specialized
         t = Transaction()
@@ -193,8 +193,9 @@
         oids = self._storage.transactionalUndo(tid, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
-        self.assertEqual(len(oids), 1)
-        self.assertEqual(oids[0], oid)
+        if oid is not None:
+            self.assertEqual(len(oids), 1)
+            self.assertEqual(oids[0], oid)
         return self._storage.lastTransaction()
 
     def _commitVersion(self, src, dst):
@@ -214,4 +215,3 @@
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         return oids
-