Skip to content

Commit

Permalink
Add test for QtToolTipEventFilter (#6066)
Browse files Browse the repository at this point in the history
# Description

Adds a test for the `QtToolTipEventFilter` as a continuation of the
effort started at #5864 to increase Qt widgets/code coverage

## Type of change
- [x] Tests improvements/additions

# How has this been tested?
- [x] all tests pass with my change
- [x] I check if my changes works with both PySide and PyQt backends
      as there are small differences between the two Qt bindings.  

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
  • Loading branch information
dalthviz committed Aug 1, 2023
1 parent b37eea4 commit d5be72d
Showing 1 changed file with 41 additions and 0 deletions.
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

0 comments on commit d5be72d

Please sign in to comment.