Integrate Espressif's QEMU fork for virtual ESP device management: - QemuManager component with 5 MCP tools (start/stop/list/status/flash) - Config auto-detects QEMU binaries from ~/.espressif/tools/ - Supports esp32, esp32s2, esp32s3, esp32c3 chip emulation - Virtual serial over TCP (socket://localhost:PORT) transparent to esptool - Scan integration: QEMU instances appear in esp_scan_ports results - Blank flash images initialized to 0xFF (erased NOR flash state) - 38 unit tests covering lifecycle, port allocation, flash writes
85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
"""
|
|
Test configuration management
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from mcp_esptool_server.config import ESPToolServerConfig
|
|
|
|
|
|
def test_config_from_environment():
|
|
"""Test configuration creation from environment variables"""
|
|
config = ESPToolServerConfig.from_environment()
|
|
|
|
assert config.esptool_path == "esptool" # default value
|
|
assert config.default_baud_rate == 460800
|
|
assert config.connection_timeout == 30
|
|
assert config.enable_stub_flasher is True
|
|
assert config.production_mode is False
|
|
|
|
|
|
def test_config_environment_override():
|
|
"""Test environment variable override"""
|
|
from unittest.mock import patch
|
|
|
|
# Set test environment variables
|
|
test_env = {
|
|
"ESPTOOL_PATH": "/custom/esptool",
|
|
"ESP_DEFAULT_BAUD_RATE": "115200",
|
|
"PRODUCTION_MODE": "true",
|
|
}
|
|
|
|
# Temporarily override environment
|
|
original_env = {}
|
|
for key, value in test_env.items():
|
|
original_env[key] = os.getenv(key)
|
|
os.environ[key] = value
|
|
|
|
try:
|
|
# Mock tool availability check to always return True
|
|
with patch.object(ESPToolServerConfig, "_check_tool_availability", return_value=True):
|
|
config = ESPToolServerConfig.from_environment()
|
|
assert config.esptool_path == "/custom/esptool"
|
|
assert config.default_baud_rate == 115200
|
|
assert config.production_mode is True
|
|
finally:
|
|
# Restore original environment
|
|
for key, value in original_env.items():
|
|
if value is None:
|
|
os.environ.pop(key, None)
|
|
else:
|
|
os.environ[key] = value
|
|
|
|
|
|
def test_config_to_dict():
|
|
"""Test configuration serialization"""
|
|
config = ESPToolServerConfig()
|
|
config_dict = config.to_dict()
|
|
|
|
assert isinstance(config_dict, dict)
|
|
assert "esptool_path" in config_dict
|
|
assert "default_baud_rate" in config_dict
|
|
assert "production_mode" in config_dict
|
|
|
|
|
|
def test_common_ports():
|
|
"""Test common port detection"""
|
|
config = ESPToolServerConfig()
|
|
ports = config.get_common_ports()
|
|
|
|
assert isinstance(ports, list)
|
|
assert len(ports) > 0 # Should return some ports for any platform
|
|
|
|
|
|
@pytest.mark.skipif(not Path("/usr/bin/esptool").exists(), reason="esptool not found")
|
|
def test_tool_availability():
|
|
"""Test tool availability check"""
|
|
config = ESPToolServerConfig()
|
|
|
|
# This should work if esptool is in PATH
|
|
available = config._check_tool_availability("esptool")
|
|
assert isinstance(available, bool)
|