summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/engines.py8
-rw-r--r--test/inheritance.py8
-rw-r--r--test/query.py6
-rw-r--r--test/testbase.py23
4 files changed, 30 insertions, 15 deletions
diff --git a/test/engines.py b/test/engines.py
index 7cc07ddda..aeb962c9b 100644
--- a/test/engines.py
+++ b/test/engines.py
@@ -58,8 +58,6 @@ class EngineTest(PersistTest):
mysql_engine='InnoDB'
)
- print repr(users)
- print repr(addresses)
# users.c.parent_user_id.set_foreign_key(ForeignKey(users.c.user_id))
@@ -69,14 +67,14 @@ class EngineTest(PersistTest):
# clear out table registry
users.deregister()
addresses.deregister()
-
+
try:
users = Table('engine_users', testbase.db, autoload = True)
addresses = Table('engine_email_addresses', testbase.db, autoload = True)
finally:
addresses.drop()
users.drop()
-
+
users.create()
addresses.create()
try:
@@ -86,6 +84,8 @@ class EngineTest(PersistTest):
# we can now as long as we use InnoDB
# if testbase.db.engine.__module__.endswith('mysql'):
# addresses.c.remote_user_id.append_item(ForeignKey('engine_users.user_id'))
+ print users
+ print addresses
j = join(users, addresses)
print str(j.onclause)
self.assert_((users.c.user_id==addresses.c.remote_user_id).compare(j.onclause))
diff --git a/test/inheritance.py b/test/inheritance.py
index 82d66e48c..4400cab89 100644
--- a/test/inheritance.py
+++ b/test/inheritance.py
@@ -139,8 +139,10 @@ class InheritTest2(testbase.AssertMixin):
b = Bar('barfoo')
objectstore.commit()
- b.foos.append(Foo('subfoo1'))
- b.foos.append(Foo('subfoo2'))
+ f1 = Foo('subfoo1')
+ f2 = Foo('subfoo2')
+ b.foos.append(f1)
+ b.foos.append(f2)
objectstore.commit()
objectstore.clear()
@@ -150,7 +152,7 @@ class InheritTest2(testbase.AssertMixin):
print l[0].foos
self.assert_result(l, Bar,
# {'id':1, 'data':'barfoo', 'bid':1, 'foos':(Foo, [{'id':2,'data':'subfoo1'}, {'id':3,'data':'subfoo2'}])},
- {'id':1, 'data':'barfoo', 'foos':(Foo, [{'id':2,'data':'subfoo1'}, {'id':3,'data':'subfoo2'}])},
+ {'id':b.id, 'data':'barfoo', 'foos':(Foo, [{'id':f1.id,'data':'subfoo1'}, {'id':f2.id,'data':'subfoo2'}])},
)
diff --git a/test/query.py b/test/query.py
index 8c732b75a..cf0bc94d3 100644
--- a/test/query.py
+++ b/test/query.py
@@ -47,7 +47,7 @@ class QueryTest(PersistTest):
that PassiveDefault upon insert, even though PassiveDefault says
"let the database execute this", because in postgres we must have all the primary
key values in memory before insert; otherwise we cant locate the just inserted row."""
- if not db.engine.__module__.endswith('postgres'):
+ if db.engine.name != 'postgres':
return
try:
db.execute("""
@@ -96,8 +96,8 @@ class QueryTest(PersistTest):
x['x'] += 1
return x['x']
- use_function_defaults = db.engine.__module__.endswith('postgres') or db.engine.__module__.endswith('oracle')
- is_oracle = db.engine.__module__.endswith('oracle')
+ use_function_defaults = db.engine.name == 'postgres' or db.engine.name == 'oracle'
+ is_oracle = db.engine.name == 'oracle'
# select "count(1)" from the DB which returns different results
# on different DBs
diff --git a/test/testbase.py b/test/testbase.py
index cdd0d6a33..2a9094f5d 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -1,6 +1,7 @@
import unittest
import StringIO
import sqlalchemy.engine as engine
+import sqlalchemy.ext.proxy
import re, sys
echo = True
@@ -15,14 +16,22 @@ def parse_argv():
global db, db_uri
DBTYPE = 'sqlite'
-
+ PROXY = False
+
if len(sys.argv) >= 3:
if sys.argv[1] == '--dburi':
(param, db_uri) = (sys.argv.pop(1), sys.argv.pop(1))
elif sys.argv[1] == '--db':
(param, DBTYPE) = (sys.argv.pop(1), sys.argv.pop(1))
+
if (None == db_uri):
+ p = DBTYPE.split('.')
+ if len(p) > 1:
+ arg = p[0]
+ DBTYPE = p[1]
+ if arg == 'proxy':
+ PROXY = True
if DBTYPE == 'sqlite':
db_uri = 'sqlite://filename=:memory:'
elif DBTYPE == 'sqlite_file':
@@ -37,7 +46,11 @@ def parse_argv():
if not db_uri:
raise "Could not create engine. specify --db <sqlite|sqlite_file|postgres|mysql|oracle> to test runner."
- db = engine.create_engine(db_uri, echo=echo, default_ordering=True)
+ if PROXY:
+ db = sqlalchemy.ext.proxy.ProxyEngine(echo=echo, default_ordering=True)
+ db.connect(db_uri)
+ else:
+ db = engine.create_engine(db_uri, echo=echo, default_ordering=True)
db = EngineAssert(db)
class PersistTest(unittest.TestCase):
@@ -75,7 +88,7 @@ class AssertMixin(PersistTest):
else:
self.assert_(getattr(rowobj, key) == value, "attribute %s value %s does not match %s" % (key, getattr(rowobj, key), value))
def assert_sql(self, db, callable_, list, with_sequences=None):
- if with_sequences is not None and (db.engine.__module__.endswith('postgres') or db.engine.__module__.endswith('oracle')):
+ if with_sequences is not None and (db.engine.name == 'postgres' or db.engine.name == 'oracle'):
db.set_assert_list(self, with_sequences)
else:
db.set_assert_list(self, list)
@@ -89,13 +102,13 @@ class AssertMixin(PersistTest):
callable_()
finally:
self.assert_(db.sql_count == count, "desired statement count %d does not match %d" % (count, db.sql_count))
-
+
class EngineAssert(object):
"""decorates a SQLEngine object to match the incoming queries against a set of assertions."""
def __init__(self, engine):
self.engine = engine
self.realexec = engine.post_exec
- engine.post_exec = self.post_exec
+ self.realexec.im_self.post_exec = self.post_exec
self.logger = engine.logger
self.set_assert_list(None, None)
self.sql_count = 0