15
15
from tkinter import ttk
16
16
from unittest .mock import patch
17
17
18
+ import pytest
19
+
18
20
from ardupilot_methodic_configurator .frontend_tkinter_autoresize_combobox import (
19
21
AutoResizeCombobox ,
20
22
update_combobox_width ,
24
26
class TestUpdateComboboxWidth (unittest .TestCase ):
25
27
"""Test cases for the update_combobox_width function."""
26
28
29
+ @pytest .mark .gui
27
30
def test_update_combobox_width (self ) -> None :
28
31
combobox = ttk .Combobox (values = ["short" , "longer" , "longest" ])
29
32
update_combobox_width (combobox )
30
33
assert combobox .cget ("width" ) == 7
31
34
35
+ @pytest .mark .gui
32
36
def test_update_combobox_width_empty_values (self ) -> None :
33
37
combobox = ttk .Combobox (values = [])
34
38
update_combobox_width (combobox )
35
39
# Should use the minimum width (4) when no values
36
40
assert combobox .cget ("width" ) == 4
37
41
42
+ @pytest .mark .gui
38
43
def test_update_combobox_width_very_short_values (self ) -> None :
39
44
combobox = ttk .Combobox (values = ["a" , "b" , "c" ])
40
45
update_combobox_width (combobox )
@@ -45,6 +50,7 @@ def test_update_combobox_width_very_short_values(self) -> None:
45
50
class TestAutoResizeCombobox (unittest .TestCase ):
46
51
"""Test cases for the AutoResizeCombobox class."""
47
52
53
+ @pytest .mark .gui
48
54
def setUp (self ) -> None :
49
55
self .root = tk .Tk ()
50
56
self .root .withdraw () # Hide the main window during tests
@@ -55,21 +61,25 @@ def setUp(self) -> None:
55
61
def tearDown (self ) -> None :
56
62
self .root .destroy ()
57
63
64
+ @pytest .mark .gui
58
65
def test_initial_selection (self ) -> None :
59
66
assert self .combobox .get () == "two"
60
67
68
+ @pytest .mark .gui
61
69
def test_update_values (self ) -> None :
62
70
self .combobox .set_entries_tuple (["four" , "five" , "six" ], "five" )
63
71
assert self .combobox .get () == "five"
64
72
assert self .combobox ["values" ] == ("four" , "five" , "six" )
65
73
74
+ @pytest .mark .gui
66
75
def test_set_entries_with_spaces (self ) -> None :
67
76
"""Test values with spaces."""
68
77
values = ["option one" , "option two" , "option three" ]
69
78
self .combobox .set_entries_tuple (values , "option two" )
70
79
assert self .combobox ["values" ] == tuple (values )
71
80
assert self .combobox .get () == "option two"
72
81
82
+ @pytest .mark .gui
73
83
@patch ("ardupilot_methodic_configurator.frontend_tkinter_autoresize_combobox.logging_error" )
74
84
def test_set_entries_invalid_selection (self , mock_logging_error ) -> None :
75
85
"""Test when selected element is not in values list."""
@@ -81,6 +91,7 @@ def test_set_entries_invalid_selection(self, mock_logging_error) -> None:
81
91
# Selected value should not be set
82
92
assert self .combobox .get () == "two" # Maintains previous value
83
93
94
+ @pytest .mark .gui
84
95
@patch ("ardupilot_methodic_configurator.frontend_tkinter_autoresize_combobox.logging_warning" )
85
96
def test_set_entries_no_selection (self , mock_logging_warning ) -> None :
86
97
"""Test when no selection is provided."""
@@ -90,6 +101,7 @@ def test_set_entries_no_selection(self, mock_logging_warning) -> None:
90
101
# Should log a warning
91
102
mock_logging_warning .assert_called_once ()
92
103
104
+ @pytest .mark .gui
93
105
@patch ("ardupilot_methodic_configurator.frontend_tkinter_autoresize_combobox.update_combobox_width" )
94
106
def test_set_entries_empty_values (self , mock_update_width ) -> None :
95
107
"""Test behavior with empty values list."""
@@ -98,6 +110,7 @@ def test_set_entries_empty_values(self, mock_update_width) -> None:
98
110
# Width update should not be called with empty values
99
111
mock_update_width .assert_not_called ()
100
112
113
+ @pytest .mark .gui
101
114
@patch ("ardupilot_methodic_configurator.frontend_tkinter_autoresize_combobox.show_tooltip" )
102
115
def test_tooltip_display (self , mock_show_tooltip ) -> None :
103
116
"""Test tooltip is shown when provided."""
@@ -106,6 +119,7 @@ def test_tooltip_display(self, mock_show_tooltip) -> None:
106
119
# Tooltip should be shown
107
120
mock_show_tooltip .assert_called_once_with (self .combobox , "Help text" )
108
121
122
+ @pytest .mark .gui
109
123
@patch ("ardupilot_methodic_configurator.frontend_tkinter_autoresize_combobox.show_tooltip" )
110
124
def test_no_tooltip_when_none (self , mock_show_tooltip ) -> None :
111
125
"""Test tooltip is not shown when None."""
0 commit comments