Пример #1
0
def test_loggers_from_logcfg_empty():
    logcfg = plugin.LoggerConfig()

    loggers = plugin._loggers_from_logcfg(logcfg, [])
    assert loggers.stdout == []
    assert loggers.file == []
    assert not loggers
Пример #2
0
def test_loggers_from_logcfg():
    logcfg = plugin.LoggerConfig()
    logcfg.add_loggers(['a', 'b', 'c'], stdout_level=logging.ERROR, file_level='warn')
    logcfg.add_loggers(['d'], stdout_level='10')

    log_option = [('b', logging.FATAL), 'd']

    loggers = plugin._loggers_from_logcfg(logcfg, log_option)
    assert loggers.stdout == [('b', logging.FATAL), ('d', 10)]
    assert loggers.file == [('a', logging.WARN), ('b', logging.WARN), ('c', logging.WARN), ('d', 0)]
    assert loggers
Пример #3
0
def test_set_formatter_class():
    logcfg = plugin.LoggerConfig()

    logcfg.set_formatter_class(logging.Formatter)
    logcfg.set_formatter_class(plugin.DefaultFormatter)

    with pytest.raises(ValueError) as e:
        logcfg.set_formatter_class(plugin.DefaultFormatter())
    assert str(e.value) == 'Got a formatter instance instead of its class !'
    with pytest.raises(ValueError) as e:
        logcfg.set_formatter_class(plugin.LoggerState)
    assert str(e.value) == 'Formatter should be a class inheriting from logging.Formatter'
    with pytest.raises(TypeError) as e:
        logcfg.set_formatter_class(10)
    assert str(e.value) == 'issubclass() arg 1 must be a class'
Пример #4
0
def test_split_by_outcome_wrong_config():
    logcfg = plugin.LoggerConfig()
    with pytest.raises(ValueError, match="got unexpected_outcomes: <\\['sthelese'\\]>"):
        logcfg.split_by_outcome(outcomes=['failed', 'sthelese'])