From: Jason Kirtland Date: Sun, 14 Oct 2007 18:35:51 +0000 (+0000) Subject: Restored unicode foreign key tests for [ticket:729]. X-Git-Tag: rel_0_4_0~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79dafdf3d4ffe9cb56ee0b03651b92e7e7b7353e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Restored unicode foreign key tests for [ticket:729]. --- diff --git a/test/sql/unicode.py b/test/sql/unicode.py index 1b76983011..55f3f6bc56 100644 --- a/test/sql/unicode.py +++ b/test/sql/unicode.py @@ -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') diff --git a/test/testlib/testing.py b/test/testlib/testing.py index 1c80c7bb13..74a2cb5cdb 100644 --- a/test/testlib/testing.py +++ b/test/testlib/testing.py @@ -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."""