[Zodb-checkins] SVN: ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/ Only test version methods if the storage under test supports versions.

Jim Fulton jim at zope.com
Thu Apr 26 13:05:41 EDT 2007


Log message for revision 74793:
  Only test version methods if the storage under test supports versions.
  
  This isn't pretty, but will go away in 3.9.
  

Changed:
  U   ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/BasicStorage.py
  U   ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/MTStorage.py
  U   ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/Synchronization.py

-=-
Modified: ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/BasicStorage.py
===================================================================
--- ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/BasicStorage.py	2007-04-26 17:05:38 UTC (rev 74792)
+++ ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/BasicStorage.py	2007-04-26 17:05:40 UTC (rev 74793)
@@ -46,22 +46,24 @@
             self._storage.store,
             0, 0, 0, 0, transaction.Transaction())
 
-        try:
-            self._storage.abortVersion('dummy', transaction.Transaction())
-        except (POSException.StorageTransactionError,
-                POSException.VersionCommitError):
-            pass # test passed ;)
-        else:
-            assert 0, "Should have failed, invalid transaction."
+        if self.__supportsVersions():
+            try:
+                self._storage.abortVersion(
+                    'dummy', transaction.Transaction())
+            except (POSException.StorageTransactionError,
+                    POSException.VersionCommitError):
+                pass # test passed ;)
+            else:
+                assert 0, "Should have failed, invalid transaction."
 
-        try:
-            self._storage.commitVersion('dummy', 'dummer',
-                                        transaction.Transaction())
-        except (POSException.StorageTransactionError,
-                POSException.VersionCommitError):
-            pass # test passed ;)
-        else:
-            assert 0, "Should have failed, invalid transaction."
+            try:
+                self._storage.commitVersion('dummy', 'dummer',
+                                            transaction.Transaction())
+            except (POSException.StorageTransactionError,
+                    POSException.VersionCommitError):
+                pass # test passed ;)
+            else:
+                assert 0, "Should have failed, invalid transaction."
 
         self.assertRaises(
             POSException.StorageTransactionError,
@@ -69,6 +71,15 @@
             0, 1, 2, 3, transaction.Transaction())
         self._storage.tpc_abort(t)
 
+    def __supportsVersions(self):
+        storage = self._storage
+        try:
+            supportsVersions = storage.supportsVersions
+        except AttributeError:
+            return False
+        else:
+            return supportsVersions()
+
     def checkSerialIsNoneForInitialRevision(self):
         eq = self.assertEqual
         oid = self._storage.new_oid()
@@ -107,9 +118,10 @@
         eq(zodb_unpickle(data), MinPO(21))
 
     def checkNonVersionModifiedInVersion(self):
-        oid = self._storage.new_oid()
-        self._dostore(oid=oid)
-        self.assertEqual(self._storage.modifiedInVersion(oid), '')
+        if self.__supportsVersions():
+            oid = self._storage.new_oid()
+            self._dostore(oid=oid)
+            self.assertEqual(self._storage.modifiedInVersion(oid), '')
 
     def checkConflicts(self):
         oid = self._storage.new_oid()

Modified: ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/MTStorage.py
===================================================================
--- ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/MTStorage.py	2007-04-26 17:05:38 UTC (rev 74792)
+++ ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/MTStorage.py	2007-04-26 17:05:40 UTC (rev 74793)
@@ -162,9 +162,25 @@
     def runtest(self):
         # pick some other storage ops to execute, depending in part
         # on the features provided by the storage.
-        names = ["do_load", "do_modifiedInVersion"]
-        if self.storage.supportsUndo():
-            names += ["do_loadSerial", "do_undoLog", "do_iterator"]
+        names = ["do_load"]
+
+        storage = self.storage
+        try:
+            supportsVersions = storage.supportsVersions
+        except AttributeError:
+            pass
+        else:
+            if supportsVersions():
+                names.append("do_modifiedInVersion")
+
+        try:
+            supportsUndo = storage.supportsUndo
+        except AttributeError:
+            pass
+        else:
+            if supportsUndo():
+                names += ["do_loadSerial", "do_undoLog", "do_iterator"]
+
         ops = [getattr(self, meth) for meth in names]
         assert ops, "Didn't find an storage ops in %s" % self.storage
         # do a store to guarantee there's at least one oid in self.oids

Modified: ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/Synchronization.py
===================================================================
--- ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/Synchronization.py	2007-04-26 17:05:38 UTC (rev 74792)
+++ ZODB/branches/jim-storage-api-cleanup/src/ZODB/tests/Synchronization.py	2007-04-26 17:05:40 UTC (rev 74793)
@@ -84,21 +84,33 @@
         self.assertRaises(StorageTransactionError, callable, *args)
         self._storage.tpc_abort(t)
 
+    def __supportsVersions(self):
+        storage = self._storage
+        try:
+            supportsVersions = storage.supportsVersions
+        except AttributeError:
+            return False
+        return supportsVersions()
+
     def checkAbortVersionNotCommitting(self):
-        self.verifyNotCommitting(self._storage.abortVersion,
-                                 VERSION, Transaction())
+        if self.__supportsVersions():
+            self.verifyNotCommitting(self._storage.abortVersion,
+                                     VERSION, Transaction())
 
     def checkAbortVersionWrongTrans(self):
-        self.verifyWrongTrans(self._storage.abortVersion,
-                              VERSION, Transaction())
+        if self.__supportsVersions():
+            self.verifyWrongTrans(self._storage.abortVersion,
+                                  VERSION, Transaction())
 
     def checkCommitVersionNotCommitting(self):
-        self.verifyNotCommitting(self._storage.commitVersion,
-                                 VERSION, "", Transaction())
+        if self.__supportsVersions():
+            self.verifyNotCommitting(self._storage.commitVersion,
+                                     VERSION, "", Transaction())
 
     def checkCommitVersionWrongTrans(self):
-        self.verifyWrongTrans(self._storage.commitVersion,
-                              VERSION, "", Transaction())
+        if self.__supportsVersions():
+            self.verifyWrongTrans(self._storage.commitVersion,
+                                  VERSION, "", Transaction())
 
 
     def checkStoreNotCommitting(self):



More information about the Zodb-checkins mailing list