From d8bb3d987e39765c48116589b2d5d7c150095fa4 Mon Sep 17 00:00:00 2001 From: Sandro Date: Tue, 11 Mar 2025 16:12:08 +0100 Subject: [PATCH] Enable qInfo tests for PySide6 PySide6 now exposes `qInfo` just like Qt6. This enables the `qInfo` tests accordingly. For reference see issue #232. --- src/pytestqt/qt_compat.py | 9 +-------- tests/test_basics.py | 1 + tests/test_logging.py | 30 +++++------------------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/pytestqt/qt_compat.py b/src/pytestqt/qt_compat.py index d3aafde..3b9aef7 100644 --- a/src/pytestqt/qt_compat.py +++ b/src/pytestqt/qt_compat.py @@ -111,14 +111,7 @@ def _import_module(module_name): self._check_qt_api_version() - # qInfo is not exposed in PySide6 (#232) - if hasattr(QtCore, "QMessageLogger"): - self.qInfo = lambda msg: QtCore.QMessageLogger().info(msg) - elif hasattr(QtCore, "qInfo"): - self.qInfo = QtCore.qInfo - else: - self.qInfo = None - + self.qInfo = QtCore.qInfo self.qDebug = QtCore.qDebug self.qWarning = QtCore.qWarning self.qCritical = QtCore.qCritical diff --git a/tests/test_basics.py b/tests/test_basics.py index 85e24f1..6b577f5 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -613,6 +613,7 @@ class Mock: qtcore = Mock() for method_name in ( "qInstallMessageHandler", + "qInfo", "qDebug", "qWarning", "qCritical", diff --git a/tests/test_logging.py b/tests/test_logging.py index 80b694c..d5ad134 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -26,8 +26,7 @@ def print_msg(msg_type, context, message): qt_api.QtCore.qInstallMessageHandler(print_msg) def test_types(): - # qInfo is not exposed by the bindings yet (#225) - # qt_api.qInfo('this is an INFO message') + qt_api.qInfo('this is an INFO message') qt_api.qDebug('this is a DEBUG message') qt_api.qWarning('this is a WARNING message') qt_api.qCritical('this is a CRITICAL message') @@ -45,8 +44,7 @@ def test_types(): res.stdout.fnmatch_lines( [ "*-- Captured Qt messages --*", - # qInfo is not exposed by the bindings yet (#232) - # '*QtInfoMsg: this is an INFO message*', + "*QtInfoMsg: this is an INFO message*", "*QtDebugMsg: this is a DEBUG message*", "*QtWarningMsg: this is a WARNING message*", "*QtCriticalMsg: this is a CRITICAL message*", @@ -56,9 +54,7 @@ def test_types(): res.stdout.fnmatch_lines( [ "*-- Captured stderr call --*", - # qInfo is not exposed by the bindings yet (#232) - # '*QtInfoMsg: this is an INFO message*', - # 'this is an INFO message*', + "this is an INFO message*", "this is a DEBUG message*", "this is a WARNING message*", "this is a CRITICAL message*", @@ -66,33 +62,17 @@ def test_types(): ) -def test_qinfo(qtlog): - """Test INFO messages when we have means to do so. Should be temporary until bindings - catch up and expose qInfo (or at least QMessageLogger), then we should update - the other logging tests properly. #232 - """ - - if qt_api.is_pyside: - assert ( - qt_api.qInfo is None - ), "pyside6 does not expose qInfo. If it does, update this test." - return - - qt_api.qInfo("this is an INFO message") - records = [(m.type, m.message.strip()) for m in qtlog.records] - assert records == [(qt_api.QtCore.QtMsgType.QtInfoMsg, "this is an INFO message")] - - def test_qtlog_fixture(qtlog): """ Test qtlog fixture. """ - # qInfo is not exposed by the bindings yet (#232) + qt_api.qInfo("this is an INFO message") qt_api.qDebug("this is a DEBUG message") qt_api.qWarning("this is a WARNING message") qt_api.qCritical("this is a CRITICAL message") records = [(m.type, m.message.strip()) for m in qtlog.records] assert records == [ + (qt_api.QtCore.QtMsgType.QtInfoMsg, "this is an INFO message"), (qt_api.QtCore.QtMsgType.QtDebugMsg, "this is a DEBUG message"), (qt_api.QtCore.QtMsgType.QtWarningMsg, "this is a WARNING message"), (qt_api.QtCore.QtMsgType.QtCriticalMsg, "this is a CRITICAL message"),