Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _set_esc_type_from_fc_parameters(self, fc_parameters: dict[str, float], doc:
self.set_component_value(("ESC", "FC Connection", "Type"), "AIO")

if "MOT_PWM_TYPE" in doc and "values" in doc["MOT_PWM_TYPE"]:
protocol = str(doc["MOT_PWM_TYPE"]["values"].get(str(mot_pwm_type)))
protocol = doc["MOT_PWM_TYPE"]["values"].get(str(mot_pwm_type), "")
if protocol:
self.set_component_value(("ESC", "FC Connection", "Protocol"), protocol)
# Fallback to MOT_PWM_TYPE_DICT if doc is not available
Expand Down
78 changes: 0 additions & 78 deletions tests/test_battery_cell_voltages.py

This file was deleted.

28 changes: 28 additions & 0 deletions tests/test_data_model_vehicle_components_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

import copy
from typing import Any, Optional, TypeVar
from unittest.mock import MagicMock

from ardupilot_methodic_configurator.backend_filesystem_vehicle_components import VehicleComponents
from ardupilot_methodic_configurator.data_model_vehicle_components_display import ComponentDataModelDisplay
from ardupilot_methodic_configurator.data_model_vehicle_components_json_schema import VehicleComponentsJsonSchema

# Type variables for generic fixture factories
Expand Down Expand Up @@ -163,6 +165,14 @@
}


def make_fc_schema(fc_body: dict[str, Any], *, definitions: Optional[dict[str, Any]] = None) -> dict[str, Any]:
"""Build a minimal schema dict wrapping a single Flight Controller component body."""
schema: dict[str, Any] = {"properties": {"Components": {"properties": {"Flight Controller": fc_body}}}}
if definitions is not None:
schema["definitions"] = definitions
return schema


class ComponentDataModelFixtures:
"""Factory class for creating component data model fixtures."""

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

@staticmethod
def create_mock_schema() -> MagicMock:
"""Create a mock schema with default non-optional behavior."""
schema = MagicMock()
schema.get_component_property_description.return_value = ("Test description", False)
return schema

@staticmethod
def create_display_model_with_mock_schema(mock_schema: MagicMock) -> ComponentDataModelDisplay:
"""Create a ComponentDataModelDisplay instance backed by a mock schema."""
initial_data: dict[str, Any] = {"Components": {}, "Format version": 1}
component_datatypes: dict[str, Any] = {"Flight Controller": {"Product": {"Manufacturer": str}}}
schema_dict = ComponentDataModelFixtures.create_simple_schema()
schema = VehicleComponentsJsonSchema(schema_dict)
model = ComponentDataModelDisplay(initial_data, component_datatypes, schema)
model.schema = mock_schema
return model


class CommonAssertions:
"""Common assertion helpers for component data model tests."""
Expand Down
20 changes: 2 additions & 18 deletions tests/test_data_model_vehicle_components_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,20 @@
from test_data_model_vehicle_components_common import ComponentDataModelFixtures

from ardupilot_methodic_configurator.data_model_vehicle_components_display import ComponentDataModelDisplay
from ardupilot_methodic_configurator.data_model_vehicle_components_json_schema import VehicleComponentsJsonSchema

# pylint: disable=redefined-outer-name


@pytest.fixture
def mock_schema() -> MagicMock:
"""Fixture providing a mock schema for display testing."""
schema = MagicMock()

# Default behavior: non-optional components
schema.get_component_property_description.return_value = ("Test description", False)

return schema
return ComponentDataModelFixtures.create_mock_schema()


@pytest.fixture
def display_model(mock_schema) -> ComponentDataModelDisplay:
"""Fixture providing a ComponentDataModelDisplay instance for testing."""
# Create minimal required dependencies
initial_data = {"Components": {}, "Format version": 1}
component_datatypes = {"Flight Controller": {"Product": {"Manufacturer": str}}}
schema_dict = ComponentDataModelFixtures.create_simple_schema()
schema = VehicleComponentsJsonSchema(schema_dict)

# Create and configure the display model
model = ComponentDataModelDisplay(initial_data, component_datatypes, schema)
# Override with mock schema for easier testing
model.schema = mock_schema
return model
return ComponentDataModelFixtures.create_display_model_with_mock_schema(mock_schema)


@pytest.fixture
Expand Down
Loading
Loading