From: Mike Bayer Date: Sun, 28 May 2006 19:02:09 +0000 (+0000) Subject: extra tests... X-Git-Tag: rel_0_2_1~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abb24ed648f1d22805e46e2a504b2dfed342bab8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git extra tests... --- diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index d909cbeda2..84e5a7dc42 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -14,7 +14,12 @@ class TLSession(object): try: return self.__transaction except AttributeError: - return base.Connection(self.engine, close_with_result=close_with_result) + return TLConnection(self, close_with_result=close_with_result) + def set_transaction(self, tlconnection, trans): + if self.__tcount == 0: + self.__transaction = tlconnection + self.__trans = trans + self.__tcount += 1 def begin(self): if self.__tcount == 0: self.__transaction = self.get_connection() @@ -41,7 +46,12 @@ class TLSession(object): def is_begun(self): return self.__tcount > 0 - +class TLConnection(base.Connection): + def __init__(self, session, close_with_result): + base.Connection.__init__(self, session.engine, close_with_result=close_with_result) + self.__session = session + # TODO: get begin() to communicate with the Session to maintain the same transactional state + class TLEngine(base.ComposedSQLEngine): """a ComposedSQLEngine that includes support for thread-local managed transactions. This engine is better suited to be used with threadlocal Pool object.""" diff --git a/test/parseconnect.py b/test/parseconnect.py index e1f50e8c91..97061a6834 100644 --- a/test/parseconnect.py +++ b/test/parseconnect.py @@ -17,10 +17,12 @@ class ParseConnectTest(PersistTest): 'dbtype:///:memory:', 'dbtype:///foo/bar/im/a/file', 'dbtype:///E:/work/src/LEM/db/hello.db', - 'dbtype://' + 'dbtype://', + 'dbtype://username:password@/db' ): u = url.make_url(text) print u, text + print u.username, u.password, u.database assert str(u) == text diff --git a/test/testbase.py b/test/testbase.py index 17e42906b5..57fcb58c30 100644 --- a/test/testbase.py +++ b/test/testbase.py @@ -157,8 +157,6 @@ class MockPool(pool.Pool): raise "Invalid" def do_get(self): - if getattr(self, 'breakpoint', False): - raise "breakpoint" assert self.connection is not None c = self.connection self.connection = None diff --git a/test/transaction.py b/test/transaction.py index a009c447ca..42baff46d6 100644 --- a/test/transaction.py +++ b/test/transaction.py @@ -143,6 +143,13 @@ class TLTransactionTest(testbase.PersistTest): self.assert_(external_connection.scalar("select count(1) from query_users") == 0) finally: external_connection.close() + + def testconnections(self): + """tests that contextual_connect is threadlocal""" + c1 = tlengine.contextual_connect() + c2 = tlengine.contextual_connect() + assert c1.connection is c2.connection + c1.close() if __name__ == "__main__": testbase.main()