summaryrefslogtreecommitdiff
path: root/test/testbase.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-12-30 00:23:01 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-12-30 00:23:01 +0000
commit4372eafaabd71e0e3935bf4b3931f1a75ac0993c (patch)
tree79347bcb58dcbf6f08863b8cfb17ca28bbe2ff5e /test/testbase.py
parent1980102244b79275b231130fe510c24f1199304d (diff)
downloadsqlalchemy-4372eafaabd71e0e3935bf4b3931f1a75ac0993c.tar.gz
catching up oracle to current, some tweaks to unittests to work better with oracle,
allow different ordering of expected statements. unittests still dont work completely with oracle due to sequence columns in INSERT statements
Diffstat (limited to 'test/testbase.py')
-rw-r--r--test/testbase.py64
1 files changed, 43 insertions, 21 deletions
diff --git a/test/testbase.py b/test/testbase.py
index d08b58527..a5785f299 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -33,7 +33,7 @@ def parse_argv():
elif DBTYPE == 'mysql':
db = engine.create_engine('mysql://db=test&host=127.0.0.1&user=scott&passwd=tiger', echo=echo)
elif DBTYPE == 'oracle':
- db = engine.create_engine('oracle://db=test&host=127.0.0.1&user=scott&passwd=tiger', echo=echo)
+ db = engine.create_engine('oracle://user=scott&password=tiger', echo=echo)
db = EngineAssert(db)
class PersistTest(unittest.TestCase):
@@ -108,35 +108,57 @@ class EngineAssert(object):
statement = re.sub(r'\n', '', statement)
if self.assert_list is not None:
- item = self.assert_list.pop()
+ item = self.assert_list[-1]
+ if not isinstance(item, dict):
+ item = self.assert_list.pop()
+ else:
+ # asserting a dictionary of statements->parameters
+ # this is to specify query assertions where the queries can be in
+ # multiple orderings
+ if not item.has_key('_converted'):
+ for key in item.keys():
+ ckey = self.convert_statement(key)
+ item[ckey] = item[key]
+ if ckey != key:
+ del item[key]
+ item['_converted'] = True
+ try:
+ entry = item.pop(statement)
+ if len(item) == 1:
+ self.assert_list.pop()
+ item = (statement, entry)
+ print "OK ON", statement
+ except KeyError:
+ self.unittest.assert_(False, "Testing for one of the following queries: %s, received '%s'" % (repr([k for k in item.keys()]), statement))
+
(query, params) = item
if callable(params):
params = params()
- # deal with paramstyles of different engines
- paramstyle = self.engine.paramstyle
- if paramstyle == 'named':
- pass
- elif paramstyle =='pyformat':
- query = re.sub(r':([\w_]+)', r"%(\1)s", query)
- else:
- # positional params
- names = []
- repl = None
- if paramstyle=='qmark':
- repl = "?"
- elif paramstyle=='format':
- repl = r"%s"
- elif paramstyle=='numeric':
- repl = None
- counter = 0
- query = re.sub(r':([\w_]+)', repl, query)
+ query = self.convert_statement(query)
self.unittest.assert_(statement == query and params == parameters, "Testing for query '%s' params %s, received '%s' with params %s" % (query, repr(params), statement, repr(parameters)))
self.sql_count += 1
return self.realexec(proxy, compiled, parameters, **kwargs)
-
+ def convert_statement(self, query):
+ paramstyle = self.engine.paramstyle
+ if paramstyle == 'named':
+ pass
+ elif paramstyle =='pyformat':
+ query = re.sub(r':([\w_]+)', r"%(\1)s", query)
+ else:
+ # positional params
+ repl = None
+ if paramstyle=='qmark':
+ repl = "?"
+ elif paramstyle=='format':
+ repl = r"%s"
+ elif paramstyle=='numeric':
+ repl = None
+ query = re.sub(r':([\w_]+)', repl, query)
+ return query
+
class TTestSuite(unittest.TestSuite):
"""override unittest.TestSuite to provide per-TestCase class setUpAll() and tearDownAll() functionality"""
def __init__(self, tests=()):