def deferrer(marker, clock, delay): """ Tracing interceptor that returns a delayed result. """ return around( lambda context: deferLater(clock, delay, lambda: trace( context, 'enter', marker)), lambda context: trace(context, 'leave', marker))
def thrower_sync(marker): """ Tracing interceptor that raises a synchronous exception. """ def _enter(context): raise TracingError(marker) return around(_enter, lambda context: trace(context, 'leave', marker), 'thrower_sync')
def test_around(self): """ Interceptor only has an enter and leave function. """ interceptors = [ tracer('a'), around(tracing('enter', 'b'), tracing('leave', 'b')), tracer('c') ] self.assertThat( execute(empty_context, interceptors), succeeded( Traced( Equals( v(('enter', 'a'), ('enter', 'b'), ('enter', 'c'), ('leave', 'c'), ('leave', 'b'), ('leave', 'a'))))))
def thrower(marker): """ Tracing interceptor that raises an asynchronous exception. """ return around(lambda context: fail(TracingError(marker)), lambda context: trace(context, 'leave', marker), 'thrower')
def tracer(marker): """ Tracing interceptor. """ return around(lambda context: trace(context, 'enter', marker), lambda context: trace(context, 'leave', marker), 'tracer')