1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 20:02:22 +01:00

[mipi_spi] Template code, partial buffer support (#9314)

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
Clyde Stubbs
2025-07-16 11:05:27 +10:00
committed by GitHub
parent 5480675dd8
commit 6486147da1
42 changed files with 1430 additions and 1113 deletions

View File

@@ -5,18 +5,30 @@ from __future__ import annotations
from collections.abc import Callable, Generator
from pathlib import Path
import sys
from typing import Any
import pytest
from esphome import config, final_validate
from esphome.const import (
KEY_CORE,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PlatformFramework,
)
from esphome.types import ConfigType
# Add package root to python path
here = Path(__file__).parent
package_root = here.parent.parent
sys.path.insert(0, package_root.as_posix())
from esphome.__main__ import generate_cpp_contents # noqa: E402
from esphome.config import read_config # noqa: E402
from esphome.config import Config, read_config # noqa: E402
from esphome.core import CORE # noqa: E402
from .types import SetCoreConfigCallable # noqa: E402
@pytest.fixture(autouse=True)
def config_path(request: pytest.FixtureRequest) -> Generator[None]:
@@ -36,6 +48,59 @@ def config_path(request: pytest.FixtureRequest) -> Generator[None]:
CORE.config_path = original_path
@pytest.fixture(autouse=True)
def reset_core() -> Generator[None]:
"""Reset CORE after each test."""
yield
CORE.reset()
@pytest.fixture
def set_core_config() -> Generator[SetCoreConfigCallable]:
"""Fixture to set up the core configuration for tests."""
def setter(
platform_framework: PlatformFramework,
/,
*,
core_data: ConfigType | None = None,
platform_data: ConfigType | None = None,
) -> None:
platform, framework = platform_framework.value
# Set base core configuration
CORE.data[KEY_CORE] = {
KEY_TARGET_PLATFORM: platform.value,
KEY_TARGET_FRAMEWORK: framework.value,
}
# Update with any additional core data
if core_data:
CORE.data[KEY_CORE].update(core_data)
# Set platform-specific data
if platform_data:
CORE.data[platform.value] = platform_data
config.path_context.set([])
final_validate.full_config.set(Config())
yield setter
@pytest.fixture
def set_component_config() -> Callable[[str, Any], None]:
"""
Fixture to set a component configuration in the mock config.
This must be used after the core configuration has been set up.
"""
def setter(name: str, value: Any) -> None:
final_validate.full_config.get()[name] = value
return setter
@pytest.fixture
def component_fixture_path(request: pytest.FixtureRequest) -> Callable[[str], Path]:
"""Return a function to get absolute paths relative to the component's fixtures directory."""
@@ -60,7 +125,7 @@ def component_config_path(request: pytest.FixtureRequest) -> Callable[[str], Pat
@pytest.fixture
def generate_main() -> Generator[Callable[[str | Path], str]]:
"""Generates the C++ main.cpp file and returns it in string form."""
"""Generates the C++ main.cpp from a given yaml file and returns it in string form."""
def generator(path: str | Path) -> str:
CORE.config_path = str(path)
@@ -69,5 +134,3 @@ def generate_main() -> Generator[Callable[[str | Path], str]]:
return CORE.cpp_main_section
yield generator
CORE.reset()