MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / run_as_contextmanager

Function run_as_contextmanager

lib/sqlalchemy/testing/util.py:197–219  ·  view source on GitHub ↗

Run the given function under the given contextmanager, simulating the behavior of 'with' to support older Python versions. This is not necessary anymore as we have placed 2.6 as minimum Python version, however some tests are still using this structure.

(ctx, fn, *arg, **kw)

Source from the content-addressed store, hash-verified

195
196
197def run_as_contextmanager(ctx, fn, *arg, **kw):
198 """Run the given function under the given contextmanager,
199 simulating the behavior of 'with' to support older
200 Python versions.
201
202 This is not necessary anymore as we have placed 2.6
203 as minimum Python version, however some tests are still using
204 this structure.
205
206 """
207
208 obj = ctx.__enter__()
209 try:
210 result = fn(obj, *arg, **kw)
211 ctx.__exit__(None, None, None)
212 return result
213 except:
214 exc_info = sys.exc_info()
215 raise_ = ctx.__exit__(*exc_info)
216 if not raise_:
217 raise
218 else:
219 return raise_
220
221
222def rowset(results):

Callers

nothing calls this directly

Calls 2

__enter__Method · 0.45
__exit__Method · 0.45

Tested by

no test coverage detected