Пример #1
0
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))
Пример #2
0
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')
Пример #3
0
 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'))))))
Пример #4
0
def thrower(marker):
    """
    Tracing interceptor that raises an asynchronous exception.
    """
    return around(lambda context: fail(TracingError(marker)),
                  lambda context: trace(context, 'leave', marker), 'thrower')
Пример #5
0
def tracer(marker):
    """
    Tracing interceptor.
    """
    return around(lambda context: trace(context, 'enter', marker),
                  lambda context: trace(context, 'leave', marker), 'tracer')