mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-14 09:10:58 +01:00
The three Python packages pinned ruff twice at different versions: requirements.txt at 0.16.7, .pre-commit-config.yaml at v0.15.2. Only the older one ever ran, so `select = ["ALL"]` was enforced two minor versions behind. Measured before aligning: v0.15.2 reports 0 findings, every 0.16.x reports CPY001 on each file -- 70 crdt-sync, 23 freedays, 71 gatelock, and no other rule. Resolved by adding the notice rather than ignoring the rule, so the gate keeps its teeth. Two gatelock modules sat at exactly the 250-line cap, so a one-line header tipped them to 251. Both are split along a real seam rather than shaved: _widget_fills.py colour arithmetic over LockConfig, no tkinter import _surfaces_focus.py selects among existing surfaces, never mutates them The focus split keeps _surfaces.py's documented containment (it stays the only module that creates, moves or destroys windows), and the static guard in test_recovery_invariants.py globs _surfaces*.py, so the new sibling is covered with no list to extend. widgets.py re-exports the fills helpers, which keeps gatelock.widgets the single public surface its tests import. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019kMvSMtsVMB3d2uoZ56pbp
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""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)
|