mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-21 07:32:28 +01:00
main was red on file length, the noqa ban, codespell, test naming and dart coverage; this change touches every one of those jobs. - sickdays: set_enabled is keyword-only; the panel test splits in two with shared probes; the sync wire format moves to DOCS-sync.md. - earned_time: _focus types the project as a Protocol, no noqa; the gate-maturity section moves to DOCS-maturity.md; codespell knows the `checkin` event name. - focus_project: real fixes for every noqa (local-day clocks, typed fakes, logged broad catches, split helpers). The public API that focus-guard calls keeps its signatures; their PLR0913 exemption lives in pyproject with the reason, not in noqa. - crdt-sync: pylint gets nacl/argon2, docstrings, and allows the public E2eLayout.of; _blobs moves to _e2e_blobs.py. - crdt_sync_dart: Argon2Params and the header errors move to e2e_params.dart (re-exported); tests split and reach 100% lines. - sql_drills: test helpers get a leading underscore, as in earned_time. Todo: fda71ed1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""The word-free controls and the drawn icons, against a real Tk."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tkinter as tk
|
|
|
|
import pytest
|
|
|
|
from sickdays._constants import LOCKERS
|
|
from sickdays.gui import _tokens as tok
|
|
from sickdays.gui._controls import IconButton, IconSlot, Toggle
|
|
from sickdays.gui._icons import ICONS, LOCKER_ICONS, TAG
|
|
|
|
|
|
@pytest.fixture
|
|
def shown(tk_root: tk.Tk) -> tk.Tk:
|
|
"""The root mapped, so real clicks reach the canvases."""
|
|
tk_root.deiconify()
|
|
tk_root.update()
|
|
return tk_root
|
|
|
|
|
|
def _click(widget: tk.Canvas) -> None:
|
|
widget.pack()
|
|
widget.update()
|
|
widget.event_generate("<Button-1>", x=2, y=2)
|
|
widget.update()
|
|
|
|
|
|
def test_every_icon_draws_something(tk_root: tk.Tk) -> None:
|
|
for icon in ICONS:
|
|
slot = IconSlot(tk_root, size=32).show(icon, tok.DANGER)
|
|
assert slot.icon == icon
|
|
assert slot.find_withtag(TAG), icon
|
|
assert slot.show(None).icon is None
|
|
assert slot.find_withtag(TAG) == ()
|
|
|
|
|
|
def test_every_locker_has_an_icon() -> None:
|
|
assert set(LOCKER_ICONS) == set(LOCKERS)
|
|
assert set(LOCKER_ICONS.values()) <= set(ICONS)
|
|
|
|
|
|
def test_a_click_invokes_the_button_unless_disabled(shown: tk.Tk) -> None:
|
|
calls: list[int] = []
|
|
button = IconButton(shown, "check", lambda: calls.append(1), name="ok")
|
|
button.set_enabled(enabled=False)
|
|
assert str(button.cget("cursor")) == "arrow"
|
|
_click(button)
|
|
button.invoke()
|
|
assert calls == []
|
|
button.set_enabled(enabled=True)
|
|
_click(button)
|
|
assert calls == [1]
|
|
|
|
|
|
def test_a_click_flips_the_switch_unless_disabled(shown: tk.Tk) -> None:
|
|
on = tk.BooleanVar(shown, value=False)
|
|
switch = Toggle(shown, on, name="switch")
|
|
_click(switch)
|
|
assert switch.is_on()
|
|
assert on.get()
|
|
switch.set_enabled(enabled=False)
|
|
_click(switch)
|
|
switch.invoke()
|
|
assert switch.is_on()
|
|
switch.set_enabled(enabled=True)
|
|
switch.invoke()
|
|
assert not switch.is_on()
|