mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 19:07:16 +01:00
`requires-python` and the CI pin already said 3.14, but ruff, mypy and pylint were still grading against 3.10 -- three tools judging an interpreter nothing runs any more, and ruff withholding the pyupgrade fixes that only become safe at the newer target. `pin_ci_python.py` rewrites exactly these three knobs. What the stale target was hiding: 118 sites on `datetime.timezone.utc` instead of `datetime.UTC` (UP017), two classes still written with `Generic[...]` rather than PEP 695 syntax, and ruff's stable formatter applying PEP 758 -- `except (A, B):` becomes `except A, B:`. That last one makes the source 3.14-only at the syntax level, which is what `requires-python = ">=3.14"` already promised; kuhy chose it deliberately over holding ruff a release back (2026-08-29). The PEP 695 fix needed a hand: ruff rewrote `class WidgetGroup(Generic[_W])` to `class WidgetGroup[W: tk.Misc]` but left the body annotated with the module-level `_W`, a *different* type variable -- mypy caught it as "a function returning TypeVar should receive at least one argument containing the same TypeVar". Renamed the body to the new parameter, gave `FrameGroup.__init__` the concrete `list[tk.Frame]` it always wrapped, and deleted the two now-dead module-level TypeVars. ruff, ruff-format, mypy --strict and both pylint passes clean at the new target. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfnJmxxsZ534AKk16rC2Gr
85 lines
2.7 KiB
Python
85 lines
2.7 KiB
Python
"""Tests for shutdown schedule adjustment coverage gaps (part 2)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC
|
|
import json
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from screen_locker.tests.conftest import create_locker
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
class TestSickModeUsedToday:
|
|
"""Tests for _sick_mode_used_today method."""
|
|
|
|
def test_returns_false_when_no_file(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Test returns False when state file doesn't exist."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
mock_file = MagicMock()
|
|
mock_file.exists.return_value = False
|
|
with patch(
|
|
"screen_locker._shutdown_sick_state.SICK_DAY_STATE_FILE",
|
|
mock_file,
|
|
):
|
|
assert locker._sick_mode_used_today() is False
|
|
|
|
def test_returns_true_when_used_today(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Test returns True when state matches today."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
state_file = tmp_path / "state.json"
|
|
with patch(
|
|
"screen_locker._shutdown_sick_state.SICK_DAY_STATE_FILE",
|
|
state_file,
|
|
):
|
|
from datetime import datetime
|
|
|
|
today = datetime.now(tz=UTC).strftime("%Y-%m-%d")
|
|
state_file.write_text(json.dumps({"date": today}))
|
|
assert locker._sick_mode_used_today() is True
|
|
|
|
def test_returns_false_when_different_date(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Test returns False when state is from different date."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
state_file = tmp_path / "state.json"
|
|
with patch(
|
|
"screen_locker._shutdown_sick_state.SICK_DAY_STATE_FILE",
|
|
state_file,
|
|
):
|
|
state_file.write_text(json.dumps({"date": "2020-01-01"}))
|
|
assert locker._sick_mode_used_today() is False
|
|
|
|
def test_returns_false_on_json_error(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Test returns False on JSONDecodeError."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
state_file = tmp_path / "state.json"
|
|
with patch(
|
|
"screen_locker._shutdown_sick_state.SICK_DAY_STATE_FILE",
|
|
state_file,
|
|
):
|
|
state_file.write_text("not json{{{")
|
|
assert locker._sick_mode_used_today() is False
|