]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Restored unicode foreign key tests for [ticket:729].
authorJason Kirtland <jek@discorporate.us>
Sun, 14 Oct 2007 18:35:51 +0000 (18:35 +0000)
committerJason Kirtland <jek@discorporate.us>
Sun, 14 Oct 2007 18:35:51 +0000 (18:35 +0000)
test/sql/unicode.py
test/testlib/testing.py

index 1b7698301190a0d7a819062406f8b448cb4de8b3..55f3f6bc561bf7997f59922eaeb867d0cb81ab08 100644 (file)
@@ -27,23 +27,32 @@ class UnicodeSchemaTest(PersistTest):
                    ),
                    test_needs_fk=True,
             )
-        t3 = Table(u'\u6e2c\u8a66', metadata,
-                   Column(u'\u6e2c\u8a66_id', Integer, primary_key=True,
-                          autoincrement=False),
-                   Column(u'unitable1_\u6e2c\u8a66', Integer,
-                            # lets leave these out for now so that PG tests pass, until
-                            # the test can be broken out into a pg-passing version (or we figure it out)
-                          #ForeignKey(u'unitable1.\u6e2c\u8a66')
-                          ),
-                   Column(u'Unitéble2_b', Integer,
-                         # ForeignKey(u'Unitéble2.b')
-                          ),
-                   Column(u'\u6e2c\u8a66_self', Integer,
-                        #  ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id')
-                          ),
-                          test_needs_fk=True,
-                          
-                          )
+
+        # Few DBs support Unicode foreign keys
+        if testing.against('sqlite'):
+            t3 = Table(u'\u6e2c\u8a66', metadata,
+                       Column(u'\u6e2c\u8a66_id', Integer, primary_key=True,
+                              autoincrement=False),
+                       Column(u'unitable1_\u6e2c\u8a66', Integer,
+                              ForeignKey(u'unitable1.\u6e2c\u8a66')
+                              ),
+                       Column(u'Unitéble2_b', Integer,
+                              ForeignKey(u'Unitéble2.b')
+                              ),
+                       Column(u'\u6e2c\u8a66_self', Integer,
+                              ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id')
+                              ),
+                       test_needs_fk=True,
+                       )
+        else:
+            t3 = Table(u'\u6e2c\u8a66', metadata,
+                       Column(u'\u6e2c\u8a66_id', Integer, primary_key=True,
+                              autoincrement=False),
+                       Column(u'unitable1_\u6e2c\u8a66', Integer),
+                       Column(u'Unitéble2_b', Integer),
+                       Column(u'\u6e2c\u8a66_self', Integer),
+                       test_needs_fk=True,
+                       )
         metadata.create_all()
 
     @testing.unsupported('oracle', 'sybase')
index 1c80c7bb13de5dbab6afe1fcfcda7f4631afd98c..74a2cb5cdb0153474fc5153b2d4d27b3e1de603a 100644 (file)
@@ -17,7 +17,9 @@ _ops = { '<': operator.lt,
          '!=': operator.ne,
          '<=': operator.le,
          '>=': operator.ge,
-         'in': operator.contains }
+         'in': operator.contains,
+         'between': lambda val, pair: val >= pair[0] and val <= pair[1],
+         }
 
 def unsupported(*dbs):
     """Mark a test as unsupported by one or more database implementations"""
@@ -91,7 +93,37 @@ def exclude(db, op, spec):
             pass
         return maybe
     return decorate
-        
+
+def against(*queries):
+    """Boolean predicate, compares to testing database configuration.
+
+    Given one or more dialect names, returns True if one is the configured
+    database engine.
+
+    Also supports comparison to database version when provided with one or
+    more 3-tuples of dialect name, operator, and version specification::
+
+      testing.against('mysql', 'postgres')
+      testing.against(('mysql', '>=', (5, 0, 0))
+    """
+
+    for query in queries:
+        if isinstance(query, basestring):
+            if config.db.name == query:
+                return True
+        else:
+            name, op, spec = query
+            if config.db.name != name:
+                continue
+
+            have = config.db.dialect.server_version_info(
+                config.db.contextual_connect())
+
+            oper = hasattr(op, '__call__') and op or _ops[op]
+            if oper(have, spec):
+                return True
+    return False
+
 class TestData(object):
     """Tracks SQL expressions as they are executed via an instrumented ExecutionContext."""