From: Mike Bayer Date: Fri, 17 Feb 2006 04:49:04 +0000 (+0000) Subject: fix to types test, postgres time types descend from Time type X-Git-Tag: rel_0_1_1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6ccddde2102d9b5e5a0c4c51d9b3429e4085e0d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix to types test, postgres time types descend from Time type --- diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index dab14b460d..d93a084ee5 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -62,10 +62,10 @@ class PG1Date(sqltypes.Date): return value def get_col_spec(self): return "DATE" -class PG2Time(sqltypes.Date): +class PG2Time(sqltypes.Time): def get_col_spec(self): return "TIME" -class PG1Time(sqltypes.Date): +class PG1Time(sqltypes.Time): def convert_bind_param(self, value, engine): # TODO: perform appropriate postgres1 conversion between Python DateTime/MXDateTime # this one doesnt seem to work with the "emulation" mode diff --git a/test/alltests.py b/test/alltests.py index 83b1647318..3fe704e93f 100644 --- a/test/alltests.py +++ b/test/alltests.py @@ -15,7 +15,7 @@ def suite(): # schema/tables 'engines', - 'types', + 'testtypes', # SQL syntax 'select', @@ -46,7 +46,6 @@ def suite(): #'wsgi_test', ) - alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(unittest.findTestCases(module, suiteClass=None)) diff --git a/test/types.py b/test/testtypes.py similarity index 89% rename from test/types.py rename to test/testtypes.py index 77452e51b1..3ea868ac90 100644 --- a/test/types.py +++ b/test/testtypes.py @@ -5,30 +5,41 @@ import testbase db = testbase.db +class MyType(types.TypeEngine): + def get_col_spec(self): + return "VARCHAR(100)" + def convert_bind_param(self, value, engine): + return "BIND_IN"+ value + def convert_result_value(self, value, engine): + return value + "BIND_OUT" + def adapt(self, typeobj): + return typeobj() + def adapt_args(self): + return self + +class MyDecoratedType(types.TypeDecorator, types.String): + def convert_bind_param(self, value, engine): + return "BIND_IN"+ value + def convert_result_value(self, value, engine): + return value + "BIND_OUT" + class OverrideTest(PersistTest): """tests user-defined types, including a full type as well as a TypeDecorator""" def testprocessing(self): - class MyType(types.TypeEngine): - def get_col_spec(self): - return "VARCHAR(100)" - def convert_bind_param(self, value, engine): - return "BIND_IN"+ value - def convert_result_value(self, value, engine): - return value + "BIND_OUT" - def adapt(self, typeobj): - return typeobj() - def adapt_args(self): - return self - - class MyDecoratedType(types.TypeDecorator, types.String): - def convert_bind_param(self, value, engine): - return "BIND_IN"+ value - def convert_result_value(self, value, engine): - return value + "BIND_OUT" global users - users = Table('users', db, + users.insert().execute(user_id = 2, goofy = 'jack', goofy2='jack', goofy3='jack') + users.insert().execute(user_id = 3, goofy = 'lala', goofy2='lala', goofy3='lala') + users.insert().execute(user_id = 4, goofy = 'fred', goofy2='fred', goofy3='fred') + + l = users.select().execute().fetchall() + print repr(l) + self.assert_(l == [(2, 'BIND_INjackBIND_OUT', 'BIND_INjackBIND_OUT', 'BIND_INjackBIND_OUT'), (3, 'BIND_INlalaBIND_OUT', 'BIND_INlalaBIND_OUT', 'BIND_INlalaBIND_OUT'), (4, 'BIND_INfredBIND_OUT', 'BIND_INfredBIND_OUT', 'BIND_INfredBIND_OUT')]) + + def setUpAll(self): + global users + users = Table('type_users', db, Column('user_id', Integer, primary_key = True), # totall custom type Column('goofy', MyType, nullable = False), @@ -41,16 +52,6 @@ class OverrideTest(PersistTest): ) users.create() - - users.insert().execute(user_id = 2, goofy = 'jack', goofy2='jack', goofy3='jack') - users.insert().execute(user_id = 3, goofy = 'lala', goofy2='lala', goofy3='lala') - users.insert().execute(user_id = 4, goofy = 'fred', goofy2='fred', goofy3='fred') - - l = users.select().execute().fetchall() - print repr(l) - self.assert_(l == [(2, 'BIND_INjackBIND_OUT', 'BIND_INjackBIND_OUT', 'BIND_INjackBIND_OUT'), (3, 'BIND_INlalaBIND_OUT', 'BIND_INlalaBIND_OUT', 'BIND_INlalaBIND_OUT'), (4, 'BIND_INfredBIND_OUT', 'BIND_INfredBIND_OUT', 'BIND_INfredBIND_OUT')]) - - def tearDownAll(self): global users users.drop() @@ -79,7 +80,7 @@ class ColumnsTest(AssertMixin): ) for aCol in testTable.c: - self.assertEquals(expectedResults[aCol.name], db.schemagenerator(None).get_column_specification(aCol)) + self.assertEquals(expectedResults[aCol.name], db.schemagenerator().get_column_specification(aCol)) class UnicodeTest(AssertMixin): """tests the Unicode type. also tests the TypeDecorator with instances in the types package.""" @@ -87,8 +88,8 @@ class UnicodeTest(AssertMixin): global unicode_table unicode_table = Table('unicode_table', db, Column('id', Integer, primary_key=True), - Column('unicode_data', Unicode(50)), - Column('plain_data', String) + Column('unicode_data', Unicode(250)), + Column('plain_data', String(250)) ) unicode_table.create() def tearDownAll(self):