[Zodb-checkins] CVS: ZODB3/ZODB/tests - testConfig.py:1.2 testStorageConfig.py:1.7

Fred L. Drake, Jr. fred@zope.com
Fri, 3 Jan 2003 16:19:11 -0500


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

Modified Files:
	testStorageConfig.py 
Added Files:
	testConfig.py 
Log Message:
Merge ZConfig schema support integration from the zconfig-schema-devel-branch.

=== ZODB3/ZODB/tests/testConfig.py 1.1 => 1.2 ===
--- /dev/null	Fri Jan  3 16:19:11 2003
+++ ZODB3/ZODB/tests/testConfig.py	Fri Jan  3 16:19:07 2003
@@ -0,0 +1,121 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+
+import os
+import errno
+import shutil
+import tempfile
+import unittest
+
+import ZODB.config
+import ZODB.tests
+from ZODB.POSException import ReadOnlyError
+from ZEO.ClientStorage import ClientDisconnected
+
+class ConfigTestBase(unittest.TestCase):
+    def _opendb(self, s):
+        return ZODB.config.databaseFromString(s)
+
+    def _test(self, s):
+        db = self._opendb(s)
+        # Do something with the database to make sure it works
+        cn = db.open()
+        rt = cn.root()
+        rt["test"] = 1
+        get_transaction().commit()
+        db.close()
+
+
+class ZODBConfigTest(ConfigTestBase):
+    def test_map_config1(self):
+        self._test("<mappingstorage/>")
+
+    def test_map_config2(self):
+        self._test(
+            """<mappingstorage/>
+            cache_size 1000
+            """)
+
+    def test_file_config1(self):
+        path = tempfile.mktemp()
+        self._test(
+            """<filestorage>
+            path %s
+            </filestorage>
+            """ % path)
+        os.unlink(path)
+        
+    def test_file_config2(self):
+        path = tempfile.mktemp()
+        cfg = """
+        <filestorage>
+            path %s
+            create false
+            read_only true
+        </filestorage>
+        """ % path
+        self.assertRaises(ReadOnlyError, self._test, cfg)
+
+    def test_zeo_config(self):
+        cfg = """
+        <zeoclient>
+            server /no/path/var/test/foo
+            wait false
+        </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():
+    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')


=== ZODB3/ZODB/tests/testStorageConfig.py 1.6 => 1.7 ===
--- ZODB3/ZODB/tests/testStorageConfig.py:1.6	Wed Dec 18 17:15:05 2002
+++ ZODB3/ZODB/tests/testStorageConfig.py	Fri Jan  3 16:19:07 2003
@@ -17,7 +17,7 @@
 import unittest
 from StringIO import StringIO
 
-import ZConfig
+import ZConfig.Context
 
 from ZODB import StorageConfig
 
@@ -46,6 +46,11 @@
         except os.error:
             pass
 
+    def loadConfigText(self, text):
+        context = ZConfig.Context.Context()
+        io = StringIO(text)
+        return context.loadFile(io)
+
     def testFileStorage(self):
         from ZODB.FileStorage import FileStorage
         sample = """
@@ -55,8 +60,7 @@
         create     yes
         </Storage>
         """ % self.tmpfn
-        io = StringIO(sample)
-        rootconf = ZConfig.loadfile(io)
+        rootconf = self.loadConfigText(sample)
         storageconf = rootconf.getSection("Storage")
         cls, args = StorageConfig.getStorageInfo(storageconf)
         self.assertEqual(cls, FileStorage)
@@ -73,8 +77,7 @@
         wait       no
         </Storage>
         """
-        io = StringIO(sample)
-        rootconf = ZConfig.loadfile(io)
+        rootconf = self.loadConfigText(sample)
         storageconf = rootconf.getSection("Storage")
         cls, args = StorageConfig.getStorageInfo(storageconf)
         self.assertEqual(cls, ClientStorage)
@@ -89,8 +92,7 @@
         type       DemoStorage
         </Storage>
         """
-        io = StringIO(sample)
-        rootconf = ZConfig.loadfile(io)
+        rootconf = self.loadConfigText(sample)
         storageconf = rootconf.getSection("Storage")
         cls, args = StorageConfig.getStorageInfo(storageconf)
         self.assertEqual(cls, DemoStorage)
@@ -106,8 +108,7 @@
         type       ZODB.DemoStorage.DemoStorage
         </Storage>
         """
-        io = StringIO(sample)
-        rootconf = ZConfig.loadfile(io)
+        rootconf = self.loadConfigText(sample)
         storageconf = rootconf.getSection("Storage")
         cls, args = StorageConfig.getStorageInfo(storageconf)
         self.assertEqual(cls, DemoStorage)
@@ -128,8 +129,7 @@
         </Storage>
         """ % self.tmpfn
         os.mkdir(self.tmpfn)
-        io = StringIO(sample)
-        rootconf = ZConfig.loadfile(io)
+        rootconf = self.loadConfigText(sample)
         storageconf = rootconf.getSection("Storage")
         cls, args = StorageConfig.getStorageInfo(storageconf)
         self.assertEqual(cls, BDBFullStorage)
@@ -155,8 +155,7 @@
         </Storage>
         """ % self.tmpfn
         os.mkdir(self.tmpfn)
-        io = StringIO(sample)
-        rootconf = ZConfig.loadfile(io)
+        rootconf = self.loadConfigText(sample)
         storageconf = rootconf.getSection("Storage")
         cls, args = StorageConfig.getStorageInfo(storageconf)
         self.assertEqual(cls, BDBMinimalStorage)