[Zodb-checkins] CVS: ZODB3/BDBStorage/tests - test_autopack.py:1.6 test_create.py:1.16 test_storage_api.py:1.29 test_virgin.py:1.12 test_whitebox.py:1.4 test_zodb_simple.py:1.10

Barry Warsaw barry@wooz.org
Fri, 3 Jan 2003 17:47:14 -0500


Update of /cvs-repository/ZODB3/BDBStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv29521/BDBStorage/tests

Modified Files:
	test_autopack.py test_create.py test_storage_api.py 
	test_virgin.py test_whitebox.py test_zodb_simple.py 
Log Message:
Here's a principled way to determine whether the BDBStorages are
available or not, and also fixes to all the tests so they won't crap
out or complain if not.

To test whether these storages are avialable (including all package
dependencies), do:

import BDBStorage
if BDBStorage.is_available:
    # okay to use

Also, in BDBStorage/__init__.py do some cross-platform compatibility
for the bsddb module; in Python 2.3 we can just use the built-in
module, but in earlier Pythons we have to use bsddb3.  Now you can
just use "from BDBStorage import db" to get the proper db object.


=== ZODB3/BDBStorage/tests/test_autopack.py 1.5 => 1.6 ===
--- ZODB3/BDBStorage/tests/test_autopack.py:1.5	Wed Dec 18 17:15:03 2002
+++ ZODB3/BDBStorage/tests/test_autopack.py	Fri Jan  3 17:47:10 2003
@@ -21,9 +21,16 @@
 from ZODB.tests.MinPO import MinPO
 from Persistence import Persistent
 
-from BDBStorage.BDBFullStorage import BDBFullStorage
-from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
-from BDBStorage.BerkeleyBase import BerkeleyConfig
+import BDBStorage
+if BDBStorage.is_available:
+    from BDBStorage.BDBFullStorage import BDBFullStorage
+    from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
+    from BDBStorage.BerkeleyBase import BerkeleyConfig
+else:
+    # Sigh
+    class FakeBaseClass: pass
+    BDBFullStorage = BDBMinimalStorage = FakeBaseClass
+
 from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
 
 ZERO = '\0'*8
@@ -254,9 +261,10 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(TestAutopack, 'check'))
-    suite.addTest(unittest.makeSuite(TestAutomaticClassicPack, 'check'))
-    suite.addTest(unittest.makeSuite(TestMinimalPack, 'check'))
+    if BDBStorage.is_available:
+        suite.addTest(unittest.makeSuite(TestAutopack, 'check'))
+        suite.addTest(unittest.makeSuite(TestAutomaticClassicPack, 'check'))
+        suite.addTest(unittest.makeSuite(TestMinimalPack, 'check'))
     return suite
 
 


=== ZODB3/BDBStorage/tests/test_create.py 1.15 => 1.16 ===
--- ZODB3/BDBStorage/tests/test_create.py:1.15	Wed Dec 18 17:15:03 2002
+++ ZODB3/BDBStorage/tests/test_create.py	Fri Jan  3 17:47:10 2003
@@ -18,9 +18,12 @@
 import time
 import unittest
 
-from BDBStorage.BerkeleyBase import BerkeleyConfig
+import BDBStorage
+if BDBStorage.is_available:
+    from BDBStorage.BerkeleyBase import BerkeleyConfig
+    from BDBStorage.BDBFullStorage import BDBFullStorage
+
 from BDBStorage.tests import BerkeleyTestBase
-from BDBStorage.BDBFullStorage import BDBFullStorage
 
 
 
@@ -106,11 +109,12 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(MinimalCreateTest, 'check'))
-    suite.addTest(unittest.makeSuite(FullCreateTest, 'check'))
-    suite.addTest(unittest.makeSuite(FullOpenExistingTest, 'check'))
-    suite.addTest(unittest.makeSuite(FullOpenCloseTest, 'check'))
-    suite.addTest(unittest.makeSuite(OpenRecoveryTest, 'check'))
+    if BDBStorage.is_available:
+        suite.addTest(unittest.makeSuite(MinimalCreateTest, 'check'))
+        suite.addTest(unittest.makeSuite(FullCreateTest, 'check'))
+        suite.addTest(unittest.makeSuite(FullOpenExistingTest, 'check'))
+        suite.addTest(unittest.makeSuite(FullOpenCloseTest, 'check'))
+        suite.addTest(unittest.makeSuite(OpenRecoveryTest, 'check'))
     return suite
 
 


=== ZODB3/BDBStorage/tests/test_storage_api.py 1.28 => 1.29 ===
--- ZODB3/BDBStorage/tests/test_storage_api.py:1.28	Tue Nov 19 15:40:22 2002
+++ ZODB3/BDBStorage/tests/test_storage_api.py	Fri Jan  3 17:47:10 2003
@@ -15,13 +15,11 @@
 # Unit tests for basic storage functionality
 
 import unittest
-# Import this here and now so that import failures properly cause the test
-# suite to ignore these tests.
-import bsddb3
-
 from ZODB import POSException
 
-import BerkeleyTestBase
+import BDBStorage
+from BDBStorage.tests import BerkeleyTestBase
+
 from ZODB.tests.BasicStorage import BasicStorage
 from ZODB.tests.RevisionStorage import RevisionStorage
 from ZODB.tests.VersionStorage import VersionStorage
@@ -79,9 +77,10 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(FullTest, 'check'))
-    suite.addTest(unittest.makeSuite(FullRecoveryTest, 'check'))
-    suite.addTest(unittest.makeSuite(MinimalTest, 'check'))
+    if BDBStorage.is_available:
+        suite.addTest(unittest.makeSuite(FullTest, 'check'))
+        suite.addTest(unittest.makeSuite(FullRecoveryTest, 'check'))
+        suite.addTest(unittest.makeSuite(MinimalTest, 'check'))
     return suite
 
 


=== ZODB3/BDBStorage/tests/test_virgin.py 1.11 => 1.12 ===
--- ZODB3/BDBStorage/tests/test_virgin.py:1.11	Wed Dec 18 17:15:03 2002
+++ ZODB3/BDBStorage/tests/test_virgin.py	Fri Jan  3 17:47:10 2003
@@ -16,7 +16,8 @@
 
 import unittest
 
-from ZODBTestBase import ZODBTestBase
+import BDBStorage
+from BDBStorage.tests.ZODBTestBase import ZODBTestBase
 from Persistence import PersistentMapping
         
 
@@ -46,8 +47,9 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(MinimalNewInsertsTest, 'check'))
-    suite.addTest(unittest.makeSuite(FullNewInsertsTest, 'check'))
+    if BDBStorage.is_available:
+        suite.addTest(unittest.makeSuite(MinimalNewInsertsTest, 'check'))
+        suite.addTest(unittest.makeSuite(FullNewInsertsTest, 'check'))
     return suite
 
 


=== ZODB3/BDBStorage/tests/test_whitebox.py 1.3 => 1.4 ===
--- ZODB3/BDBStorage/tests/test_whitebox.py:1.3	Wed Dec 18 17:15:03 2002
+++ ZODB3/BDBStorage/tests/test_whitebox.py	Fri Jan  3 17:47:10 2003
@@ -19,10 +19,18 @@
 from ZODB.utils import U64
 from ZODB.tests.MinPO import MinPO
 from ZODB.tests.StorageTestBase import zodb_unpickle
-from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
-from BDBStorage.BDBFullStorage import BDBFullStorage
-from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
+
+import BDBStorage
+if BDBStorage.is_available:
+    from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
+    from BDBStorage.BDBFullStorage import BDBFullStorage
+else:
+    # Sigh
+    class FakeBaseClass: pass
+    BDBFullStorage = BDBMinimalStorage = FakeBaseClass
+
 from BDBStorage.tests.ZODBTestBase import ZODBTestBase
+from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
 
 from Persistence import Persistent
 
@@ -218,9 +226,10 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(WhiteboxLowLevelMinimal, 'check'))
-    suite.addTest(unittest.makeSuite(WhiteboxHighLevelMinimal, 'check'))
-    suite.addTest(unittest.makeSuite(WhiteboxHighLevelFull, 'check'))
+    if BDBStorage.is_available:
+        suite.addTest(unittest.makeSuite(WhiteboxLowLevelMinimal, 'check'))
+        suite.addTest(unittest.makeSuite(WhiteboxHighLevelMinimal, 'check'))
+        suite.addTest(unittest.makeSuite(WhiteboxHighLevelFull, 'check'))
     return suite
 
 


=== ZODB3/BDBStorage/tests/test_zodb_simple.py 1.9 => 1.10 ===
--- ZODB3/BDBStorage/tests/test_zodb_simple.py:1.9	Wed Dec 18 17:15:03 2002
+++ ZODB3/BDBStorage/tests/test_zodb_simple.py	Fri Jan  3 17:47:10 2003
@@ -18,11 +18,9 @@
 
 import time
 import unittest
-# Import this here and now so that import failures properly cause the test
-# suite to ignore these tests.
-import bsddb3
 
-from ZODBTestBase import ZODBTestBase
+import BDBStorage
+from BDBStorage.tests.ZODBTestBase import ZODBTestBase
 from Persistence import PersistentMapping
 
 
@@ -81,8 +79,9 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(MinimalCommitAndRead, 'check'))
-    suite.addTest(unittest.makeSuite(FullCommitAndRead, 'check'))
+    if BDBStorage.is_available:
+        suite.addTest(unittest.makeSuite(MinimalCommitAndRead, 'check'))
+        suite.addTest(unittest.makeSuite(FullCommitAndRead, 'check'))
     return suite