]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Improve utf8 engine handling during test setup and in test suites.
authorJason Kirtland <jek@discorporate.us>
Wed, 8 Aug 2007 20:19:23 +0000 (20:19 +0000)
committerJason Kirtland <jek@discorporate.us>
Wed, 8 Aug 2007 20:19:23 +0000 (20:19 +0000)
test/testlib/config.py
test/testlib/engines.py

index df2e81b0c705e3502bbdade583809ef46192b65d..77cacc820cd1cdf0dfcec4c1e7e9aa27b824c911 100644 (file)
@@ -1,5 +1,5 @@
 import testbase
-import optparse, os, sys, re, ConfigParser, StringIO, time
+import optparse, os, sys, re, ConfigParser, StringIO, time, warnings
 logging, require = None, None
 
 
@@ -205,21 +205,29 @@ def _prep_testing_database(options, file_config):
     from testlib import engines
     from sqlalchemy import schema
 
-    # also create alt schemas etc. here?
-    e = engines.utf8_engine()
-    existing = e.table_names()
-    if existing:
+    try:
+        # also create alt schemas etc. here?
+        e = engines.utf8_engine()
+        existing = e.table_names()
+        if existing:
+            if not options.quiet:
+                print "Dropping existing tables in database: " + db_url
+                try:
+                    print "Tables: %s" % ', '.join(existing)
+                except:
+                    pass
+                print "Abort within 5 seconds..."
+                time.sleep(5)
+            md = schema.MetaData(e, reflect=True)
+            md.drop_all()
+        e.dispose()
+    except (KeyboardInterrupt, SystemExit):
+        raise
+    except Exception, e:
         if not options.quiet:
-            print "Dropping existing tables in database: " + db_url
-            try:
-                print "Tables: %s" % ', '.join(existing)
-            except:
-                pass
-            print "Abort within 5 seconds..."
-            time.sleep(5)
-        md = schema.MetaData(e, reflect=True)
-        md.drop_all()
-    e.dispose()
+            warnings.warn(RuntimeWarning(
+                "Error checking for existing tables in testing "
+                "database: %s" % e))
 post_configure['prep_db'] = _prep_testing_database
 
 def _set_table_options(options, file_config):
index da337496775311e6ee741224be68e2fe1c963c98..addef3f9eeea2fcf8e1e76a9ec5bb002545020ff 100644 (file)
@@ -24,10 +24,17 @@ def utf8_engine(url=None, options=None):
     from sqlalchemy.engine import url as engine_url
 
     if config.db.name == 'mysql':
-        url = url or config.db_url
-        url = engine_url.make_url(url)
-        url.query['charset'] = 'utf8'
-        url.query['use_unicode'] = '0'
-        url = str(url)
+        dbapi_ver = config.db.dialect.dbapi.version_info
+        if (dbapi_ver < (1, 2, 1) or
+            dbapi_ver in ((1, 2, 1, 'gamma', 1), (1, 2, 1, 'gamma', 2),
+                          (1, 2, 1, 'gamma', 3), (1, 2, 1, 'gamma', 5))):
+            raise RuntimeError('Character set support unavailable with this '
+                               'driver version: %s' % repr(dbapi_ver))
+        else:
+            url = url or config.db_url
+            url = engine_url.make_url(url)
+            url.query['charset'] = 'utf8'
+            url.query['use_unicode'] = '0'
+            url = str(url)
 
     return testing_engine(url, options)