test: cover confirmation prompt handling

This commit is contained in:
2025-12-23 04:47:06 +01:00
parent 02364e54c6
commit 875feb204c

36
tests/test_safeguard.py Normal file
View File

@@ -0,0 +1,36 @@
import logging
import pytest
from skywipe.safeguard import require_confirmation
def test_require_confirmation_skips_prompt():
logger = logging.getLogger("test.safeguard")
require_confirmation("do nothing", skip_confirmation=True, logger=logger)
def test_require_confirmation_accepts_yes(monkeypatch):
logger = logging.getLogger("test.safeguard")
monkeypatch.setattr("builtins.input", lambda _: "y")
require_confirmation("do nothing", logger=logger)
def test_require_confirmation_rejects_no(monkeypatch):
logger = logging.getLogger("test.safeguard")
monkeypatch.setattr("builtins.input", lambda _: "n")
with pytest.raises(SystemExit) as excinfo:
require_confirmation("do nothing", logger=logger)
assert excinfo.value.code == 0
def test_require_confirmation_handles_eof(monkeypatch):
logger = logging.getLogger("test.safeguard")
def raise_eof(_prompt):
raise EOFError
monkeypatch.setattr("builtins.input", raise_eof)
with pytest.raises(SystemExit) as excinfo:
require_confirmation("do nothing", logger=logger)
assert excinfo.value.code == 0