Example #1
0
def test_dup_sink():
    log = Logger('test_exc_logger')
    agg_sink = AggregateSink()

    log.add_sink(agg_sink)
    log.add_sink(agg_sink)

    assert len(log.sinks) == 1
Example #2
0
def test_dup_sink():
    log = Logger('test_exc_logger')
    agg_sink = AggregateSink()

    log.add_sink(agg_sink)
    log.add_sink(agg_sink)

    assert len(log.sinks) == 1
Example #3
0
def test_comment():
    log = Logger('test_comment')

    events = []

    class ComSink(object):
        def on_comment(self, event):
            events.append(event)

    log.add_sink(ComSink())

    log.comment('the first')
    log.comment('the second')

    assert len(events) == 2
Example #4
0
def test_comment():
    log = Logger('test_comment')

    events = []

    class ComSink(object):
        def on_comment(self, event):
            events.append(event)

    log.add_sink(ComSink())

    log.comment('the first')
    log.comment('the second {}', 'commenting')

    assert len(events) == 2
Example #5
0
def test_exception():
    log = Logger('test_exc_logger')

    exc_list = []

    class ExcSink(object):
        def on_exception(self, event, etype, eobj, etb):
            exc_list.append(event)

    exc_sink = ExcSink()
    log.add_sink(exc_sink)

    try:
        with log.critical('raise_act'):
            raise RuntimeError('whooops')
    except RuntimeError:
        pass

    assert len(exc_list) == 1
    assert exc_list[0].exc_info.exc_type == 'RuntimeError'
Example #6
0
def test_exception():
    log = Logger('test_exc_logger')

    exc_list = []

    class ExcSink(object):
        def on_exception(self, event, etype, eobj, etb):
            exc_list.append(event)

    exc_sink = ExcSink()
    log.add_sink(exc_sink)

    try:
        with log.critical('raise_act'):
            raise RuntimeError('whooops')
    except RuntimeError:
        pass

    assert len(exc_list) == 1
    assert exc_list[0].exc_info.exc_type == 'RuntimeError'