screen-locker/screen_locker/tests/test_errors.py
Krzysztof kuhy Rudnicki 9e7f536f96
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Report errors and stalls to the shared board
gatelock error_report: uncaught, thread and Tk callback errors plus a
frozen lock window over 1 s go to the app-errors spool. The pre-commit
pylint env moves to gatelock 0.16.0, the version requirements pin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:00:15 +01:00

62 lines
2.2 KiB
Python

"""screen-locker's error reporting: installed once, into the shared spool."""
from __future__ import annotations
import contextlib
import json
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch
from screen_locker import _cli, _errors, screen_lock
from screen_locker.screen_lock import ScreenLocker
from screen_locker.tests._locker_factories import create_locker
if TYPE_CHECKING:
from pathlib import Path
import pytest
def test_install_keeps_the_reporter_and_writes_the_spool(tmp_path: Path) -> None:
"""The CLI's install names this app and its repo in every report."""
rep = _errors.install()
assert _errors.SLOT.reporter is rep
assert rep.app == "screen-locker"
rep.report("uncaught.python", ValueError("deliberate"))
line = (tmp_path / "app-errors-spool" / "screen-locker.jsonl").read_text()
entry = json.loads(line)
assert entry["repo"] == "kuhyx/screen-locker"
assert entry["error"] == "ValueError: deliberate"
def test_cli_installs_the_reporter_before_any_mode() -> None:
"""Every mode, headless ones included, runs with errors hooked."""
with (
patch.object(_cli, "run_status", side_effect=SystemExit(0)),
patch.object(_cli, "_headless_locker"),
contextlib.suppress(SystemExit),
):
_cli.main(ScreenLocker, ["screen_lock.py", "--status"])
assert _errors.SLOT.reporter is not None
def test_lock_window_watches_stalls_once_installed(
monkeypatch: pytest.MonkeyPatch, mock_tk: MagicMock, tmp_path: Path
) -> None:
"""A lock window built after install reports its own freezes."""
watch = MagicMock()
monkeypatch.setattr(screen_lock, "watch_stalls", watch)
monkeypatch.setattr(_errors.SLOT, "reporter", MagicMock())
locker = create_locker(mock_tk, tmp_path)
watch.assert_called_once_with(locker.root, _errors.SLOT.reporter)
def test_lock_window_skips_the_watch_without_install(
monkeypatch: pytest.MonkeyPatch, mock_tk: MagicMock, tmp_path: Path
) -> None:
"""Tests and library callers that never installed get no watch."""
watch = MagicMock()
monkeypatch.setattr(screen_lock, "watch_stalls", watch)
create_locker(mock_tk, tmp_path)
watch.assert_not_called()