diff options
author | Jason Kirtland <jek@discorporate.us> | 2007-05-25 22:48:42 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2007-05-25 22:48:42 +0000 |
commit | 91e8b20f52e20bae6c9b75ee41eeba13ca676313 (patch) | |
tree | 1e84bf09c737f9fb3723c4bbc2d65992f24bd7f7 /test/dialect/mysql.py | |
parent | bb02957181911989ec0e92dd555de41c9287f07a (diff) | |
download | sqlalchemy-91e8b20f52e20bae6c9b75ee41eeba13ca676313.tar.gz |
- Nearly all MySQL column types are now supported for declaration and
reflection. Added NCHAR, NVARCHAR, VARBINARY, TINYBLOB, LONGBLOB, YEAR
- The sqltypes.Binary passthrough now builds a VARBINARY rather than a
BINARY if given a length
- Refactored the inheritance of some types with respect to sqltypes, and
especially the binary types
- Lots and lots of docs
- MySQL unit tests now starting to adapt to known problems with alpha/beta
drivers
- A couple mysql unit test fix-ups and expansions
Diffstat (limited to 'test/dialect/mysql.py')
-rw-r--r-- | test/dialect/mysql.py | 104 |
1 files changed, 89 insertions, 15 deletions
diff --git a/test/dialect/mysql.py b/test/dialect/mysql.py index c74de74ee..75c8c0166 100644 --- a/test/dialect/mysql.py +++ b/test/dialect/mysql.py @@ -223,7 +223,7 @@ class TypesTest(AssertMixin): self.assertEqual(spec(enum_table.c.e2), """e2 ENUM("a",'b') NOT NULL""") self.assertEqual(spec(enum_table.c.e3), """e3 ENUM("a",'b')""") self.assertEqual(spec(enum_table.c.e4), """e4 ENUM("a",'b') NOT NULL""") - enum_table.drop() + enum_table.drop(checkfirst=True) enum_table.create() try: @@ -244,26 +244,100 @@ class TypesTest(AssertMixin): # Insert out of range enums, push stderr aside to avoid expected # warnings cluttering test output - try: - aside = sys.stderr - sys.stderr = StringIO.StringIO() - - con = db.connect() - self.assert_(not con.connection.show_warnings()) + con = db.connect() + if not hasattr(con.connection, 'show_warnings'): con.execute(insert(enum_table, {'e1':'c', 'e2':'c', 'e3':'a', 'e4':'a'})) - self.assert_(con.connection.show_warnings()) - finally: - sys.stderr = aside + else: + try: + aside = sys.stderr + sys.stderr = StringIO.StringIO() + + self.assert_(not con.connection.show_warnings()) + + con.execute(insert(enum_table, {'e1':'c', 'e2':'c', + 'e3':'a', 'e4':'a'})) + + self.assert_(con.connection.show_warnings()) + finally: + sys.stderr = aside res = enum_table.select().execute().fetchall() - # This is known to fail with MySQLDB versions < 1.2.2 - self.assertEqual(res, [(None, 'a', None, 'a'), - ('a', 'a', 'a', 'a'), - ('b', 'b', 'b', 'b'), - ('', '', 'a', 'a')]) + expected = [(None, 'a', None, 'a'), + ('a', 'a', 'a', 'a'), + ('b', 'b', 'b', 'b'), + ('', '', 'a', 'a')] + + # This is known to fail with MySQLDB 1.2.2 beta versions + # which return these as sets.Set(['a']), sets.Set(['b']) + # (even on Pythons with __builtin__.set) + if db.dialect.dbapi.version_info < (1, 2, 2, 'beta', 3) and \ + db.dialect.dbapi.version_info >= (1, 2, 2): + # these mysqldb seem to always uses 'sets', even on later pythons + import sets + def convert(value): + if value is None: + return value + if value == '': + return sets.Set([]) + else: + return sets.Set([value]) + + e = [] + for row in expected: + e.append(tuple([convert(c) for c in row])) + expected = e + + self.assertEqual(res, expected) enum_table.drop() + @testbase.supported('mysql') + def test_type_reflection(self): + # (ask_for, roundtripped_as_if_different) + specs = [( String(), mysql.MSText(), ), + ( String(1), mysql.MSString(1), ), + ( String(3), mysql.MSString(3), ), + ( mysql.MSChar(1), ), + ( mysql.MSChar(3), ), + ( NCHAR(2), mysql.MSChar(2), ), + ( mysql.MSNChar(2), mysql.MSChar(2), ), # N is CREATE only + ( mysql.MSNVarChar(22), mysql.MSString(22), ), + ( Smallinteger(), mysql.MSSmallInteger(), ), + ( Smallinteger(4), mysql.MSSmallInteger(4), ), + ( mysql.MSSmallInteger(), ), + ( mysql.MSSmallInteger(4), mysql.MSSmallInteger(4), ), + ( Binary(3), mysql.MSVarBinary(3), ), + ( Binary(), mysql.MSBlob() ), + ( mysql.MSBinary(3), mysql.MSBinary(3), ), + ( mysql.MSBaseBinary(), mysql.MSBlob(), ), + ( mysql.MSBaseBinary(3), mysql.MSVarBinary(3), ), + ( mysql.MSVarBinary(3),), + ( mysql.MSVarBinary(), mysql.MSBlob()), + ( mysql.MSTinyBlob(),), + ( mysql.MSBlob(),), + ( mysql.MSBlob(1234), mysql.MSBlob()), + ( mysql.MSMediumBlob(),), + ( mysql.MSLongBlob(),), + ] + + columns = [Column('c%i' % (i + 1), t[0]) for i, t in enumerate(specs)] + + m = BoundMetaData(db) + t_table = Table('mysql_types', m, *columns) + m.drop_all() + m.create_all() + + m2 = BoundMetaData(db) + rt = Table('mysql_types', m2, autoload=True) + + expected = [len(c) > 1 and c[1] or c[0] for c in specs] + for i, reflected in enumerate(rt.c): + #print (reflected, specs[i][0], '->', + # reflected.type, '==', expected[i]) + assert type(reflected.type) == type(expected[i]) + + #m.drop_all() + if __name__ == "__main__": testbase.main() |