Compare commits

..

2 Commits

Author SHA1 Message Date
dd3b220a4a test: use shared config fixture 2025-12-30 23:09:01 +01:00
82b99da50d test: add config_with_tmp_path fixture 2025-12-30 23:08:51 +01:00
3 changed files with 19 additions and 27 deletions

View File

@@ -1,7 +1,10 @@
from pathlib import Path
from typing import Iterable, Callable
import pytest
from skywipe.configure import Configuration
@pytest.fixture
def user_input(monkeypatch) -> Callable[[Iterable[str], Iterable[str]], None]:
@@ -14,3 +17,9 @@ def user_input(monkeypatch) -> Callable[[Iterable[str], Iterable[str]], None]:
lambda _prompt: next(password_iter))
return _set
@pytest.fixture
def config_with_tmp_path(monkeypatch, tmp_path):
monkeypatch.setattr(Path, "home", lambda: tmp_path)
return Configuration()

View File

@@ -1,11 +1,8 @@
from pathlib import Path
import yaml
from skywipe.configure import Configuration
def test_configuration_create_reprompts_and_writes_file(monkeypatch, tmp_path, user_input):
def test_configuration_create_reprompts_and_writes_file(config_with_tmp_path, user_input):
inputs = iter([
"bad handle",
"alice.bsky.social",
@@ -18,10 +15,9 @@ def test_configuration_create_reprompts_and_writes_file(monkeypatch, tmp_path, u
"longenough",
])
monkeypatch.setattr(Path, "home", lambda: tmp_path)
user_input(inputs, passwords)
config = Configuration()
config = config_with_tmp_path
config.create()
assert config.config_file.exists() is True
@@ -33,7 +29,7 @@ def test_configuration_create_reprompts_and_writes_file(monkeypatch, tmp_path, u
assert data["verbose"] is False
def test_configuration_create_invalid_batch_size(monkeypatch, tmp_path, user_input):
def test_configuration_create_invalid_batch_size(config_with_tmp_path, user_input):
inputs = iter([
"alice.bsky.social",
"0",
@@ -42,16 +38,15 @@ def test_configuration_create_invalid_batch_size(monkeypatch, tmp_path, user_inp
])
passwords = iter(["longenough"])
monkeypatch.setattr(Path, "home", lambda: tmp_path)
user_input(inputs, passwords)
config = Configuration()
config = config_with_tmp_path
config.create()
assert config.config_file.exists() is False
def test_configuration_create_invalid_delay(monkeypatch, tmp_path, user_input):
def test_configuration_create_invalid_delay(config_with_tmp_path, user_input):
inputs = iter([
"alice.bsky.social",
"10",
@@ -60,18 +55,16 @@ def test_configuration_create_invalid_delay(monkeypatch, tmp_path, user_input):
])
passwords = iter(["longenough"])
monkeypatch.setattr(Path, "home", lambda: tmp_path)
user_input(inputs, passwords)
config = Configuration()
config = config_with_tmp_path
config.create()
assert config.config_file.exists() is False
def test_configuration_create_overwrite_cancel(monkeypatch, tmp_path, user_input):
monkeypatch.setattr(Path, "home", lambda: tmp_path)
config = Configuration()
def test_configuration_create_overwrite_cancel(config_with_tmp_path, user_input):
config = config_with_tmp_path
config.config_file.parent.mkdir(parents=True, exist_ok=True)
config.config_file.write_text("existing")
@@ -82,14 +75,13 @@ def test_configuration_create_overwrite_cancel(monkeypatch, tmp_path, user_input
assert config.config_file.read_text() == "existing"
def test_configuration_create_write_failure(monkeypatch, tmp_path, user_input):
monkeypatch.setattr(Path, "home", lambda: tmp_path)
def test_configuration_create_write_failure(config_with_tmp_path, user_input, monkeypatch):
user_input(
["alice.bsky.social", "5", "0", "y"],
["longenough"],
)
config = Configuration()
config = config_with_tmp_path
original_open = open

View File

@@ -1,17 +1,8 @@
from pathlib import Path
from unittest.mock import patch
import pytest
import yaml
from skywipe.configure import Configuration
@pytest.fixture
def config_with_tmp_path(monkeypatch, tmp_path):
monkeypatch.setattr(Path, "home", lambda: tmp_path)
return Configuration()
def test_configuration_load_missing_file(config_with_tmp_path):
with pytest.raises(FileNotFoundError, match="Configuration file not found"):