mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
Add tests for crystal callback wiring in upload_using_esptool
Tests both the in-process (run_external_command) and subprocess (run_external_process) paths to ensure line_callbacks are passed.
This commit is contained in:
@@ -6,6 +6,7 @@ from collections.abc import Generator
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import time
|
||||
@@ -3360,3 +3361,63 @@ def test_crystal_freq_callback_no_crystal_line() -> None:
|
||||
assert callback("Chip type: ESP8684H") is None
|
||||
assert callback("MAC: a0:b7:65:8b:16:d4") is None
|
||||
assert callback("") is None
|
||||
|
||||
|
||||
def test_upload_using_esptool_passes_crystal_callback(
|
||||
tmp_path: Path,
|
||||
mock_run_external_command_main: Mock,
|
||||
mock_get_idedata: Mock,
|
||||
) -> None:
|
||||
"""Test that upload_using_esptool passes crystal freq callback for ESP32."""
|
||||
setup_core(platform=PLATFORM_ESP32, tmp_path=tmp_path, name="test")
|
||||
CORE.data[KEY_ESP32] = {KEY_VARIANT: VARIANT_ESP32}
|
||||
|
||||
# Create sdkconfig with XTAL_FREQ
|
||||
build_dir = Path(CORE.build_path)
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
sdkconfig = build_dir / "sdkconfig.test"
|
||||
sdkconfig.write_text("CONFIG_XTAL_FREQ=40\n")
|
||||
|
||||
mock_idedata = MagicMock(spec=platformio_api.IDEData)
|
||||
mock_idedata.firmware_bin_path = tmp_path / "firmware.bin"
|
||||
mock_idedata.extra_flash_images = []
|
||||
mock_get_idedata.return_value = mock_idedata
|
||||
(tmp_path / "firmware.bin").touch()
|
||||
|
||||
config = {CONF_ESPHOME: {"platformio_options": {}}}
|
||||
upload_using_esptool(config, "/dev/ttyUSB0", None, None)
|
||||
|
||||
# Verify line_callbacks was passed with the crystal callback
|
||||
call_kwargs = mock_run_external_command_main.call_args[1]
|
||||
assert "line_callbacks" in call_kwargs
|
||||
assert len(call_kwargs["line_callbacks"]) == 1
|
||||
|
||||
|
||||
def test_upload_using_esptool_subprocess_passes_crystal_callback(
|
||||
mock_run_external_process: Mock,
|
||||
mock_get_idedata: Mock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Test that crystal freq callback is passed via run_external_process."""
|
||||
setup_core(platform=PLATFORM_ESP32, tmp_path=tmp_path, name="test")
|
||||
CORE.data[KEY_ESP32] = {KEY_VARIANT: VARIANT_ESP32}
|
||||
|
||||
# Create sdkconfig with XTAL_FREQ
|
||||
build_dir = Path(CORE.build_path)
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
sdkconfig = build_dir / "sdkconfig.test"
|
||||
sdkconfig.write_text("CONFIG_XTAL_FREQ=40\n")
|
||||
|
||||
mock_idedata = MagicMock(spec=platformio_api.IDEData)
|
||||
mock_idedata.firmware_bin_path = tmp_path / "firmware.bin"
|
||||
mock_idedata.extra_flash_images = []
|
||||
mock_get_idedata.return_value = mock_idedata
|
||||
(tmp_path / "firmware.bin").touch()
|
||||
|
||||
config = {CONF_ESPHOME: {"platformio_options": {}}}
|
||||
with patch.dict(os.environ, {"ESPHOME_USE_SUBPROCESS": "1"}):
|
||||
upload_using_esptool(config, "/dev/ttyUSB0", None, None)
|
||||
|
||||
call_kwargs = mock_run_external_process.call_args[1]
|
||||
assert "line_callbacks" in call_kwargs
|
||||
assert len(call_kwargs["line_callbacks"]) == 1
|
||||
|
||||
Reference in New Issue
Block a user