Esempio n. 1
0
def test_parse_lines_invalid():
    with (Path(__file__).with_name('data') /
          'vhost_combined.log').open() as fp:
        entries = parse_lines(VHOST_COMBINED, fp)
        assert next(entries) == VHOST_COMBINED_LOG_ENTRIES[0]
        assert next(entries) == VHOST_COMBINED_LOG_ENTRIES[1]
        assert next(entries) == VHOST_COMBINED_LOG_ENTRIES[2]
        assert next(entries) == VHOST_COMBINED_LOG_ENTRIES[3]
        with pytest.raises(InvalidEntryError) as excinfo:
            next(entries)
        assert str(excinfo.value) == (
            "Could not match log entry 'Bad line'"
            " against log format {!r}".format(VHOST_COMBINED))
        assert excinfo.value.entry == 'Bad line'
        assert excinfo.value.format == VHOST_COMBINED
Esempio n. 2
0
def test_parse_lines_custom_enc(mocker):
    m = mocker.patch('apachelogs.LogParser', spec=LogParser)
    r = parse_lines('%s', ['200'], encoding='utf-8', errors='surrogateescape')
    m.assert_called_once_with('%s', encoding='utf-8', errors='surrogateescape')
    m.return_value.parse_lines.assert_called_once_with(['200'], False)
    assert r is m.return_value.parse_lines.return_value
Esempio n. 3
0
def test_parse_lines_default_enc(mocker):
    m = mocker.patch('apachelogs.LogParser', spec=LogParser)
    r = parse_lines('%s', ['200'])
    m.assert_called_once_with('%s', encoding='iso-8859-1', errors=None)
    m.return_value.parse_lines.assert_called_once_with(['200'], False)
    assert r is m.return_value.parse_lines.return_value
Esempio n. 4
0
def test_parse_lines_ignore_invalid():
    with (Path(__file__).with_name('data') /
          'vhost_combined.log').open() as fp:
        entries = parse_lines(VHOST_COMBINED, fp, ignore_invalid=True)
        assert list(entries) == VHOST_COMBINED_LOG_ENTRIES
Esempio n. 5
0
def test_parse_lines_custom_enc(mocker):
    m = mocker.patch("apachelogs.LogParser", spec=LogParser)
    r = parse_lines("%s", ["200"], encoding="utf-8", errors="surrogateescape")
    m.assert_called_once_with("%s", encoding="utf-8", errors="surrogateescape")
    m.return_value.parse_lines.assert_called_once_with(["200"], False)
    assert r is m.return_value.parse_lines.return_value
Esempio n. 6
0
def test_parse_lines_default_enc(mocker):
    m = mocker.patch("apachelogs.LogParser", spec=LogParser)
    r = parse_lines("%s", ["200"])
    m.assert_called_once_with("%s", encoding="iso-8859-1", errors=None)
    m.return_value.parse_lines.assert_called_once_with(["200"], False)
    assert r is m.return_value.parse_lines.return_value