[Zodb-checkins] CVS: Zope/lib/python/ZODB/tests - RevisionStorage.py:1.1.4.1 testDemoStorage.py:1.1.4.1 BasicStorage.py:1.8.4.1 HistoryStorage.py:1.4.10.1 IteratorStorage.py:1.3.10.1 PackableStorage.py:1.8.4.1 StorageTestBase.py:1.6.6.1 TransactionalUndoStorage.py:1.11.10.1 VersionStorage.py:1.7.10.1 testFileStorage.py:1.9.10.1

Steve Alexander steve@cat-box.net
Fri, 5 Oct 2001 09:03:28 -0400


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

Modified Files:
      Tag: stevea_zcatalog_api_cruft_cleanup-branch
	BasicStorage.py HistoryStorage.py IteratorStorage.py 
	PackableStorage.py StorageTestBase.py 
	TransactionalUndoStorage.py VersionStorage.py 
	testFileStorage.py 
Added Files:
      Tag: stevea_zcatalog_api_cruft_cleanup-branch
	RevisionStorage.py testDemoStorage.py 
Log Message:
Updated stevea_zcatalog_api_cruft_cleanup to be in synch with HEAD


=== Added File Zope/lib/python/ZODB/tests/RevisionStorage.py ===
"""Check loadSerial() on storages that support historical revisions."""

from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle

ZERO = '\0'*8

class RevisionStorage:
    
    def checkLoadSerial(self):
        oid = self._storage.new_oid()
        revid = ZERO
        revisions = {}
        for i in range(31, 38):
            revid = self._dostore(oid, revid=revid, data=MinPO(i))
            revisions[revid] = MinPO(i)
        # Now make sure all the revisions have the correct value
        for revid, value in revisions.items():
            data = self._storage.loadSerial(oid, revid)
            self.assertEqual(zodb_unpickle(data), value)
    


=== Added File Zope/lib/python/ZODB/tests/testDemoStorage.py ===
import ZODB.DemoStorage
import os, unittest

from ZODB.tests import StorageTestBase, BasicStorage, \
     TransactionalUndoStorage, VersionStorage, \
     TransactionalUndoVersionStorage, PackableStorage, \
     Synchronization, ConflictResolution, HistoryStorage, \
     IteratorStorage, Corruption

class DemoStorageTests(StorageTestBase.StorageTestBase,
                       BasicStorage.BasicStorage,
                       VersionStorage.VersionStorage,
                       Synchronization.SynchronizedStorage,
                       ):

    def setUp(self):
        self._storage = ZODB.DemoStorage.DemoStorage()
        StorageTestBase.StorageTestBase.setUp(self)

def test_suite():
    suite = unittest.makeSuite(DemoStorageTests, 'check')
    return suite

if __name__ == "__main__":
    loader = unittest.TestLoader()
    loader.testMethodPrefix = "check"
    unittest.main(testLoader=loader)
    


=== Zope/lib/python/ZODB/tests/BasicStorage.py 1.8 => 1.8.4.1 ===
-#
-# http://www.zope.org/Documentation/Developer/Models/ZODB/ZODB_Architecture_Storage_Interface_Info.html
-#
-# All storages should be able to pass these tests
+"""Run the basic tests for a storage as described in the official storage API
+
+The most complete and most out-of-date description of the interface is:
+http://www.zope.org/Documentation/Developer/Models/ZODB/ZODB_Architecture_Storage_Interface_Info.html
+
+All storages should be able to pass these tests.
+"""
 
 from ZODB.Transaction import Transaction
 from ZODB import POSException
@@ -89,18 +91,6 @@
         self._dostore(oid=oid)
         self.assertEqual(self._storage.modifiedInVersion(oid), '')
 
-    def checkLoadSerial(self):
-        oid = self._storage.new_oid()
-        revid = ZERO
-        revisions = {}
-        for i in range(31, 38):
-            revid = self._dostore(oid, revid=revid, data=MinPO(i))
-            revisions[revid] = MinPO(i)
-        # Now make sure all the revisions have the correct value
-        for revid, value in revisions.items():
-            data = self._storage.loadSerial(oid, revid)
-            self.assertEqual(zodb_unpickle(data), value)
-    
     def checkConflicts(self):
         oid = self._storage.new_oid()
         revid1 = self._dostore(oid, data=MinPO(11))
@@ -139,3 +129,16 @@
         for oid, revid in [(oid1, revid1), (oid, revid)]:
             data, _revid = self._storage.load(oid, '')
             self.assertEqual(revid, _revid)
+
+    def checkStoreTwoObjects(self):
+        noteq = self.assertNotEqual
+        p31, p32, p51, p52 = map(MinPO, (31, 32, 51, 52))
+        oid1 = self._storage.new_oid()
+        oid2 = self._storage.new_oid()
+        noteq(oid1, oid2)
+        revid1 = self._dostore(oid1, data=p31)
+        revid2 = self._dostore(oid2, data=p51)
+        noteq(revid1, revid2)
+        revid3 = self._dostore(oid1, revid=revid1, data=p32)
+        revid4 = self._dostore(oid2, revid=revid2, data=p52)
+        noteq(revid3, revid4)


=== Zope/lib/python/ZODB/tests/HistoryStorage.py 1.4 => 1.4.10.1 ===
-# the history() method should be able to pass all these tests.
+"""Run the history() related tests for a storage.
+
+Any storage that supports the history() method should be able to pass
+all these tests.
+"""
 
 from ZODB.tests.MinPO import MinPO
 from ZODB.tests.StorageTestBase import zodb_unpickle


=== Zope/lib/python/ZODB/tests/IteratorStorage.py 1.3 => 1.3.10.1 ===
-# supports the iterator() method should be able to pass all these tests.
+"""Run tests against the iterator() interface for storages.
+
+Any storage that supports the iterator() method should be able to pass
+all these tests.
+"""
 
 from ZODB.tests.MinPO import MinPO
 from ZODB.tests.StorageTestBase import zodb_unpickle


=== Zope/lib/python/ZODB/tests/PackableStorage.py 1.8 => 1.8.4.1 ===
+"""Run some tests relevant for storages that support pack()."""
 
 try:
     import cPickle
@@ -18,7 +18,6 @@
 
 ZERO = '\0'*8
 
-
 
 # This class is for the root object.  It must not contain a getoid() method
 # (really, attribute).  The persistent pickling machinery -- in the dumps()
@@ -105,7 +104,7 @@
 class PackableStorage(PackableStorageBase):
     def _initroot(self):
         try:
-            self._storage.load('\0\0\0\0\0\0\0\0','')
+            self._storage.load(ZERO, '')
         except KeyError:
             import PersistentMapping
             from ZODB.Transaction import Transaction
@@ -116,8 +115,7 @@
             t=Transaction()
             t.description='initial database creation'
             self._storage.tpc_begin(t)
-            self._storage.store('\0\0\0\0\0\0\0\0',
-                                None, file.getvalue(), '', t)
+            self._storage.store(ZERO, None, file.getvalue(), '', t)
             self._storage.tpc_vote(t)
             self._storage.tpc_finish(t)
             


=== Zope/lib/python/ZODB/tests/StorageTestBase.py 1.6 => 1.6.6.1 ===
-# provides basic setUp() and tearDown() semantics (which you can override),
-# and it also provides a helper method _dostore() which performs a complete
-# store transaction for a single object revision.
+"""Provide a mixin base class for storage tests.
+
+The StorageTestBase class provides basic setUp() and tearDown()
+semantics (which you can override), and it also provides a helper
+method _dostore() which performs a complete store transaction for a
+single object revision.
+"""
 
 import pickle
 import string
@@ -18,6 +21,7 @@
 ZERO = '\0'*8
 
 def zodb_pickle(obj):
+    """Create a pickle in the format expected by ZODB."""
     f = StringIO()
     p = Pickler(f, 1)
     klass = obj.__class__
@@ -35,6 +39,7 @@
     return f.getvalue(1)
 
 def zodb_unpickle(data):
+    """Unpickle an object stored using the format expected by ZODB."""
     f = StringIO(data)
     u = Unpickler(f)
     klass_info = u.load()


=== Zope/lib/python/ZODB/tests/TransactionalUndoStorage.py 1.11 => 1.11.10.1 ===
-# must pass these tests.
+"""Check transactionalUndo().
+
+Any storage that supports transactionalUndo() must pass these tests.
+"""
 
 import types
 from ZODB import POSException
@@ -280,14 +282,15 @@
 
     def checkTwoObjectUndoAgain(self):
         eq = self.assertEqual
-        p32, p33, p52, p53 = map(zodb_pickle,
-                                 map(MinPO, (32, 33, 52, 53)))
+        p31, p32, p33, p51, p52, p53 = map(
+            zodb_pickle,
+            map(MinPO, (31, 32, 33, 51, 52, 53)))
         # Like the above, but the first revision of the objects are stored in
         # different transactions.
         oid1 = self._storage.new_oid()
         oid2 = self._storage.new_oid()
-        revid1 = self._dostore(oid1, data=MinPO(31))
-        revid2 = self._dostore(oid2, data=MinPO(51))
+        revid1 = self._dostore(oid1, data=p31, already_pickled=1)
+        revid2 = self._dostore(oid2, data=p51, already_pickled=1)
         # Update those same two objects
         self._storage.tpc_begin(self._transaction)
         self._transaction_begin()


=== Zope/lib/python/ZODB/tests/VersionStorage.py 1.7 => 1.7.10.1 ===
-# versions should be able to pass all these tests.
+"""Run the version related tests for a storage.
+
+Any storage that supports versions should be able to pass all these tests.
+"""
+
+# XXX we should clean this code up to get rid of the #JF# comments.
+# They were introduced when Jim reviewed the original version of the
+# code.  Barry and Jeremy didn't understand versions then.
 
 from ZODB import POSException
 from ZODB.tests.MinPO import MinPO
@@ -154,6 +160,7 @@
         self.assertRaises(POSException.VersionError,
                           self._storage.abortVersion,
                           '', self._transaction)
+        
         # But now we really try to abort the version
         oids = self._storage.abortVersion(version, self._transaction)
         self._storage.tpc_vote(self._transaction)
@@ -163,6 +170,16 @@
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(51))
 
+    def checkCommitVersionErrors(self):
+        eq = self.assertEqual
+        oid1, version1 = self._setup_version('one')
+        data, revid1 = self._storage.load(oid1, version1)
+        eq(zodb_unpickle(data), MinPO(54))
+        self._storage.tpc_begin(self._transaction)
+        self.assertRaises(POSException.VersionCommitError,
+                          self._storage.commitVersion,
+                          'one', 'one', self._transaction)
+
     def checkModifyAfterAbortVersion(self):
         eq = self.assertEqual
         oid, version = self._setup_version()
@@ -199,18 +216,20 @@
     def checkCommitToOtherVersion(self):
         eq = self.assertEqual
         oid1, version1 = self._setup_version('one')
+
         data, revid1 = self._storage.load(oid1, version1)
         eq(zodb_unpickle(data), MinPO(54))
         oid2, version2 = self._setup_version('two')
         data, revid2 = self._storage.load(oid2, version2)
         eq(zodb_unpickle(data), MinPO(54))
-        # Let's make sure we can't get object1 in version2
-        #JF# This won't fail because we fall back to non-version data.
-        #JF# In fact, it must succed and give us 51
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load, oid1, version2)
+
+        # make sure we see the non-version data when appropriate
         data, revid2 = self._storage.load(oid1, version2)
         eq(zodb_unpickle(data), MinPO(51))
+        data, revid2 = self._storage.load(oid2, version1)
+        eq(zodb_unpickle(data), MinPO(51))
+        data, revid2 = self._storage.load(oid1, '')
+        eq(zodb_unpickle(data), MinPO(51))
         
         # Okay, now let's commit object1 to version2
         self._storage.tpc_begin(self._transaction)
@@ -224,12 +243,16 @@
         eq(zodb_unpickle(data), MinPO(54))
         data, revid = self._storage.load(oid2, version2)
         eq(zodb_unpickle(data), MinPO(54))
-        #JF# Ditto, sort of
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load, oid1, version1)
+
+        # an object can only exist in one version, so a load from
+        # version1 should now give the non-version data 
         data, revid2 = self._storage.load(oid1, version1)
         eq(zodb_unpickle(data), MinPO(51))
 
+        # as should a version that has never been used
+        data, revid2 = self._storage.load(oid1, 'bela lugosi')
+        eq(zodb_unpickle(data), MinPO(51))
+
     def checkAbortOneVersionCommitTheOther(self):
         eq = self.assertEqual
         oid1, version1 = self._setup_version('one')
@@ -238,16 +261,11 @@
         oid2, version2 = self._setup_version('two')
         data, revid2 = self._storage.load(oid2, version2)
         eq(zodb_unpickle(data), MinPO(54))
-        # Let's make sure we can't get object1 in version2
 
-        #JF# It's not an error to load data in a different version when data
-        #JF# are stored in non-version. See above
-        #JF#
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load, oid1, version2)
+        # Let's make sure we can't get object1 in version2
         data, revid2 = self._storage.load(oid1, version2)
         eq(zodb_unpickle(data), MinPO(51))
-        
+
         # First, let's abort version1
         self._storage.tpc_begin(self._transaction)
         oids = self._storage.abortVersion(version1, self._transaction)
@@ -279,18 +297,13 @@
         self._storage.tpc_finish(self._transaction)
         eq(len(oids), 1)
         eq(oids[0], oid2)
-        # These objects should not be found in version 2
-        #JF# Ditto
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load, oid1, version2)
         data, revid = self._storage.load(oid1, '')
         eq(zodb_unpickle(data), MinPO(51))
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load, oid2, version2)
+
         # But the trunk should be up to date now
-        data, revid = self._storage.load(oid2, version2)
-        eq(zodb_unpickle(data), MinPO(54))
         data, revid = self._storage.load(oid2, '')
+        eq(zodb_unpickle(data), MinPO(54))
+        data, revid = self._storage.load(oid2, version2)
         eq(zodb_unpickle(data), MinPO(54))
 
         #JF# To do a test like you want, you have to add the data in a version


=== Zope/lib/python/ZODB/tests/testFileStorage.py 1.9 => 1.9.10.1 ===
-sys.path.insert(0, '.')
-
 import ZODB.FileStorage
 import os, unittest
-import StorageTestBase, BasicStorage, TransactionalUndoStorage
-import VersionStorage, TransactionalUndoVersionStorage
-import PackableStorage
-import Synchronization
-import ConflictResolution
-import HistoryStorage
-import IteratorStorage
-import Corruption
+
+from ZODB.tests import StorageTestBase, BasicStorage, \
+     TransactionalUndoStorage, VersionStorage, \
+     TransactionalUndoVersionStorage, PackableStorage, \
+     Synchronization, ConflictResolution, HistoryStorage, \
+     IteratorStorage, Corruption, RevisionStorage
 
 class FileStorageTests(
     StorageTestBase.StorageTestBase,
     BasicStorage.BasicStorage,
     TransactionalUndoStorage.TransactionalUndoStorage,
+    RevisionStorage.RevisionStorage,
     VersionStorage.VersionStorage,
     TransactionalUndoVersionStorage.TransactionalUndoVersionStorage,
     PackableStorage.PackableStorage,
@@ -41,7 +37,6 @@
     suite = unittest.makeSuite(FileStorageTests, 'check')
     suite2 = unittest.makeSuite(Corruption.FileStorageCorruptTests, 'check')
     suite.addTest(suite2)
-##    suite._tests.extend(suite2._tests)
     return suite
 
 def main():