mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 18:33:57 +01:00
Six new modules, all composed or re-exported so no caller changes:
_shutdown.py (384) -> _shutdown_sick_state.py SickDayStateMixin
_wake_alarm.py WakeAlarmMixin
_phone_verification.py (380)-> _adb_transport.py AdbTransportMixin
_http_workout_fetch.py HttpWorkoutFetchMixin
_status_data.py (370) -> _status_types.py the 7 dataclasses
_status_projection.py shutdown projection
+ format_summary_line
Moving a name means moving where it is *read*, so 30-odd mock patch targets
move with it. Most importantly conftest.py's autouse _block_real_network
fixture: ruff correctly dropped the now-unused `socket` import from
_phone_verification, which silently removed the guard's target and would have
let subnet probes reach the real network. It now blocks socket in both modules
that actually own the probes, and both targets are asserted to exist.
976 tests pass at 100% branch coverage; pylint 8.70 -> 8.71; `screen_lock
--status` renders the real week unchanged. File-length gate: 41 -> 35.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EveB813BQ8abAP68VSqZ5Y
84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
"""Tests for shutdown schedule adjustment coverage gaps (part 2)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
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, timezone
|
|
|
|
today = datetime.now(tz=timezone.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
|