Пример #1
0
def test_missing_key_set_to_error():
    '''Test missing values raise KeyError when missing_key set to ERROR.'''
    log = Log(message='A message')

    template = Field(keys=['level', 'message'], missing_key=Field.ERROR)
    with pytest.raises(KeyError):
        template.format([log])
Пример #2
0
def test_include_remaining_keys(keys, expected):
    '''Test using '*' to include remaining keys in alphabetical order.'''
    log = Log(level='info', message='A message', a=3, b=2, z=1)

    template = Field(keys=keys)
    assert template.format([log]) == expected
Пример #3
0
def test_missing_key_set_to_substitute():
    '''Test missing values replaced when missing_key set to a substitute.'''
    log = Log(message='A message')
    template = Field(keys=['level', 'message'], missing_key='NOT_SET')
    assert template.format([log]) == ['level=NOT_SET:message=A message\n']
Пример #4
0
def test_missing_key_set_to_skip():
    '''Test missing values skipped when missing_key set to SKIP.'''
    log = Log(message='A message')
    template = Field(keys=['level', 'message'], missing_key=Field.SKIP)
    assert template.format([log]) == ['message=A message\n']
Пример #5
0
def test_alternative_separator():
    '''Test configuring the separator'''
    log = Log(message='A message', level='info')
    template = Field(keys=['level', 'message'], item_separator=', ')
    assert template.format([log]) == ['level=info, message=A message\n']
Пример #6
0
def test_alternative_template():
    '''Test configuring the template.'''
    log = Log(message='A message')

    template = Field(keys=['level', 'message'], template='{value}')
    assert template.format([log]) == ['A message\n']
Пример #7
0
def test_format():
    '''Test formatted log result is as expected.'''
    log = Log(message='A message', level='info')
    template = Field(keys=['level', 'message'])
    assert template.format([log]) == ['level=info:message=A message\n']