test: add test cases for main#1388
Conversation
|
Im planning to add a few more tests, will remove it from draft when ready. |
c9507af to
e0a859a
Compare
Pull Request Test Coverage Report for Build 23251116424Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
6f02df2 to
921152c
Compare
|
Hello @amilcarlucas , can you please take a look at this and check if its ok? |
921152c to
5c19da0
Compare
amilcarlucas
left a comment
There was a problem hiding this comment.
Thanks. Looks good at first sight. I rebased it to re-trigger the tests.
There was a problem hiding this comment.
Pull request overview
Adds unit tests covering key control-flow branches in ardupilot_methodic_configurator.__main__ to address #1352 and improve confidence in startup orchestration, plugin validation, filesystem setup, editor flows, backups, and parameter upload behavior.
Changes:
- Added targeted tests for plugin registration/validation and first-use documentation URL behavior
- Added tests for connection error handling, writable-dir fallback, and filesystem initialization fatal-paths
- Added tests for component/parameter editor paths, backups, GPS param rename behavior, and
main()orchestration
tests/test__main__.py
Outdated
| # Assert | ||
| assert result == fallback | ||
| mock_warn.assert_called_once() | ||
| warn_kwargs: dict = mock_warn.call_args[0][1] |
There was a problem hiding this comment.
mock_warn.call_args[0][1] assumes logging_warning is called with at least two positional args and that the second is a dict. If logging_warning uses keyword args (common for structured logging) or only one positional arg, this will raise (IndexError/TypeError) and make the test incorrectly fail. Prefer asserting against mock_warn.call_args.kwargs (or mock_warn.call_args[1]) and only fall back to positional arg inspection if the production signature truly passes a dict positionally.
| warn_kwargs: dict = mock_warn.call_args[0][1] | |
| args, kwargs = mock_warn.call_args | |
| if kwargs: | |
| warn_kwargs: dict = kwargs | |
| elif len(args) > 1 and isinstance(args[1], dict): | |
| warn_kwargs = args[1] | |
| else: | |
| pytest.fail("logging_warning was not called with expected keyword or dict positional arguments") |
| patch( | ||
| "ardupilot_methodic_configurator.__main__.ProgramSettings.get_setting", | ||
| return_value=False, | ||
| ), |
There was a problem hiding this comment.
Patching ProgramSettings.get_setting with a blanket return_value=False makes the test brittle and can accidentally push main() down unintended branches if main() (now or later) reads a non-boolean setting (e.g., string-valued settings like GUI mode). Using a side_effect that returns specific values per key (or patching only the specific settings read in this test) will keep the test focused and reduce false failures when main() evolves.
| validate_plugin_registry(mock_fs) | ||
|
|
||
| # Assert | ||
| mock_err.assert_called_once() |
There was a problem hiding this comment.
This assertion only verifies that an error was logged, but not that it identifies the missing plugin. To make the test protect the diagnostic behavior (and prevent regressions where the wrong plugin name is reported), assert that the logged call includes "unknown_plugin" (either in args or kwargs, depending on logging_error's signature).
| mock_err.assert_called_once() | |
| mock_err.assert_called_once() | |
| args, kwargs = mock_err.call_args | |
| # Ensure that the logged error message identifies the missing plugin | |
| combined = " ".join([str(a) for a in args] + [str(v) for v in kwargs.values()]) | |
| assert "unknown_plugin" in combined |
Adds BDD-style unit tests covering key control-flow branches and initial setup orchestration in `ardupilot_methodic_configurator.__main__`. Specific test additions include: - Validation logic for plugin registration (motor_test, battery_monitor). - Failure pathways for connection timeouts and non-writable directory fallbacks. - Correct firmware documentation rendering based on user application state. - Parameter editor pathing, component editor flows, and legacy GPS param renames. - Proper logging propagation on disk space exhaustion during FC backups. - Mocked end-to-end `main()` execution confirming graceful exit loops. Fixes: ArduPilot#1352 Signed-off-by: Omkar Sarkar <omkarsarkar24@gmail.com>
5c19da0 to
34ceb28
Compare
Signed-off-by: Omkar Sarkar <omkarsarkar24@gmail.com>
|
Fixed the pylint error , should be passing now :) |
amilcarlucas
left a comment
There was a problem hiding this comment.
Thanks for the tests, and the pylint fix. merged
Fixes: #1352
Tests addded for
__main__.py: