test(data_model_vehicle_components): Added more tests#1463
test(data_model_vehicle_components): Added more tests#1463amilcarlucas merged 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Expands unit-test coverage across the vehicle components data model modules (schema, import, display, validation, templates) and refines a couple of import/validation code paths to better align with expected inputs.
Changes:
- Added multiple new unit tests targeting previously uncovered branches across data model modules.
- Introduced shared test helper
make_fc_schemato simplify minimal schema construction in tests. - Tweaked import/validation logic (ESC protocol lookup default, removed some redundant parsing/guards) and migrated battery voltage tests to pytest style.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit_data_model_vehicle_components_json_schema.py | Adds branch-coverage unit tests for VehicleComponentsJsonSchema helpers and error logs. |
| tests/unit_data_model_vehicle_components_import.py | Adds unit tests for battery-type setting and validation-guard behavior. |
| tests/unit_data_model_vehicle_components_display.py | New unit test file to cover internal ComponentDataModelDisplay branches. |
| tests/unit_data_model_vehicle_components_base.py | Adds unit tests for uncovered branches in ComponentDataModelBase. |
| tests/unit_battery_cell_voltages.py | New pytest-based unit tests for battery_cell_voltages functionality. |
| tests/test_data_model_vehicle_components_validation.py | Adds extensive uncovered-branch tests for validation logic. |
| tests/test_data_model_vehicle_components_templates.py | Adds test for creating missing "Components" root key. |
| tests/test_data_model_vehicle_components_json_schema.py | Adds a small new branch-coverage test class for schema behavior. |
| tests/test_data_model_vehicle_components_import.py | Adds many uncovered-branch tests for import edge cases (bitmasks, fallbacks, warnings/errors). |
| tests/test_data_model_vehicle_components_common.py | Adds make_fc_schema helper to support new schema tests. |
| tests/test_battery_cell_voltages.py | Removes old unittest-based battery voltage tests (replaced by pytest unit tests). |
| ardupilot_methodic_configurator/data_model_vehicle_components_validation.py | Removes some parsing/ValueError guards and adjusts pylint directives. |
| ardupilot_methodic_configurator/data_model_vehicle_components_import.py | Fixes ESC protocol lookup default to avoid unintended "None" protocol strings. |
ardupilot_methodic_configurator/data_model_vehicle_components_validation.py
Outdated
Show resolved
Hide resolved
ardupilot_methodic_configurator/data_model_vehicle_components_validation.py
Outdated
Show resolved
Hide resolved
ardupilot_methodic_configurator/data_model_vehicle_components_validation.py
Outdated
Show resolved
Hide resolved
| schema = { | ||
| "properties": { | ||
| "Components": { | ||
| "Flight Controller": { | ||
| "description": "FC", | ||
| "properties": {"Product": {"description": "Product info"}}, | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This schema shape doesn’t match the other tests (and typical JSON schema structure) where components live under schema["properties"]["Components"]["properties"]. As written, this test may be exercising “malformed schema” behavior rather than the intended “missing section” behavior. Recommendation (mandatory for test correctness): adjust the fixture to nest "Flight Controller" under "Components": {"properties": {...}} so the test isolates the missing-section condition.
tests/unit_battery_cell_voltages.py
Outdated
| def test_best_chemistry_for_voltage_returns_none_for_ambiguous_voltage(self) -> None: | ||
| """best_chemistry_for_voltage returns None when no chemistry gives a near-integer cell count.""" | ||
| # 10.0 V doesn't divide cleanly by common cell voltages → no clear winner | ||
| result = BatteryCell.best_chemistry_for_voltage(10.0, "Volt per cell max") | ||
| # May or may not match - the important thing is no exception; result can be None or a string | ||
| assert result is None or isinstance(result, str) |
There was a problem hiding this comment.
The docstring states the function “returns None” for ambiguous voltage, but the assertion allows any string as well, which makes the test non-verifying and contradicts its own documentation. Recommendation (mandatory): either (a) assert result is None using a voltage you expect to be ambiguous deterministically, or (b) update the docstring/test intent to reflect the function’s actual contract (e.g., “may return None”) and validate a more specific property of the result.
| def test_best_chemistry_for_voltage_returns_none_for_ambiguous_voltage(self) -> None: | |
| """best_chemistry_for_voltage returns None when no chemistry gives a near-integer cell count.""" | |
| # 10.0 V doesn't divide cleanly by common cell voltages → no clear winner | |
| result = BatteryCell.best_chemistry_for_voltage(10.0, "Volt per cell max") | |
| # May or may not match - the important thing is no exception; result can be None or a string | |
| assert result is None or isinstance(result, str) | |
| def test_best_chemistry_for_voltage_returns_none_or_valid_chemistry_for_ambiguous_voltage(self) -> None: | |
| """best_chemistry_for_voltage may return None or a known chemistry for an ambiguous voltage.""" | |
| # 10.0 V may be ambiguous depending on scoring; if a match is returned, it must be a known chemistry. | |
| result = BatteryCell.best_chemistry_for_voltage(10.0, "Volt per cell max") | |
| assert result is None or result in BatteryCell.chemistries() |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified FilesNo covered modified files...
|
Test Results 4 files ± 0 4 suites ±0 41m 1s ⏱️ +4s Results for commit f6523d9. ± Comparison against base commit ca776fa. This pull request removes 9 and adds 112 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
No description provided.