Skip to content

Commit 5c97bed

Browse files
committed
test(data_model_vehicle_components): Added more tests
1 parent 858f292 commit 5c97bed

13 files changed

Lines changed: 1918 additions & 97 deletions

ardupilot_methodic_configurator/data_model_vehicle_components_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def _set_esc_type_from_fc_parameters(self, fc_parameters: dict[str, float], doc:
328328
self.set_component_value(("ESC", "FC Connection", "Type"), "AIO")
329329

330330
if "MOT_PWM_TYPE" in doc and "values" in doc["MOT_PWM_TYPE"]:
331-
protocol = str(doc["MOT_PWM_TYPE"]["values"].get(str(mot_pwm_type)))
331+
protocol = doc["MOT_PWM_TYPE"]["values"].get(str(mot_pwm_type), "")
332332
if protocol:
333333
self.set_component_value(("ESC", "FC Connection", "Protocol"), protocol)
334334
# Fallback to MOT_PWM_TYPE_DICT if doc is not available

tests/test_battery_cell_voltages.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

tests/test_data_model_vehicle_components_common.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
import copy
1414
from typing import Any, Optional, TypeVar
15+
from unittest.mock import MagicMock
1516

1617
from ardupilot_methodic_configurator.backend_filesystem_vehicle_components import VehicleComponents
18+
from ardupilot_methodic_configurator.data_model_vehicle_components_display import ComponentDataModelDisplay
1719
from ardupilot_methodic_configurator.data_model_vehicle_components_json_schema import VehicleComponentsJsonSchema
1820

1921
# Type variables for generic fixture factories
@@ -163,6 +165,14 @@
163165
}
164166

165167

168+
def make_fc_schema(fc_body: dict[str, Any], *, definitions: Optional[dict[str, Any]] = None) -> dict[str, Any]:
169+
"""Build a minimal schema dict wrapping a single Flight Controller component body."""
170+
schema: dict[str, Any] = {"properties": {"Components": {"properties": {"Flight Controller": fc_body}}}}
171+
if definitions is not None:
172+
schema["definitions"] = definitions
173+
return schema
174+
175+
166176
class ComponentDataModelFixtures:
167177
"""Factory class for creating component data model fixtures."""
168178

@@ -254,6 +264,24 @@ def create_realistic_model(model_class: type[T]) -> T:
254264
post_init({})
255265
return model
256266

267+
@staticmethod
268+
def create_mock_schema() -> MagicMock:
269+
"""Create a mock schema with default non-optional behavior."""
270+
schema = MagicMock()
271+
schema.get_component_property_description.return_value = ("Test description", False)
272+
return schema
273+
274+
@staticmethod
275+
def create_display_model_with_mock_schema(mock_schema: MagicMock) -> ComponentDataModelDisplay:
276+
"""Create a ComponentDataModelDisplay instance backed by a mock schema."""
277+
initial_data: dict[str, Any] = {"Components": {}, "Format version": 1}
278+
component_datatypes: dict[str, Any] = {"Flight Controller": {"Product": {"Manufacturer": str}}}
279+
schema_dict = ComponentDataModelFixtures.create_simple_schema()
280+
schema = VehicleComponentsJsonSchema(schema_dict)
281+
model = ComponentDataModelDisplay(initial_data, component_datatypes, schema)
282+
model.schema = mock_schema
283+
return model
284+
257285

258286
class CommonAssertions:
259287
"""Common assertion helpers for component data model tests."""

tests/test_data_model_vehicle_components_display.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,20 @@
1616
from test_data_model_vehicle_components_common import ComponentDataModelFixtures
1717

1818
from ardupilot_methodic_configurator.data_model_vehicle_components_display import ComponentDataModelDisplay
19-
from ardupilot_methodic_configurator.data_model_vehicle_components_json_schema import VehicleComponentsJsonSchema
2019

2120
# pylint: disable=redefined-outer-name
2221

2322

2423
@pytest.fixture
2524
def mock_schema() -> MagicMock:
2625
"""Fixture providing a mock schema for display testing."""
27-
schema = MagicMock()
28-
29-
# Default behavior: non-optional components
30-
schema.get_component_property_description.return_value = ("Test description", False)
31-
32-
return schema
26+
return ComponentDataModelFixtures.create_mock_schema()
3327

3428

3529
@pytest.fixture
3630
def display_model(mock_schema) -> ComponentDataModelDisplay:
3731
"""Fixture providing a ComponentDataModelDisplay instance for testing."""
38-
# Create minimal required dependencies
39-
initial_data = {"Components": {}, "Format version": 1}
40-
component_datatypes = {"Flight Controller": {"Product": {"Manufacturer": str}}}
41-
schema_dict = ComponentDataModelFixtures.create_simple_schema()
42-
schema = VehicleComponentsJsonSchema(schema_dict)
43-
44-
# Create and configure the display model
45-
model = ComponentDataModelDisplay(initial_data, component_datatypes, schema)
46-
# Override with mock schema for easier testing
47-
model.schema = mock_schema
48-
return model
32+
return ComponentDataModelFixtures.create_display_model_with_mock_schema(mock_schema)
4933

5034

5135
@pytest.fixture

0 commit comments

Comments
 (0)