Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions tests/test_frontend_tkinter_connection_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def setUp(self) -> None:
return_value=self.mock_combobox,
),
patch("ardupilot_methodic_configurator.frontend_tkinter_connection_selection.show_tooltip"),
patch(
"ardupilot_methodic_configurator.frontend_tkinter_connection_selection.ProgramSettings.get_connection_history",
return_value=[],
),
):
self.widget = ConnectionSelectionWidgets(
self.mock_parent,
Expand Down Expand Up @@ -226,7 +230,10 @@ def test_add_connection_canceled(self, mock_logging_debug, mock_askstring) -> No
self.mock_flight_controller.add_connection.reset_mock()

# Patch the reconnect method to prevent it from being called
with patch.object(self.widget, "reconnect"):
with (
patch.object(self.widget, "reconnect"),
patch("ardupilot_methodic_configurator.frontend_tkinter_connection_selection.ProgramSettings.store_connection"),
):
# Call the method
result = self.widget.add_connection()

Expand All @@ -239,7 +246,10 @@ def test_add_connection_canceled(self, mock_logging_debug, mock_askstring) -> No

# Test with empty string input
mock_askstring.return_value = ""
with patch.object(self.widget, "reconnect"):
with (
patch.object(self.widget, "reconnect"),
patch("ardupilot_methodic_configurator.frontend_tkinter_connection_selection.ProgramSettings.store_connection"),
):
result = self.widget.add_connection()
assert result == ""
self.mock_flight_controller.add_connection.assert_not_called()
Expand All @@ -262,13 +272,17 @@ def test_add_connection_success(self, mock_logging_debug, mock_askstring) -> Non
("Add another", "Add another connection"),
]

# Reset mocks
# Reset mocks to clear any previous test state
self.mock_flight_controller.add_connection.reset_mock()
self.mock_flight_controller.get_connection_tuples.reset_mock()
self.mock_flight_controller.get_connection_tuples.return_value = updated_tuples
self.mock_combobox.reset_mock()

# Patch the reconnect method
with patch.object(self.widget, "reconnect") as mock_reconnect:
# Patch the reconnect method and ProgramSettings
with (
patch.object(self.widget, "reconnect") as mock_reconnect,
patch("ardupilot_methodic_configurator.frontend_tkinter_connection_selection.ProgramSettings.store_connection"),
):
# Call the method
result = self.widget.add_connection()

Expand Down
Loading