-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHORE: Add tests to frontend classes
- Loading branch information
1 parent
9bc543b
commit f3dee9c
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/python3 | ||
|
||
""" | ||
Tests for the frontend_tkinter_software_update.py file. | ||
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator | ||
SPDX-FileCopyrightText: 2024-2025 Amilcar Lucas | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
""" | ||
|
||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
|
||
from ardupilot_methodic_configurator.frontend_tkinter_software_update import UpdateDialog | ||
|
||
|
||
class TestUpdateDialog(unittest.TestCase): | ||
"""Test cases for the UpdateDialog class.""" | ||
|
||
def setUp(self) -> None: | ||
"""Set up test fixtures.""" | ||
self.tk_mock = patch("tkinter.Tk").start() | ||
self.ttk_mock = patch("tkinter.ttk").start() | ||
self.version_info = "Test Version Info" | ||
self.download_callback = MagicMock(return_value=True) | ||
|
||
def tearDown(self) -> None: | ||
"""Clean up after each test.""" | ||
patch.stopall() | ||
|
||
def test_init(self) -> None: | ||
"""Test dialog initialization.""" | ||
dialog = UpdateDialog(self.version_info, self.download_callback) | ||
|
||
self.tk_mock.assert_called_once() | ||
assert dialog.result is None | ||
assert dialog.download_callback == self.download_callback | ||
|
||
def test_update_progress(self) -> None: | ||
"""Test progress bar updates.""" | ||
|
||
def test_on_yes_successful_update(self) -> None: | ||
"""Test successful update process.""" | ||
|
||
def test_on_yes_failed_update(self) -> None: | ||
"""Test failed update process.""" | ||
|
||
def test_on_no(self) -> None: | ||
"""Test 'Not Now' button behavior.""" | ||
dialog = UpdateDialog(self.version_info) | ||
dialog.on_no() | ||
|
||
assert not dialog.result | ||
dialog.root.destroy.assert_called_once() | ||
|
||
def test_on_cancel(self) -> None: | ||
"""Test cancel operation.""" | ||
dialog = UpdateDialog(self.version_info) | ||
dialog.on_cancel() | ||
|
||
assert not dialog.result | ||
dialog.root.destroy.assert_called_once() | ||
|
||
def test_grid_management(self) -> None: | ||
"""Test grid management during update process.""" | ||
|
||
@patch("tkinter.ttk.Button") | ||
def test_button_states(self, mock_button) -> None: | ||
"""Test button state management.""" | ||
|
||
def test_status_messages(self) -> None: | ||
"""Test status message updates.""" | ||
|
||
def test_window_protocol(self) -> None: | ||
"""Test window protocol configuration.""" | ||
dialog = UpdateDialog(self.version_info) | ||
dialog.root.protocol.assert_called_with("WM_DELETE_WINDOW", dialog.on_cancel) | ||
|
||
@patch("tkinter.ttk.Frame") | ||
def test_frame_configuration(self, mock_frame) -> None: | ||
"""Test frame configuration.""" | ||
dialog = UpdateDialog(self.version_info) | ||
mock_frame.assert_called_with(dialog.root, padding="20") | ||
dialog.frame.grid.assert_called_with(sticky="nsew") | ||
|
||
def test_progress_value_bounds(self) -> None: | ||
"""Test progress bar value bounds.""" | ||
|
||
def test_multiple_updates(self) -> None: | ||
"""Test multiple update attempts.""" | ||
dialog = UpdateDialog(self.version_info, self.download_callback) | ||
|
||
# First update attempt | ||
dialog.on_yes() | ||
assert dialog.result | ||
|
||
# Second update attempt should not change result | ||
dialog.on_yes() | ||
assert dialog.result | ||
|
||
def test_version_info_display(self) -> None: | ||
"""Test version info display in dialog.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/python3 | ||
|
||
""" | ||
Tests for the frontend_tkinter_template_overview.py file. | ||
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator | ||
SPDX-FileCopyrightText: 2024-2025 Amilcar do Carmo Lucas <[email protected]> | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
""" | ||
|
||
import argparse | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from ardupilot_methodic_configurator.frontend_tkinter_template_overview import argument_parser, main | ||
|
||
|
||
class TestTemplateOverviewWindow(unittest.TestCase): | ||
"""Test cases for the TemplateOverviewWindow class.""" | ||
|
||
|
||
class TestArgumentParser(unittest.TestCase): | ||
"""Test cases for argument parsing functionality.""" | ||
|
||
def test_argument_parser_exit(self) -> None: | ||
"""Test argument parser exits with no arguments.""" | ||
with pytest.raises(SystemExit): | ||
argument_parser() | ||
|
||
@patch("sys.argv", ["script.py", "--loglevel", "DEBUG"]) | ||
def test_main_function(self) -> None: | ||
"""Test main function execution.""" | ||
with ( | ||
patch("ardupilot_methodic_configurator.frontend_tkinter_template_overview.TemplateOverviewWindow") as mock_window, | ||
patch("ardupilot_methodic_configurator.frontend_tkinter_template_overview.argument_parser") as mock_parser, | ||
): | ||
mock_parser.return_value = argparse.Namespace(loglevel="DEBUG") | ||
main() | ||
mock_window.assert_called_once_with(None) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters