From d6174283bc68bc64b0ec284a8c9d67e123b88401 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 3 Jan 2006 00:36:45 +0000 Subject: [PATCH] added binary unit tests moved datetest to the types module --- test/engines.py | 9 ++++--- test/query.py | 27 ------------------- test/types.py | 69 ++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/test/engines.py b/test/engines.py index c84df433e5..0ab3cb3e65 100644 --- a/test/engines.py +++ b/test/engines.py @@ -21,10 +21,11 @@ class EngineTest(PersistTest): Column('test3', TEXT), Column('test4', DECIMAL, nullable = False), Column('test5', TIMESTAMP), - Column('parent_user_id', INT, ForeignKey('engine_users.user_id')), - Column('test6', DATETIME, nullable = False), - Column('test7', CLOB), - Column('test8', BLOB), + Column('parent_user_id', Integer, ForeignKey('engine_users.user_id')), + Column('test6', DateTime, nullable = False), + Column('test7', String), + Column('test8', Binary), + Column('test9', Binary(100)), ) diff --git a/test/query.py b/test/query.py index 9458938441..942362caa4 100644 --- a/test/query.py +++ b/test/query.py @@ -40,33 +40,6 @@ class QueryTest(PersistTest): self.users.update(self.users.c.user_id == 7).execute(user_name = 'fred') print repr(self.users.select().execute().fetchall()) - def testselectdate(self): - users_with_date = Table('query_users_with_date', db, - Column('user_id', INT, primary_key = True), - Column('user_name', VARCHAR(20)), - Column('user_date', DateTime), - redefine = True - ) - users_with_date.create() - - c = db.connection() - users_with_date.insert().execute(user_id = 7, user_name = 'jack', user_date=datetime.datetime(2005,11,10)) - users_with_date.insert().execute(user_id = 8, user_name = 'roy', user_date=datetime.datetime(2005,11,10, 11,52,35)) - users_with_date.insert().execute(user_id = 9, user_name = 'foo', user_date=datetime.datetime(2005,11,10, 11,52,35, 54839)) - users_with_date.insert().execute(user_id = 10, user_name = 'colber', user_date=None) - l = users_with_date.select().execute().fetchall() - l = [[c for c in r] for r in l] - if db.engine.__module__.endswith('mysql'): - x = [[7, 'jack', datetime.datetime(2005, 11, 10, 0, 0)], [8, 'roy', datetime.datetime(2005, 11, 10, 11, 52, 35)], [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35)], [10, 'colber', None]] - else: - x = [[7, 'jack', datetime.datetime(2005, 11, 10, 0, 0)], [8, 'roy', datetime.datetime(2005, 11, 10, 11, 52, 35)], [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35, 54839)], [10, 'colber', None]] - print repr(l) - print repr(x) - try: - self.assert_(l == x) - finally: - users_with_date.drop() - def testdefaults(self): x = {'x':0} def mydefault(): diff --git a/test/types.py b/test/types.py index 70cc1500fc..8c1f099260 100644 --- a/test/types.py +++ b/test/types.py @@ -1,13 +1,11 @@ from sqlalchemy import * +import string,datetime, re +from testbase import PersistTest, AssertMixin import testbase -import string - - -class TypesTest(testbase.PersistTest): - def setUpAll(self): - global db - db = testbase.db +db = testbase.db + +class TypesTest(PersistTest): def testprocessing(self): class MyType(types.TypeEngine): @@ -40,6 +38,63 @@ class TypesTest(testbase.PersistTest): l = users.select(use_labels=True).execute().fetchall() print repr(l) self.assert_(l == [(2, u'BIND_INjackBIND_OUT'), (3, u'BIND_INlalaBIND_OUT'), (4, u'BIND_INfredBIND_OUT')]) + +class BinaryTest(AssertMixin): + def setUpAll(self): + global binary_table + binary_table = Table('binary_table', db, + Column('primary_id', Integer, primary_key=True), + Column('data', Binary), + Column('data_slice', Binary(100)), + Column('misc', String(30))) + binary_table.create() + def tearDownAll(self): + binary_table.drop() + def testbinary(self): + stream1 =self.get_module_stream('sqlalchemy.sql') + stream2 =self.get_module_stream('sqlalchemy.engine') + binary_table.insert().execute(misc='sql.pyc', data=stream1, data_slice=stream1[0:100]) + binary_table.insert().execute(misc='engine.pyc', data=stream2, data_slice=stream2[0:99]) + l = binary_table.select().execute().fetchall() + print len(stream1), len(l[0]['data']), len(l[0]['data_slice']) + self.assert_(list(stream1) == list(l[0]['data'])) + self.assert_(list(stream1[0:100]) == list(l[0]['data_slice'])) + self.assert_(list(stream2) == list(l[1]['data'])) + def get_module_stream(self, name): + mod = __import__(name) + for token in name.split('.')[1:]: + mod = getattr(mod, token) + f = mod.__file__ + f = re.sub('\.py$', '\.pyc', f) + return file(f).read() + +class DateTest(AssertMixin): + def setUpAll(self): + global users_with_date + users_with_date = Table('query_users_with_date', db, + Column('user_id', INT, primary_key = True), + Column('user_name', VARCHAR(20)), + Column('user_date', DateTime), + redefine = True + ) + users_with_date.create() + def tearDownAll(self): + users_with_date.drop() + + def testdate(self): + users_with_date.insert().execute(user_id = 7, user_name = 'jack', user_date=datetime.datetime(2005,11,10)) + users_with_date.insert().execute(user_id = 8, user_name = 'roy', user_date=datetime.datetime(2005,11,10, 11,52,35)) + users_with_date.insert().execute(user_id = 9, user_name = 'foo', user_date=datetime.datetime(2005,11,10, 11,52,35, 54839)) + users_with_date.insert().execute(user_id = 10, user_name = 'colber', user_date=None) + l = users_with_date.select().execute().fetchall() + l = [[c for c in r] for r in l] + if db.engine.__module__.endswith('mysql'): + x = [[7, 'jack', datetime.datetime(2005, 11, 10, 0, 0)], [8, 'roy', datetime.datetime(2005, 11, 10, 11, 52, 35)], [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35)], [10, 'colber', None]] + else: + x = [[7, 'jack', datetime.datetime(2005, 11, 10, 0, 0)], [8, 'roy', datetime.datetime(2005, 11, 10, 11, 52, 35)], [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35, 54839)], [10, 'colber', None]] + print repr(l) + print repr(x) + self.assert_(l == x) if __name__ == "__main__": -- 2.47.2