[Zodb-checkins] CVS: ZODB3/ZODB/tests - testConfig.py:1.1.4.4

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


Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv28364

Modified Files:
      Tag: zconfig-schema-devel-branch
	testConfig.py 
Log Message:
Tests of BerkeleyDB based storages.  Also, a bit of refactoring.


=== ZODB3/ZODB/tests/testConfig.py 1.1.4.3 => 1.1.4.4 ===
--- ZODB3/ZODB/tests/testConfig.py:1.1.4.3	Thu Jan  2 18:30:37 2003
+++ ZODB3/ZODB/tests/testConfig.py	Fri Jan  3 14:04:46 2003
@@ -13,18 +13,22 @@
 ##############################################################################
 
 import os
+import errno
+import shutil
 import tempfile
 import unittest
 
-from ZODB.POSException import ReadOnlyError
 import ZODB.config
 import ZODB.tests
+from ZODB.POSException import ReadOnlyError
 from ZEO.ClientStorage import ClientDisconnected
 
-class ZODBConfigTest(unittest.TestCase):
+class ConfigTestBase(unittest.TestCase):
+    def _opendb(self, s):
+        return ZODB.config.databaseFromString(s)
 
     def _test(self, s):
-        db = ZODB.config.databaseFromString(s)
+        db = self._opendb(s)
         # Do something with the database to make sure it works
         cn = db.open()
         rt = cn.root()
@@ -32,6 +36,8 @@
         get_transaction().commit()
         db.close()
 
+
+class ZODBConfigTest(ConfigTestBase):
     def test_map_config1(self):
         self._test("<mappingstorage/>")
 
@@ -52,23 +58,65 @@
         
     def test_file_config2(self):
         path = tempfile.mktemp()
-        cfg = \
-            """<filestorage>
+        cfg = """
+        <filestorage>
             path %s
             create false
             read_only true
-            </filestorage>
-            """ % path
+        </filestorage>
+        """ % path
         self.assertRaises(ReadOnlyError, self._test, cfg)
 
     def test_zeo_config(self):
-        cfg = \
-            """<zeoclient>
+        cfg = """
+        <zeoclient>
             server /no/path/var/test/foo
             wait false
-            </zeoclient>
-            """
+        </zeoclient>
+        """
         self.assertRaises(ClientDisconnected, self._test, cfg)
 
+
+class BDBConfigTest(ConfigTestBase):
+    def setUp(self):
+        self._path = tempfile.mktemp()
+        try:
+            os.mkdir(self._path)
+        except OSError, e:
+            if e.errno <> errno.EEXIST:
+                raise
+
+    def tearDown(self):
+        shutil.rmtree(self._path)
+
+    def test_bdbfull_simple(self):
+        cfg = """
+        <fullstorage>
+            name %s
+        </fullstorage>
+        """ % self._path
+        self._test(cfg)
+
+    def test_bdbminimal_simple(self):
+        cfg = """
+        <minimalstorage>
+            name %s
+        </minimalstorage>
+        """ % self._path
+        self._test(cfg)
+
+
 def test_suite():
-    return unittest.makeSuite(ZODBConfigTest)
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(ZODBConfigTest))
+    try:
+        import BDBStorage.BDBFullStorage
+    except ImportError:
+        pass
+    else:
+        suite.addTest(unittest.makeSuite(BDBConfigTest))
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')