Skip to content

Commit e0d11d4

Browse files
amilcarlucastripcoded
authored andcommitted
test(coverage): Remove tests that tested non-production code
1 parent 0eff031 commit e0d11d4

File tree

6 files changed

+6
-368
lines changed

6 files changed

+6
-368
lines changed

ardupilot_methodic_configurator/data_model_software_updates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def check_for_software_updates() -> bool:
153153
return False
154154

155155

156-
if __name__ == "__main__":
156+
if __name__ == "__main__": # pragma: no cover
157157
logging_basicConfig(level=logging_getLevelName("DEBUG"), format="%(asctime)s - %(levelname)s - %(message)s")
158158
logging_warning(
159159
_(

ardupilot_methodic_configurator/frontend_tkinter_template_overview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def argument_parser() -> argparse.Namespace: # pragma: no cover
401401
return add_common_arguments(parser).parse_args()
402402

403403

404-
def setup_logging(loglevel: str) -> None:
404+
def setup_logging(loglevel: str) -> None: # pragma: no cover
405405
"""
406406
Set up logging with the specified log level.
407407

tests/test__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ardupilot_methodic_configurator.backend_flightcontroller import DEVICE_FC_PARAM_FROM_FILE
4040
from ardupilot_methodic_configurator.frontend_tkinter_usage_popup_window import PopupWindow
4141

42-
# pylint: disable=,too-many-lines,redefined-outer-name,too-few-public-methods
42+
# pylint: disable=too-many-lines,redefined-outer-name,too-few-public-methods
4343

4444
# ====== Fixtures following pytest_testing_instructions.md ======
4545

tests/test_frontend_tkinter_motor_test.py

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
MotorTestView,
3535
MotorTestWindow,
3636
_create_motor_test_view,
37-
argument_parser,
38-
main,
3937
register_motor_test_plugin,
4038
)
4139

@@ -796,78 +794,7 @@ def fake_base_init(self) -> None:
796794

797795

798796
class TestCommandLineWorkflow:
799-
"""Verifies CLI helpers, entry points, and plugin registration hooks."""
800-
801-
def test_argument_parser_wires_common_arguments(self, mocker) -> None:
802-
"""
803-
Argument parser delegates to backend helpers and parses args.
804-
805-
GIVEN: Patched backend adders returning the provided parser
806-
WHEN: argument_parser is invoked
807-
THEN: Each backend helper receives the parser instance
808-
"""
809-
parser_mock = MagicMock()
810-
fc_adder = mocker.patch(
811-
"ardupilot_methodic_configurator.backend_flightcontroller.FlightController.add_argparse_arguments",
812-
side_effect=lambda parser: parser,
813-
)
814-
fs_adder = mocker.patch(
815-
"ardupilot_methodic_configurator.backend_filesystem.LocalFilesystem.add_argparse_arguments",
816-
side_effect=lambda parser: parser,
817-
)
818-
mocker.patch(
819-
"ardupilot_methodic_configurator.frontend_tkinter_motor_test.add_common_arguments",
820-
return_value=parser_mock,
821-
)
822-
parser_mock.parse_args.return_value = SimpleNamespace()
823-
824-
argument_parser()
825-
assert fc_adder.called
826-
assert fs_adder.called
827-
fc_parser = fc_adder.call_args.args[0]
828-
fs_parser = fs_adder.call_args.args[0]
829-
assert fc_parser is fs_parser
830-
parser_mock.parse_args.assert_called_once_with()
831-
832-
def test_main_success_and_failure_paths(self, mocker) -> None:
833-
"""
834-
The standalone entry point starts the window and reports failures.
835-
836-
GIVEN: Patched dependencies for ApplicationState, window, and dialogs
837-
WHEN: main succeeds once and fails the next time
838-
THEN: The window mainloop executes and failures trigger showerror
839-
"""
840-
args = SimpleNamespace()
841-
mocker.patch(
842-
"ardupilot_methodic_configurator.frontend_tkinter_motor_test.argument_parser",
843-
return_value=args,
844-
)
845-
state = SimpleNamespace(flight_controller=MagicMock(), local_filesystem=MagicMock())
846-
mocker.patch(
847-
"ardupilot_methodic_configurator.frontend_tkinter_motor_test.ApplicationState",
848-
return_value=state,
849-
)
850-
mocker.patch("ardupilot_methodic_configurator.frontend_tkinter_motor_test.setup_logging")
851-
mocker.patch("ardupilot_methodic_configurator.frontend_tkinter_motor_test.initialize_flight_controller_and_filesystem")
852-
window_mock = MagicMock()
853-
window_mock.root = MagicMock()
854-
mocker.patch(
855-
"ardupilot_methodic_configurator.frontend_tkinter_motor_test.MotorTestWindow",
856-
return_value=window_mock,
857-
)
858-
mocker.patch(
859-
"ardupilot_methodic_configurator.frontend_tkinter_motor_test.MotorTestDataModel", return_value=MagicMock()
860-
)
861-
862-
main()
863-
window_mock.root.mainloop.assert_called_once()
864-
865-
mocker.patch(
866-
"ardupilot_methodic_configurator.frontend_tkinter_motor_test.MotorTestWindow",
867-
side_effect=RuntimeError("boom"),
868-
)
869-
main()
870-
state.flight_controller.disconnect.assert_called()
797+
"""Verifies plugin registration hooks."""
871798

872799
def test_plugin_registration_and_factory_creation(
873800
self,

tests/test_frontend_tkinter_project_creator.py

Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
VehicleProjectCreationError,
2020
)
2121
from ardupilot_methodic_configurator.frontend_tkinter_base_window import BaseWindow
22-
from ardupilot_methodic_configurator.frontend_tkinter_project_creator import VehicleProjectCreatorWindow, argument_parser, main
22+
from ardupilot_methodic_configurator.frontend_tkinter_project_creator import VehicleProjectCreatorWindow
2323

2424
# pylint: disable=redefined-outer-name, unused-argument, duplicate-code
2525

@@ -432,130 +432,3 @@ def test_user_workflow_with_flight_controller_connected(self, mock_project_manag
432432
# Assert: Window was created with flight controller configuration
433433
# The NewVehicleProjectSettings.get_all_settings_metadata should be called with fc_connected=True
434434
assert mock_settings.get_all_settings_metadata.called
435-
436-
437-
class TestArgumentParserAndMainFunction:
438-
"""Test argument parser and main function for coverage."""
439-
440-
def test_user_can_parse_command_line_arguments_successfully(self) -> None:
441-
"""
442-
User can parse command line arguments for the application.
443-
444-
GIVEN: A user wants to run the application with command line arguments
445-
WHEN: Arguments are parsed with argument_parser
446-
THEN: Parser should return valid namespace with expected defaults
447-
"""
448-
# Arrange: Mock sys.argv to provide clean arguments
449-
with patch("sys.argv", ["test_script"]):
450-
# Act: Parse arguments using the argument_parser function
451-
args = argument_parser()
452-
453-
# Assert: Arguments parsed correctly with proper attributes
454-
assert hasattr(args, "loglevel")
455-
assert hasattr(args, "vehicle_dir")
456-
assert hasattr(args, "vehicle_type")
457-
assert hasattr(args, "allow_editing_template_files")
458-
assert hasattr(args, "save_component_to_system_templates")
459-
460-
def test_user_can_access_main_function_window_creation_path(self) -> None:
461-
"""
462-
User can access main function window creation path for coverage.
463-
464-
GIVEN: A user runs the main function with valid configuration
465-
WHEN: Main function creates window
466-
THEN: Window creation path should be covered
467-
"""
468-
# Arrange: Mock all dependencies for main function
469-
with (
470-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.argument_parser") as mock_parser,
471-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.logging_basicConfig"),
472-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.logging_warning"),
473-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.LocalFilesystem"),
474-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.VehicleProjectManager") as mock_pm,
475-
patch(
476-
"ardupilot_methodic_configurator.frontend_tkinter_project_creator.VehicleProjectCreatorWindow"
477-
) as mock_window_class,
478-
):
479-
# Set up mock arguments
480-
mock_args = MagicMock()
481-
mock_args.loglevel = "INFO"
482-
mock_args.vehicle_dir = "/test/dir"
483-
mock_args.vehicle_type = "ArduCopter"
484-
mock_args.allow_editing_template_files = False
485-
mock_args.save_component_to_system_templates = False
486-
mock_parser.return_value = mock_args
487-
488-
# Set up project manager with files found
489-
mock_project_manager = MagicMock()
490-
mock_project_manager.get_file_parameters_list.return_value = ["file1.param", "file2.param"]
491-
mock_pm.return_value = mock_project_manager
492-
493-
# Set up window mock
494-
mock_window = MagicMock()
495-
mock_window_class.return_value = mock_window
496-
497-
# Act: Call main function (covers lines 491, 493-494)
498-
main()
499-
500-
# Assert: Window was created and mainloop called
501-
mock_window_class.assert_called_once_with(mock_project_manager)
502-
mock_window.root.mainloop.assert_called_once()
503-
504-
505-
class TestMainFunctionErrorPaths:
506-
"""Test main function error paths for coverage."""
507-
508-
def test_user_sees_error_when_no_parameter_files_found_in_main(self) -> None:
509-
"""
510-
User sees error when no parameter files found in main function.
511-
512-
GIVEN: A main function call with no parameter files
513-
WHEN: Main function checks for parameter files but finds none
514-
THEN: Error should be logged and logged appropriately
515-
"""
516-
# Arrange: Mock dependencies with empty file list
517-
with (
518-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.argument_parser") as mock_parser,
519-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.logging_basicConfig"),
520-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.logging_warning"),
521-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.logging_error") as mock_error,
522-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.LocalFilesystem"),
523-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.VehicleProjectManager") as mock_pm,
524-
patch("ardupilot_methodic_configurator.frontend_tkinter_project_creator.VehicleProjectCreatorWindow"),
525-
):
526-
# Set up mock arguments
527-
mock_args = MagicMock()
528-
mock_args.loglevel = "INFO"
529-
mock_args.vehicle_dir = "/test/dir"
530-
mock_args.vehicle_type = "ArduCopter"
531-
mock_args.allow_editing_template_files = False
532-
mock_args.save_component_to_system_templates = False
533-
mock_parser.return_value = mock_args
534-
535-
# Set up project manager with NO files found (covers line 491)
536-
mock_project_manager = MagicMock()
537-
mock_project_manager.get_file_parameters_list.return_value = [] # Empty list
538-
mock_pm.return_value = mock_project_manager
539-
540-
# Act: Call main function - should hit error path
541-
main()
542-
543-
# Assert: Error logging called for missing files (line 491)
544-
mock_error.assert_called()
545-
546-
def test_if_name_main_calls_main_function(self) -> None:
547-
"""
548-
Test that if __name__ == '__main__' calls main function.
549-
550-
GIVEN: A module run as main script
551-
WHEN: The if __name__ == '__main__' block executes
552-
THEN: The main function should be called
553-
"""
554-
# This test covers line 498: if __name__ == "__main__": main()
555-
# We can't easily test this directly as it's module-level code
556-
# But we can test the main function exists and is callable
557-
558-
# Assert: main function exists and is callable
559-
assert callable(main)
560-
# This implicitly tests that the main function is importable and available
561-
# which covers the import structure that supports line 498

0 commit comments

Comments
 (0)