Skip to content

Commit d1dbc81

Browse files
committed
test(frontend_tkinter): Address copilot review suggestions
1 parent f2a4efa commit d1dbc81

2 files changed

Lines changed: 20 additions & 37 deletions

File tree

tests/test_frontend_tkinter_about_popup_window.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,11 @@
1212

1313
import contextlib
1414
import tkinter as tk
15-
from collections.abc import Generator
1615
from unittest.mock import patch
1716
from urllib.parse import urlparse
1817

19-
import pytest
20-
2118
from ardupilot_methodic_configurator.frontend_tkinter_about_popup_window import AboutWindow
2219

23-
# pylint: disable=redefined-outer-name
24-
25-
26-
@pytest.fixture
27-
def root() -> Generator[tk.Tk, None, None]:
28-
"""Provide a hidden Tk root window for tests."""
29-
root = tk.Tk()
30-
root.withdraw()
31-
yield root
32-
root.update_idletasks()
33-
root.destroy()
34-
3520

3621
def _create_about_window(root: tk.Tk, version: str = "1.2.3") -> AboutWindow:
3722
"""Helper to create an AboutWindow with all heavy operations mocked."""
@@ -43,6 +28,10 @@ def _create_about_window(root: tk.Tk, version: str = "1.2.3") -> AboutWindow:
4328
return_value=1.0,
4429
),
4530
patch("ardupilot_methodic_configurator.frontend_tkinter_base_window.BaseWindow.center_window"),
31+
patch(
32+
"ardupilot_methodic_configurator.backend_filesystem_program_settings.ProgramSettings.display_usage_popup",
33+
return_value=True,
34+
),
4635
):
4736
return AboutWindow(root, version)
4837

@@ -279,10 +268,12 @@ def test_user_can_view_source_code_via_about_window(self, root: tk.Tk) -> None:
279268
mock_open.assert_called_once()
280269
call_args = mock_open.call_args[0][0]
281270
assert isinstance(call_args, str), f"Expected URL string but got {type(call_args)}"
282-
assert "github.com/ArduPilot/MethodicConfigurator" in call_args, (
283-
f"Expected repository URL not found in {call_args}"
284-
)
285271
assert call_args.startswith("http"), f"URL should start with http but got {call_args}"
272+
parsed_url = urlparse(call_args)
273+
host = parsed_url.hostname
274+
assert host is not None, f"GitHub URL host not found in {call_args}"
275+
assert host == "github.com" or host.endswith(".github.com"), f"GitHub URL not found in {call_args}"
276+
assert "ArduPilot/MethodicConfigurator" in parsed_url.path, f"Expected repository path not found in {call_args}"
286277

287278

288279
class TestAboutWindowUsagePopupPreferences:

tests/test_frontend_tkinter_rich_text.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,10 @@ def test_get_widget_font_family_and_size(self) -> None:
206206
unittest.main()
207207

208208

209-
class TestRichTextColorAndFontFallbacks(unittest.TestCase):
209+
class TestRichTextColorAndFontFallbacks:
210210
"""Tests for color and font fallback behavior in RichText."""
211211

212-
def setUp(self) -> None:
213-
self.root = tk.Tk()
214-
self.root.withdraw()
215-
216-
def tearDown(self) -> None:
217-
self.root.update_idletasks()
218-
self.root.destroy()
219-
220-
def test_user_can_create_rich_text_with_explicit_background_color(self) -> None:
212+
def test_user_can_create_rich_text_with_explicit_background_color(self, root: tk.Tk) -> None:
221213
"""
222214
User can create RichText with an explicit background color.
223215
@@ -226,10 +218,10 @@ def test_user_can_create_rich_text_with_explicit_background_color(self) -> None:
226218
THEN: The background kwarg should skip the auto-detection
227219
AND: Widget should use the provided background color
228220
"""
229-
rich_text = RichText(self.root, background="red")
221+
rich_text = RichText(root, background="red")
230222
assert rich_text.cget("background") == "red"
231223

232-
def test_user_can_create_rich_text_with_bg_shorthand(self) -> None:
224+
def test_user_can_create_rich_text_with_bg_shorthand(self, root: tk.Tk) -> None:
233225
"""
234226
User can create RichText with bg shorthand.
235227
@@ -238,11 +230,11 @@ def test_user_can_create_rich_text_with_bg_shorthand(self) -> None:
238230
THEN: The bg kwarg should skip the auto-detection
239231
AND: Widget should use the provided background color
240232
"""
241-
rich_text = RichText(self.root, bg="blue")
233+
rich_text = RichText(root, bg="blue")
242234
# Color may be returned as RGB by Tk on some platforms
243235
assert rich_text.cget("background")
244236

245-
def test_user_can_create_rich_text_with_explicit_foreground_color(self) -> None:
237+
def test_user_can_create_rich_text_with_explicit_foreground_color(self, root: tk.Tk) -> None:
246238
"""
247239
User can create RichText with an explicit foreground color.
248240
@@ -251,21 +243,21 @@ def test_user_can_create_rich_text_with_explicit_foreground_color(self) -> None:
251243
THEN: The foreground kwarg should skip auto-detection
252244
AND: Widget should use provided foreground color
253245
"""
254-
rich_text = RichText(self.root, foreground="green")
246+
rich_text = RichText(root, foreground="green")
255247
assert rich_text.cget("foreground")
256248

257-
def test_user_can_create_rich_text_with_fg_shorthand(self) -> None:
249+
def test_user_can_create_rich_text_with_fg_shorthand(self, root: tk.Tk) -> None:
258250
"""
259251
User can create RichText with fg shorthand.
260252
261253
GIVEN: User wants a custom foreground color using 'fg' alias
262254
WHEN: RichText is created with fg kwarg
263255
THEN: Widget should be created successfully
264256
"""
265-
rich_text = RichText(self.root, fg="purple")
257+
rich_text = RichText(root, fg="purple")
266258
assert rich_text.cget("foreground")
267259

268-
def test_user_can_create_rich_text_when_safe_font_nametofont_returns_none(self) -> None:
260+
def test_user_can_create_rich_text_when_safe_font_nametofont_returns_none(self, root: tk.Tk) -> None:
269261
"""
270262
User can create RichText even when safe_font_nametofont returns None.
271263
@@ -275,7 +267,7 @@ def test_user_can_create_rich_text_when_safe_font_nametofont_returns_none(self)
275267
AND: Widget should be created successfully
276268
"""
277269
with patch("ardupilot_methodic_configurator.frontend_tkinter_rich_text.safe_font_nametofont", return_value=None):
278-
rich_text = RichText(self.root)
270+
rich_text = RichText(root)
279271

280272
assert rich_text is not None
281273
assert "bold" in rich_text.tag_names()

0 commit comments

Comments
 (0)