File: test_logbook.py

package info (click to toggle)
logbook 1.7.0-1.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,140 kB
  • sloc: python: 6,558; makefile: 141
file content (33 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pytest

import logbook


def test_global_functions(activation_strategy):
    with activation_strategy(logbook.TestHandler()) as handler:
        logbook.debug("a debug message")
        logbook.info("an info message")
        logbook.warn("warning part 1")
        logbook.warning("warning part 2")
        logbook.notice("notice")
        logbook.error("an error")
        logbook.critical("pretty critical")
        logbook.log(logbook.CRITICAL, "critical too")

    assert handler.has_debug("a debug message")
    assert handler.has_info("an info message")
    assert handler.has_warning("warning part 1")
    assert handler.has_warning("warning part 2")
    assert handler.has_notice("notice")
    assert handler.has_error("an error")
    assert handler.has_critical("pretty critical")
    assert handler.has_critical("critical too")
    assert handler.records[0].channel == "Generic"
    assert handler.records[0].dispatcher is None


def test_level_lookup_failures():
    with pytest.raises(LookupError):
        logbook.get_level_name(37)
    with pytest.raises(LookupError):
        logbook.lookup_level("FOO")