Commits

jason kirtland committed de11954

Restored unicode foreign key tests for [ticket:729].

Comments (0)

Files changed (2)

test/sql/unicode.py

                    ),
                    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')

test/testlib/testing.py

          '!=': 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"""
             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."""