Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for QtToolTipEventFilter #6066

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions napari/_qt/_tests/test_qt_event_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

from napari._qt.qt_event_filters import QtToolTipEventFilter

pytest.importorskip('qtpy', reason='Cannot test event filters without qtpy.')


@pytest.mark.parametrize(
"tooltip,is_qt_tag_present",
[
(
"<html>"
"<p>A widget to test that a rich text tooltip might be detected "
"and therefore not changed to include a qt tag</p>"
"</html>",
False,
),
(
"A widget to test that a non-rich text tooltip might "
"be detected and therefore changed",
True,
),
],
)
def test_qt_tooltip_event_filter(qtbot, tooltip, is_qt_tag_present):
"""
Check that the tooltip event filter only changes tooltips with non-rich text.
"""
from qtpy.QtCore import QEvent
from qtpy.QtWidgets import QWidget

# event filter object and QEvent
event_filter_handler = QtToolTipEventFilter()
qevent = QEvent(QEvent.ToolTipChange)

# check if tooltip is changed by the event filter
widget = QWidget()
qtbot.addWidget(widget)
widget.setToolTip(tooltip)
event_filter_handler.eventFilter(widget, qevent)
assert ("<qt>" in widget.toolTip()) == is_qt_tag_present