mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-13 03:30:58 +01:00
Extracted from wake_alarm, screen-locker, and diet_guard, which each independently implemented fullscreen-lock, input-grab, VT-disable, and HMAC-signed-state mechanics at different levels of maturity (the HMAC module was already a hand-copied duplicate between two of them). LockConfig exposes overrideredirect/grab/disable_vt as independent axes so one LockWindow can reproduce all three projects' exact prior behavior, plus screen-locker's confirmed upgrade to retry-forever grab.
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""Tests for GateRoot's safe callback-exception handling."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from gatelock._root import GateRoot
|
|
|
|
|
|
def _make_root() -> GateRoot:
|
|
"""Build a GateRoot without running tk.Tk.__init__ (no display needed)."""
|
|
return GateRoot.__new__(GateRoot)
|
|
|
|
|
|
def _raise_boom() -> None:
|
|
"""Raise a ValueError for tests to catch via pytest.raises."""
|
|
msg = "boom"
|
|
raise ValueError(msg)
|
|
|
|
|
|
class TestReportCallbackException:
|
|
"""Tests for report_callback_exception."""
|
|
|
|
def test_calls_handler_when_set(self) -> None:
|
|
"""The configured handler is invoked on a callback error."""
|
|
root = _make_root()
|
|
handler = MagicMock()
|
|
root.on_callback_error = handler
|
|
|
|
with pytest.raises(ValueError, match="boom") as exc_info:
|
|
_raise_boom()
|
|
|
|
root.report_callback_exception(exc_info.type, exc_info.value, exc_info.tb)
|
|
|
|
handler.assert_called_once_with()
|
|
|
|
def test_does_not_raise_when_no_handler_set(self) -> None:
|
|
"""No handler configured: logs only, never re-raises."""
|
|
root = _make_root()
|
|
|
|
with pytest.raises(ValueError, match="boom") as exc_info:
|
|
_raise_boom()
|
|
|
|
root.report_callback_exception(exc_info.type, exc_info.value, exc_info.tb)
|