[Zope-CVS] CVS: Products/Ape/lib/apelib/tests - testall.py:1.2 testzope2sql.py:1.2

Shane Hathaway shane@zope.com
Sat, 12 Apr 2003 16:56:57 -0400


Update of /cvs-repository/Products/Ape/lib/apelib/tests
In directory cvs.zope.org:/tmp/cvs-serv28924/lib/apelib/tests

Modified Files:
	testall.py testzope2sql.py 
Log Message:
Implemented support for MySQL 4.0, this time for real.  The change required
further abstraction of the query generator.  Supporting more databases
should now be straightforward.


=== Products/Ape/lib/apelib/tests/testall.py 1.1 => 1.2 ===
--- Products/Ape/lib/apelib/tests/testall.py:1.1	Wed Apr  9 23:09:57 2003
+++ Products/Ape/lib/apelib/tests/testall.py	Sat Apr 12 16:56:26 2003
@@ -35,25 +35,26 @@
 from teststorage import ApeStorageTests
 from testzope2fs import Zope2FSTests, Zope2FSUnderscoreTests
 from testparams import ParamsTests
+from testsqlimpl import ApelibSQLImplTests
+import testzope2sql
 
-try:
-    import psycopg
-except ImportError:
-    sys.stderr.write('Warning: could not import psycopg.\n')
-    sys.stderr.write('Not running the PostgreSQL tests.\n')
-else:
-    try:
-        c = psycopg.connect('')
-        c.close()
-    except psycopg.DatabaseError:
-        sys.stderr.write('Warning: could not open a psycopg connection.\n')
-        sys.stderr.write('Not running the PostgreSQL tests.\n')
-    else:
-        # Run the PostgreSQL tests.
-        from testzope2sql import Zope2SQLTests
-        from testsqlimpl import ApelibSQLImplTests
+sql_suite = testzope2sql.test_suite()
 
+def test_suite():
+    suite = unittest.TestSuite()
+    for klass in (
+        SerializationTests,
+        ApelibImplTests,
+        ApeStorageTests,
+        Zope2FSTests,
+        Zope2FSUnderscoreTests,
+        ParamsTests,
+        ApelibSQLImplTests,
+        ):
+        suite.addTest(unittest.makeSuite(klass, 'test'))
+    suite.addTest(sql_suite)
+    return suite
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main(defaultTest='test_suite')
 


=== Products/Ape/lib/apelib/tests/testzope2sql.py 1.1 => 1.2 ===
--- Products/Ape/lib/apelib/tests/testzope2sql.py:1.1	Wed Apr  9 23:09:57 2003
+++ Products/Ape/lib/apelib/tests/testzope2sql.py	Sat Apr 12 16:56:26 2003
@@ -17,23 +17,29 @@
 """
 
 import unittest
+import sys
 
-from apelib.sql.pg import PsycopgConnection
+from apelib.sql.dbapi import DBAPIConnector
 from apelib.zodb3.db import ApeDB
 from apelib.zodb3.storage import ApeStorage
 from apelib.zodb3.resource import StaticResource
-from apelib.zope2.sqlmapper import createSQLMapper
+from apelib.zope2.sqlmapper import createConnectorMapper
 from zope2testbase import Zope2TestBase
 
 
-class Zope2SQLTests (unittest.TestCase, Zope2TestBase):
+class Zope2SQLTests (Zope2TestBase):
 
-    def openConnection(self):
-        return PsycopgConnection('', 'test_temp')
+    dbapi_module = None  # Name of the Database API module (required)
+    dbapi_params = ()    # Positional args for connect()
+    dbapi_kwparams = {}  # Keyword args for connect()
+
+    def getConnector(self):
+        return DBAPIConnector(self.dbapi_module, self.dbapi_params,
+                              self.dbapi_kwparams, prefix='test_temp')
 
     def setUp(self):
-        conn = self.openConnection()
-        dm, conns, gws = createSQLMapper(conn)
+        conn = self.getConnector()
+        dm, conns, gws = createConnectorMapper(conn)
         self.dm = dm
         self.conns = conns
         self.gws = gws
@@ -54,7 +60,48 @@
         self.clear()
         self.db.close()
 
+    def testConnect(self):
+        # Tests the setUp/tearDown methods
+        pass
+
+
+class PsycopgTests (Zope2SQLTests, unittest.TestCase):
+    dbapi_module = 'psycopg'
+    dbapi_params = ('',)
+
+
+class MySQLTests (Zope2SQLTests, unittest.TestCase):
+    dbapi_module = 'MySQLdb'
+    dbapi_kwparams = {'db': 'ape'}
+
+
+def test_suite():
+    """Makes a test suite for the available databases."""
+    suite = unittest.TestSuite()
+    for k, v in globals().items():
+        mname = getattr(v, 'dbapi_module', None)
+        if mname is not None:
+            try:
+                __import__(mname, {}, {}, ('__doc__',))
+            except ImportError:
+                sys.stderr.write('Warning: could not import %s. '
+                                 'Skipping %s.\n'
+                                 % (repr(mname), k))
+            else:
+                case = v('testConnect')
+                connector = case.getConnector()
+                try:
+                    connector.connect()
+                    connector.close()
+                except connector.error:
+                    sys.stderr.write('Warning: could not open a '
+                                     'connection using %s. Skipping %s.\n'
+                                     % (repr(mname), k))
+                else:
+                    suite.addTest(unittest.makeSuite(v, 'test'))
+    return suite
+
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main(defaultTest='test_suite')