Commit 4a043df9 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 42780810
......@@ -78,34 +78,6 @@ def teardown_function(f):
os.rmdir(testmntpt)
# xdefer is like defer, but makes sure exception raised before deferred
# function is called is not lost.
#
# if deferred function raises exception itself - it prints previous exception to stderr.
#
# XXX xdefer is workaround for Python2 not having exception chanining (PEP 3134)
# without which, if e.g. tDB.close() raises exception, it prevents to see
# whether and which an assert in the test failed.
#
# XXX merge into defer?
def xdefer(f):
# hack - imitate as if defer called from under xdefer was called directly by caller func
fgo = inspect.currentframe().f_back.f_back
__goframe__ = fgo.f_locals['__goframe__']
_xdefer(f)
def _xdefer(f):
def _():
# call f, but print previous exception if f raises
exc_type, exc_value, exc_traceback = sys.exc_info()
try:
f()
except:
traceback.print_exception(exc_type, exc_value, exc_traceback)
raise
defer(_)
# many tests need to be run with some reasonable timeout to detect lack of wcfs
# response. with_timout and timeout provides syntatic shortcuts to do so.
def with_timeout(parent=context.background()): # -> ctx, cancel
......@@ -1339,3 +1311,31 @@ def dump_history(t):
print('\t%s\t%s' % (t.hat(dF.rev), ' '.join(emitv)))
print()
# xdefer is like defer, but makes sure exception raised before deferred
# function is called is not lost.
#
# if deferred function raises exception itself - it prints previous exception to stderr.
#
# XXX xdefer is workaround for Python2 not having exception chanining (PEP 3134)
# without which, if e.g. tDB.close() raises exception, it prevents to see
# whether and which an assert in the test failed.
#
# XXX merge into defer?
def xdefer(f):
# hack - imitate as if defer called from under xdefer was called directly by caller func
fgo = inspect.currentframe().f_back.f_back
__goframe__ = fgo.f_locals['__goframe__']
_xdefer(f)
def _xdefer(f):
def _():
# call f, but print previous exception if f raises
exc_type, exc_value, exc_traceback = sys.exc_info()
try:
f()
except:
traceback.print_exception(exc_type, exc_value, exc_traceback)
raise
defer(_)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment