File: test_qmessage_handler.py

package info (click to toggle)
superqt 0.7.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,320 kB
  • sloc: python: 9,108; makefile: 16; sh: 12
file content (36 lines) | stat: -rw-r--r-- 1,104 bytes parent folder | download | duplicates (3)
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
34
35
36
import logging

from qtpy import QtCore

from superqt import QMessageHandler


def test_message_handler():
    with QMessageHandler() as mh:
        QtCore.qDebug("debug")
        QtCore.qWarning("warning")
        QtCore.qCritical("critical")

    assert len(mh.records) == 3
    assert mh.records[0].level == logging.DEBUG
    assert mh.records[1].level == logging.WARNING
    assert mh.records[2].level == logging.CRITICAL

    assert "3 records" in repr(mh)


def test_message_handler_with_logger(caplog):
    logger = logging.getLogger("test_logger")
    caplog.set_level(logging.DEBUG, logger="test_logger")
    with QMessageHandler(logger):
        QtCore.qDebug("debug")
        QtCore.qWarning("warning")
        QtCore.qCritical("critical")

    assert len(caplog.records) == 3
    assert caplog.records[0].message == "debug"
    assert caplog.records[0].levelno == logging.DEBUG
    assert caplog.records[1].message == "warning"
    assert caplog.records[1].levelno == logging.WARNING
    assert caplog.records[2].message == "critical"
    assert caplog.records[2].levelno == logging.CRITICAL