Add tests for command line handling and user detection

Test how command line and config values are combined, the exit codes for an incomplete SSH setup and a bad config, and the user detection under sudo/doas (simulated by patching geteuid and the environment).
This commit is contained in:
Fuxino
2026-10-14 08:10:02 +02:00
parent 41a45dad41
commit dbb0aadc84
2 changed files with 333 additions and 0 deletions
+15
View File
@@ -1,5 +1,8 @@
"""Shared fixtures for the simple_backup tests"""
import sys
from typing import Callable
import pytest
from simple_backup import simple_backup as sb
@@ -13,3 +16,15 @@ def no_side_effects(monkeypatch: pytest.MonkeyPatch) -> None:
sb.logger.removeHandler(sb.j_handler)
monkeypatch.setattr(sb, '_notify', lambda text: None)
@pytest.fixture
def run_cli(monkeypatch: pytest.MonkeyPatch) -> Callable[..., int]:
"""Run simple_backup() with the given command line arguments"""
def run(*argv: str) -> int:
monkeypatch.setattr(sys, 'argv', ['simple_backup', *argv])
return sb.simple_backup()
return run