|
12 | 12 |
|
13 | 13 | import copy |
14 | 14 | from typing import Any, Optional, TypeVar |
| 15 | +from unittest.mock import MagicMock |
15 | 16 |
|
16 | 17 | from ardupilot_methodic_configurator.backend_filesystem_vehicle_components import VehicleComponents |
| 18 | +from ardupilot_methodic_configurator.data_model_vehicle_components_display import ComponentDataModelDisplay |
17 | 19 | from ardupilot_methodic_configurator.data_model_vehicle_components_json_schema import VehicleComponentsJsonSchema |
18 | 20 |
|
19 | 21 | # Type variables for generic fixture factories |
|
163 | 165 | } |
164 | 166 |
|
165 | 167 |
|
| 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 | + |
166 | 176 | class ComponentDataModelFixtures: |
167 | 177 | """Factory class for creating component data model fixtures.""" |
168 | 178 |
|
@@ -254,6 +264,24 @@ def create_realistic_model(model_class: type[T]) -> T: |
254 | 264 | post_init({}) |
255 | 265 | return model |
256 | 266 |
|
| 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 | + |
257 | 285 |
|
258 | 286 | class CommonAssertions: |
259 | 287 | """Common assertion helpers for component data model tests.""" |
|
0 commit comments