|
19 | 19 | VehicleProjectCreationError, |
20 | 20 | ) |
21 | 21 | 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 |
23 | 23 |
|
24 | 24 | # pylint: disable=redefined-outer-name, unused-argument, duplicate-code |
25 | 25 |
|
@@ -432,130 +432,3 @@ def test_user_workflow_with_flight_controller_connected(self, mock_project_manag |
432 | 432 | # Assert: Window was created with flight controller configuration |
433 | 433 | # The NewVehicleProjectSettings.get_all_settings_metadata should be called with fc_connected=True |
434 | 434 | 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