from __future__ import annotations from unittest.mock import MagicMock, patch import pytest from gpiozero import Device from gpiozero.pins.mock import MockFactory from PIL import Image from planemapper.display import NullDisplay from planemapper.gpio_ctrl import LEDController from planemapper.main import _handle_reset @pytest.fixture(autouse=True) def mock_gpio(): Device.pin_factory = MockFactory() def test_reset_wipes_config_and_execvp(): display = NullDisplay() led = LEDController() with patch("planemapper.main.wipe_config") as mock_wipe: with patch("planemapper.main.os.execvp") as mock_exec: _handle_reset(display, led) mock_wipe.assert_called_once() mock_exec.assert_called_once_with("planemapper-provision", ["planemapper-provision"]) def test_reset_shows_setup_screen(): display = MagicMock() led = LEDController() with patch("planemapper.main.wipe_config"): with patch("planemapper.main.os.execvp"): _handle_reset(display, led) display.show.assert_called_once() img = display.show.call_args[0][0] assert isinstance(img, Image.Image) assert img.size == (800, 480) def test_reset_does_not_execvp_on_wipe_failure(): display = NullDisplay() led = LEDController() with patch("planemapper.main.wipe_config", side_effect=PermissionError("no perms")): with patch("planemapper.main.os.execvp") as mock_exec: _handle_reset(display, led) mock_exec.assert_not_called()