mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-17 21:45:08 +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>
103 lines
3.0 KiB
Python
103 lines
3.0 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""Redirect every on-disk path, and the free-day pool, away from real state.
|
|
|
|
Every writer resolves its paths through :func:`sickdays._paths.resolve_paths`,
|
|
so redirecting that one function in each module that imports it moves all of
|
|
them, including any file added later.
|
|
|
|
The GUI modules are in the list too, and their background sync is stubbed:
|
|
a test thread must never find the real crdt-sync credential.
|
|
|
|
The cross-pool check would otherwise import the real freedays and read the
|
|
real ``~/.local/share/freedays`` pool, so it is stubbed to "nothing is free"
|
|
for every test; tests of the check itself pass their own predicate.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
|
|
from sickdays._paths import Paths
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Iterator
|
|
from datetime import date
|
|
from pathlib import Path
|
|
import tkinter as tk
|
|
|
|
_MODULES = (
|
|
"sickdays._api",
|
|
"sickdays._audit",
|
|
"sickdays._conflict",
|
|
"sickdays._keep_api",
|
|
"sickdays._sync",
|
|
"sickdays.gui._panel",
|
|
"sickdays.gui._window",
|
|
)
|
|
|
|
|
|
def _never_free(_day: date) -> bool:
|
|
return False
|
|
|
|
|
|
def _no_sync(*, paths: Paths | None = None) -> bool:
|
|
"""The GUI's background sync, stubbed: no test may reach Firebase."""
|
|
del paths
|
|
return False
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _redirect_state(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
"""Point every default path at ``tmp_path`` before any test runs."""
|
|
state = tmp_path / "state"
|
|
state.mkdir()
|
|
redirected = Paths.under(state)
|
|
|
|
def _resolve(paths: Paths | None) -> Paths:
|
|
return paths if paths is not None else redirected
|
|
|
|
for module in _MODULES:
|
|
monkeypatch.setattr(f"{module}.resolve_paths", _resolve)
|
|
monkeypatch.setattr("sickdays._api.free_day_predicate", lambda: _never_free)
|
|
monkeypatch.setattr("sickdays.gui._dates.free_day_predicate", lambda: _never_free)
|
|
monkeypatch.setattr("sickdays.gui._panel.sync_quietly", _no_sync)
|
|
|
|
|
|
@pytest.fixture
|
|
def state_dir(tmp_path: Path) -> Path:
|
|
"""The redirected state directory, for tests that assert on files."""
|
|
return tmp_path / "state"
|
|
|
|
|
|
@pytest.fixture
|
|
def tk_root() -> Iterator[tk.Tk]:
|
|
"""A real, never-mapped Tk root; skips when there is no X display.
|
|
|
|
Real Tk rather than a fake: option names and Checkbutton/variable wiring
|
|
are Tk's own behaviour. CI runs the suite under ``xvfb-run``.
|
|
"""
|
|
import tkinter as tk
|
|
|
|
try:
|
|
root = tk.Tk(className="sickdays-test")
|
|
except tk.TclError as exc:
|
|
pytest.skip(f"no X display ({exc}); run the suite under xvfb-run")
|
|
root.withdraw()
|
|
yield root
|
|
root.destroy()
|
|
|
|
|
|
@pytest.fixture
|
|
def synced(monkeypatch: pytest.MonkeyPatch) -> list[Paths | None]:
|
|
"""Record every background sync the panel starts."""
|
|
calls: list[Paths | None] = []
|
|
|
|
def record(*, paths: Paths | None = None) -> bool:
|
|
calls.append(paths)
|
|
return True
|
|
|
|
monkeypatch.setattr("sickdays.gui._panel.sync_quietly", record)
|
|
return calls
|