Skip to content

Commit d2e9c58

Browse files
OmkarSarkar204amilcarlucas
authored andcommitted
fix: updated test and pylint issue
Signed-off-by: Omkar Sarkar <omkarsarkar24@gmail.com>
1 parent eb4b640 commit d2e9c58

2 files changed

Lines changed: 30 additions & 48 deletions

File tree

ardupilot_methodic_configurator/frontend_tkinter_show.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,6 @@ def _cancel_timer(self, name: str) -> None:
497497
def _cancel_show(self) -> None:
498498
self._cancel_timer("show")
499499

500-
# def show(self, event: Optional[tk.Event] = None) -> None: # pylint: disable=unused-argument
501-
# """On non-macOS, tooltip already exists, show it on events."""
502-
# self._cancel_hide()
503-
# self._hide_active_tooltip()
504-
# if self.tooltip:
505-
# self.position_tooltip()
506-
# self.tooltip.deiconify()
507-
# Tooltip._active_tooltip = self
508-
509500
def _cancel_hide(self, event: Optional[tk.Event] = None) -> None: # noqa: ARG002 # pylint: disable=unused-argument
510501
self._cancel_timer("hide")
511502

@@ -527,13 +518,13 @@ def _hide_active_tooltip(self) -> None:
527518
Tooltip._active_tooltip.force_hide()
528519
Tooltip._active_tooltip = None
529520

530-
def schedule_show(self, event: Optional[tk.Event] = None) -> None: # noqa: ARG002 # pylint: disable=unused-argument
521+
def schedule_show(self, _event: Optional[tk.Event] = None) -> None:
531522
"""Delay tooltip creation slightly to avoid flicker during pointer movement."""
532523
self._cancel_hide()
533524
self._cancel_show()
534525
self.timers["show"] = self.widget.after(TOOLTIP_SHOW_DELAY_MS, self.create_show)
535526

536-
def create_show(self, event: Optional[tk.Event] = None) -> None: # noqa: ARG002 # pylint: disable=unused-argument
527+
def create_show(self, _event: Optional[tk.Event] = None) -> None:
537528
"""On macOS, only create the tooltip when the mouse enters the widget."""
538529
self._cancel_show()
539530
self._cancel_hide()
@@ -632,19 +623,6 @@ def position_tooltip(self) -> None:
632623
# Silently ignore - tooltip will be recreated on next hover if needed
633624
pass
634625

635-
# def hide(self, event: Optional[tk.Event] = None) -> None: # pylint: disable=unused-argument
636-
# """Hide the tooltip after a delay on non-macOS."""
637-
# self._cancel_hide()
638-
# self.timers["hide"] = self.widget.after(TOOLTIP_HIDE_DELAY_MS, self._do_hide)
639-
640-
# def _do_hide(self) -> None:
641-
# """Actually hide or destroy the tooltip depending on platform."""
642-
# if self.tooltip:
643-
# self.tooltip.withdraw()
644-
# if Tooltip._active_tooltip is self:
645-
# Tooltip._active_tooltip = None
646-
# self.timers.pop("hide", None)
647-
648626
def force_hide(self) -> None:
649627
"""Immediately destroy the tooltip globally across all OSs."""
650628
self._cancel_show()

tests/bdd_frontend_tkinter_show.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import pytest
2424

2525
from ardupilot_methodic_configurator.frontend_tkinter_show import (
26-
TOOLTIP_HIDE_DELAY_MS,
2726
TOOLTIP_SHOW_DELAY_MS,
2827
MonitorBounds,
2928
Tooltip,
@@ -747,19 +746,15 @@ def test_tooltip_initialization_non_macos(self, mock_widget: MagicMock, mock_top
747746
with (
748747
patch("ardupilot_methodic_configurator.frontend_tkinter_show.platform_system", return_value="Linux"),
749748
patch("tkinter.Toplevel", return_value=mock_toplevel),
750-
patch("tkinter.ttk.Label") as mock_label,
749+
patch("tkinter.ttk.Label"),
751750
):
752751
tooltip = Tooltip(mock_widget, "Test text")
753752

754-
# Check that Toplevel was created
755-
assert tooltip.tooltip == mock_toplevel
753+
# Check that Toplevel was NOT created yet (Lazy Loading)
754+
assert tooltip.tooltip is None
756755
# Check bindings
757-
mock_widget.bind.assert_any_call("<Enter>", tooltip.show, "+")
758-
mock_widget.bind.assert_any_call("<Leave>", tooltip.hide, "+")
759-
# Check tooltip setup
760-
mock_toplevel.wm_overrideredirect.assert_called_with(boolean=True)
761-
mock_label.assert_called_once()
762-
mock_toplevel.withdraw.assert_called_once()
756+
mock_widget.bind.assert_any_call("<Enter>", tooltip.schedule_show, "+")
757+
mock_widget.bind.assert_any_call("<Leave>", tooltip.destroy_hide, "+")
763758

764759
def test_tooltip_initialization_macos(self, mock_widget: MagicMock) -> None:
765760
"""
@@ -822,10 +817,10 @@ def test_tooltip_position_tooltip(self, mock_widget, mock_toplevel) -> None:
822817
),
823818
):
824819
tooltip = Tooltip(mock_widget, "Test text")
820+
mock_widget.winfo_containing.return_value = mock_widget # Tell the test the mouse is hovering
821+
tooltip.create_show()
825822

826-
tooltip.position_tooltip()
827-
828-
# Check that geometry was set
823+
# Check that geometry was set (create_show did this automatically!)
829824
mock_toplevel.geometry.assert_called_once()
830825
# The call should be with calculated position
831826
call_args = mock_toplevel.geometry.call_args[0][0]
@@ -844,9 +839,10 @@ def test_tooltip_show_non_macos(self, mock_widget, mock_toplevel) -> None:
844839
patch("tkinter.ttk.Label"),
845840
patch("ardupilot_methodic_configurator.frontend_tkinter_show.platform_system", return_value="Linux"),
846841
):
842+
mock_widget.winfo_containing.return_value = mock_widget
847843
tooltip = Tooltip(mock_widget, "Test text")
848844

849-
tooltip.show()
845+
tooltip.create_show()
850846

851847
mock_toplevel.deiconify.assert_called_once()
852848

@@ -864,10 +860,12 @@ def test_tooltip_hide(self, mock_widget, mock_toplevel) -> None:
864860
patch("ardupilot_methodic_configurator.frontend_tkinter_show.platform_system", return_value="Linux"),
865861
):
866862
tooltip = Tooltip(mock_widget, "Test text")
863+
tooltip.tooltip = mock_toplevel # Mock that it was created
864+
tooltip.destroy_hide()
867865

868-
tooltip.hide()
869-
870-
mock_widget.after.assert_called_once_with(TOOLTIP_HIDE_DELAY_MS, tooltip._do_hide)
866+
# As it destroys immediately, check if active_tooltip is cleared
867+
assert Tooltip._active_tooltip is None
868+
mock_toplevel.destroy.assert_called_once()
871869

872870
def test_tooltip_cancel_hide(self, mock_widget) -> None:
873871
"""
@@ -990,7 +988,7 @@ def test_tooltip_no_position_when_tooltip_none(self, mock_widget) -> None:
990988

991989
# Assert: No exception, no positioning attempted
992990

993-
def test_tooltip_do_hide_withdraws_on_non_macos(self, mock_widget, mock_toplevel) -> None:
991+
def test_tooltip_force_hide_destroys_globally(self, mock_widget, mock_toplevel) -> None:
994992
"""
995993
Test tooltip _do_hide withdraws tooltip on non-macOS.
996994
@@ -1003,11 +1001,14 @@ def test_tooltip_do_hide_withdraws_on_non_macos(self, mock_widget, mock_toplevel
10031001
patch("tkinter.ttk.Label"),
10041002
patch("ardupilot_methodic_configurator.frontend_tkinter_show.platform_system", return_value="Linux"),
10051003
):
1004+
mock_widget.winfo_containing.return_value = mock_widget
10061005
tooltip = Tooltip(mock_widget, "Test text")
1006+
tooltip.create_show() # Must create it before we can destroy it
10071007

1008-
tooltip._do_hide()
1008+
tooltip.force_hide()
10091009

1010-
mock_toplevel.withdraw.assert_called()
1010+
mock_toplevel.destroy.assert_called_once()
1011+
assert tooltip.tooltip is None
10111012

10121013
def test_tooltip_create_show_avoids_redundant_creation(self, mock_widget, mock_toplevel) -> None:
10131014
"""
@@ -1067,11 +1068,13 @@ def test_tooltip_with_custom_toplevel_class(self, mock_widget, mock_toplevel) ->
10671068
patch("ardupilot_methodic_configurator.frontend_tkinter_show.platform_system", return_value="Linux"),
10681069
patch("tkinter.ttk.Label"),
10691070
):
1071+
mock_widget.winfo_containing.return_value = mock_widget
10701072
tooltip = Tooltip(mock_widget, "Test text", toplevel_class=custom_toplevel_class)
10711073

1074+
tooltip.create_show() # Trigger lazy load
1075+
10721076
# Assert: Custom class was used
1073-
custom_toplevel_class.assert_called_once_with(mock_widget)
1074-
assert tooltip.tooltip == mock_toplevel
1077+
custom_toplevel_class.assert_called_once()
10751078

10761079
def test_tooltip_position_below_false(self, mock_widget, mock_toplevel) -> None:
10771080
"""
@@ -1091,9 +1094,10 @@ def test_tooltip_position_below_false(self, mock_widget, mock_toplevel) -> None:
10911094
),
10921095
):
10931096
tooltip = Tooltip(mock_widget, "Test text", position_below=False)
1094-
tooltip.position_tooltip()
1097+
mock_widget.winfo_containing.return_value = mock_widget # Tell the test the mouse is hovering
1098+
tooltip.create_show()
10951099

1096-
# Assert: Geometry set (indicates positioning occurred)
1100+
# Assert: Geometry set
10971101
mock_toplevel.geometry.assert_called_once()
10981102

10991103
def test_tooltip_create_show_uses_macos_styling(self, mock_widget, mock_toplevel) -> None:

0 commit comments

Comments
 (0)