mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-06 12:52:04 +00:00
Refine exception handling
This commit is contained in:
1 parent
ade2d99572
commit
87cf2d837b
4 files changed
+74
-5
No files matched your search
@@ -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
|
||||
@@ -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