Skip to content

Commit aa7a40b

Browse files
committed
test(parameter editor): Fixed the pytest
Used the safe font Correct a documentation link Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
1 parent d4f3ecd commit aa7a40b

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

ardupilot_methodic_configurator/configuration_steps_ArduCopter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
"wiki_text": "Follow the blog instructions and use Mission Planner instead of this tool to configure the mandatory hardware parameters.",
215215
"wiki_url": "",
216216
"external_tool_text": "Mission Planner",
217-
"external_tool_url": "https://github.com/ArduPilot/MethodicConfigurator/blob/latest/TUNING_GUIDE_ArduCopter.md#212-configure-mandatory-hardware-parameters-17",
217+
"external_tool_url": "https://ardupilot.org/copter/docs/configuring-hardware.html",
218218
"mandatory_text": "100% mandatory (0% optional)",
219219
"auto_changed_by": "Mission Planner. If you have not done this step in Mission Planner yet, close this application and use Mission Planner",
220220
"old_filenames": ["11_mp_setup_mandatory_hardware.param"]

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,13 @@ def __should_copy_fc_values_to_file(self, selected_file: str) -> None: # pylint
542542
message_label.pack(padx=10, pady=10)
543543

544544
# Clickable link to tuning guide
545+
safe_font_config = get_safe_font_config()
545546
link_label = tk.Label(
546547
dialog,
547-
text=_("Open Tuning Guide relevant Section"),
548+
text=_("Click here to open the Tuning Guide relevant Section"),
548549
fg="blue",
549550
cursor="hand2",
550-
font=("TkDefaultFont", 9, "underline"),
551+
font=(str(safe_font_config["family"]), int(safe_font_config["size"]), "underline"),
551552
)
552553
link_label.pack(pady=(0, 10))
553554
link_label.bind("<Button-1>", lambda _e: self.configuration_manager.open_documentation_in_browser(selected_file))

tests/test_frontend_tkinter_parameter_editor.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
from typing import Any
14-
from unittest.mock import MagicMock, patch
14+
from unittest.mock import ANY, MagicMock, patch
1515

1616
import pytest
1717

@@ -245,7 +245,7 @@ def side_effect(*args, **kwargs) -> None: # noqa: ARG001 # pylint: disable=unus
245245
@patch("tkinter.Label")
246246
@patch("tkinter.Frame")
247247
@patch("tkinter.Button")
248-
def test_dialog_creation(
248+
def test_dialog_creation( # pylint: disable=too-many-locals
249249
self,
250250
mock_button: MagicMock,
251251
mock_frame: MagicMock,
@@ -281,5 +281,42 @@ def fake_wait_window(*args: Any, **kwargs: Any) -> None: # noqa: ANN401 # pylin
281281
mock_toplevel.assert_called_once()
282282

283283
# Check for label, buttons, and frame creation
284-
mock_label.assert_called_once()
284+
assert mock_label.call_count == 2 # message label and link label
285+
assert mock_button.call_count == 3 # Close, Yes, No buttons
285286
mock_frame.assert_called_once()
287+
288+
# Verify message label creation
289+
message_label_call = mock_label.call_args_list[0]
290+
assert message_label_call[1]["text"].startswith("This configuration step requires external changes by: External Tool")
291+
assert message_label_call[1]["justify"] == "left"
292+
assert message_label_call[1]["padx"] == 20
293+
assert message_label_call[1]["pady"] == 10
294+
295+
# Verify link label creation
296+
link_label_call = mock_label.call_args_list[1]
297+
assert link_label_call[1]["text"] == "Click here to open the Tuning Guide relevant Section"
298+
assert link_label_call[1]["fg"] == "blue"
299+
assert link_label_call[1]["cursor"] == "hand2"
300+
# Font should be a tuple with underline
301+
font_arg = link_label_call[1]["font"]
302+
assert isinstance(font_arg, tuple)
303+
assert len(font_arg) == 3
304+
assert font_arg[2] == "underline"
305+
306+
# Verify link label is packed and bound correctly
307+
link_label_mock = mock_label.return_value
308+
# Both labels call pack, so check that the link label's pack call was made
309+
assert link_label_mock.pack.call_count == 2
310+
link_label_mock.pack.assert_any_call(pady=(0, 10)) # link label pack call
311+
link_label_mock.pack.assert_any_call(padx=10, pady=10) # message label pack call
312+
link_label_mock.bind.assert_called_once_with("<Button-1>", ANY) # lambda function, so use ANY
313+
314+
# Verify buttons are created with correct text
315+
button_calls = mock_button.call_args_list
316+
assert button_calls[0][1]["text"] == "Close"
317+
assert button_calls[1][1]["text"] == "Yes"
318+
assert button_calls[2][1]["text"] == "No"
319+
320+
# Verify button frame is packed correctly
321+
frame_mock = mock_frame.return_value
322+
frame_mock.pack.assert_called_once_with(pady=10)

0 commit comments

Comments
 (0)