mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 08:19:23 +00:00
Refine exception handling
This commit is contained in:
24
src/tests/test_load_global_config.py
Normal file
24
src/tests/test_load_global_config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Tests for load_global_config failure scenarios."""
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from main import load_global_config
|
||||
|
||||
|
||||
def test_load_global_config_invalid_toml(monkeypatch, tmp_path, caplog):
|
||||
"""Invalid TOML should log a warning and return an empty dict."""
|
||||
config_dir = tmp_path / ".seedpass"
|
||||
config_dir.mkdir()
|
||||
config_file = config_dir / "config.toml"
|
||||
config_file.write_text("invalid = [")
|
||||
|
||||
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
result = load_global_config()
|
||||
|
||||
assert result == {}
|
||||
assert "Failed to read" in caplog.text
|
37
src/tests/test_terminal_utils_failure_handling.py
Normal file
37
src/tests/test_terminal_utils_failure_handling.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Tests for terminal utility failure handling."""
|
||||
|
||||
import logging
|
||||
import pytest
|
||||
|
||||
from utils.terminal_utils import (
|
||||
clear_header_with_notification,
|
||||
format_profile,
|
||||
)
|
||||
|
||||
|
||||
class ErrorFingerprintManager:
|
||||
def get_name(self, _fingerprint): # pragma: no cover - helper
|
||||
raise ValueError("boom")
|
||||
|
||||
|
||||
class ErrorPM:
|
||||
fingerprint_manager = ErrorFingerprintManager()
|
||||
|
||||
def get_current_notification(self): # pragma: no cover - helper
|
||||
raise RuntimeError("bad")
|
||||
|
||||
|
||||
def test_format_profile_reraises(monkeypatch, caplog):
|
||||
pm = ErrorPM()
|
||||
with caplog.at_level(logging.ERROR):
|
||||
with pytest.raises(ValueError):
|
||||
format_profile("abc", pm)
|
||||
assert "Error retrieving name for fingerprint" in caplog.text
|
||||
|
||||
|
||||
def test_clear_header_with_notification_reraises(caplog):
|
||||
pm = ErrorPM()
|
||||
with caplog.at_level(logging.ERROR):
|
||||
with pytest.raises(RuntimeError):
|
||||
clear_header_with_notification(pm)
|
||||
assert "Error getting current notification" in caplog.text
|
Reference in New Issue
Block a user