mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-09-05 01:00:20 +02:00
* remove qtcompat * change imports * change codecov * add dep * run tests against dalthviz branch * update * more replace * pin pyside6 for sake of test * add deprecation * drop qt 5.11 * unpin pyside6
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
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
|
|
caplog.records[0].message == "debug"
|
|
caplog.records[0].levelno == logging.DEBUG
|
|
caplog.records[1].message == "warning"
|
|
caplog.records[1].levelno == logging.WARNING
|
|
caplog.records[2].message == "critical"
|
|
caplog.records[2].levelno == logging.CRITICAL
|