diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-02-12 16:43:26 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-02-12 16:43:26 -0500 |
commit | c710f6cbf6a02c275974b73d65a45af4bea1f55e (patch) | |
tree | 25c6d6d57df830b120b68e3e15de7922c92df153 /test/lib/testing.py | |
parent | 8c1bf8cdd0f510173534aeccda45a44bb7ed4626 (diff) | |
download | sqlalchemy-c710f6cbf6a02c275974b73d65a45af4bea1f55e.tar.gz |
- add a context manager availble via Engine.begin()
- add a test suite for all the Engine/Connection/TLEngine transaction/begin
helpers/context managers
- update docs
Diffstat (limited to 'test/lib/testing.py')
-rw-r--r-- | test/lib/testing.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/lib/testing.py b/test/lib/testing.py index 15f85aaf8..cea11095b 100644 --- a/test/lib/testing.py +++ b/test/lib/testing.py @@ -477,6 +477,26 @@ def _chain_decorators_on(fn, *decorators): fn = decorator(fn) return fn +def run_as_contextmanager(ctx, fn, *arg, **kw): + """Run the given function under the given contextmanager, + simulating the behavior of 'with' to support older + Python versions. + + """ + + obj = ctx.__enter__() + try: + result = fn(obj, *arg, **kw) + ctx.__exit__(None, None, None) + return result + except: + exc_info = sys.exc_info() + raise_ = ctx.__exit__(*exc_info) + if raise_ is None: + raise + else: + return raise_ + def rowset(results): """Converts the results of sql execution into a plain set of column tuples. |