screen-locker/screen_locker/tests/test_wake_skip.py
Krzysztof kuhy Rudnicki 74a8bd7529 Add auto-fill RunnerUp scan, carrot bonuses, and --status interface
- Refactor RunnerUp verification: extract RunnerUpDbMixin (_runnerup_db.py),
  split _scan_and_fill_week_runnerup into a helper _try_fill_runnerup_for_date
  to keep cyclomatic complexity ≤10
- Generalise TCX lookup to any date in the ISO week (was today-only); all gap
  days Mon→today auto-filled on every startup and 08:30 timer firing
- Add _adjust_shutdown_time_by(): +1h per extra workout beyond the 4-workout
  minimum, capped at midnight (hour=24)
- Add _shutdown_base.py: daily reset of shutdown config to a stored base so
  the bonus doesn't silently accumulate across days
- Add _extra_benefits.py: streak tracking, skip credits (earn (n-4) credits
  for 5+ workout weeks), early-bird extension to 09:00 for eligible weeks
- Add --status mode (_status.py): non-locking CLI view showing per-day
  breakdown (✓/✗), RunnerUp auto-scan, bonus status, shutdown time, streak,
  skip credits, and early-bird status
- Hook carrot into _check_non_verify_exits: bonus applied whenever auto-fill
  pushes weekly count above the minimum
- Pass all pre-commit hooks (ruff, mypy, pylint, bandit, shellcheck,
  codespell, max-file-length); 508 tests at 100% branch coverage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017auyHmf2ZwQcDAwXaSo7KX
2026-06-28 08:08:35 +02:00

84 lines
2.5 KiB
Python

"""Tests for wake alarm skip integration in screen_lock.py."""
from __future__ import annotations
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 TestWakeSkipIntegration:
"""Tests for workout skip via wake alarm in screen locker init."""
def test_exits_when_wake_skip_active(
self,
mock_tk: MagicMock,
mock_sys_exit: MagicMock,
tmp_path: Path,
) -> None:
"""Screen locker exits if wake alarm granted workout skip today."""
with patch(
"screen_locker._auto_upgrade.has_workout_skip_today",
return_value=True,
):
create_locker(mock_tk, tmp_path, has_logged=False)
mock_sys_exit.assert_called_once_with(0)
def test_does_not_exit_when_no_wake_skip(
self,
mock_tk: MagicMock,
mock_sys_exit: MagicMock,
tmp_path: Path,
) -> None:
"""Screen locker proceeds normally if no wake skip active."""
with patch(
"screen_locker._auto_upgrade.has_workout_skip_today",
return_value=False,
):
locker = create_locker(mock_tk, tmp_path, has_logged=False)
mock_sys_exit.assert_not_called()
assert locker is not None
def test_logged_today_takes_precedence(
self,
mock_tk: MagicMock,
mock_sys_exit: MagicMock,
tmp_path: Path,
) -> None:
"""has_logged_today exits before wake skip is even checked."""
with patch(
"screen_locker._auto_upgrade.has_workout_skip_today",
return_value=True,
):
create_locker(mock_tk, tmp_path, has_logged=True)
# Exits because has_logged_today, not because of wake skip
mock_sys_exit.assert_called_once_with(0)
def test_verify_only_mode_ignores_wake_skip(
self,
mock_tk: MagicMock,
mock_sys_exit: MagicMock,
tmp_path: Path,
) -> None:
"""verify_only mode checks sick day log, not wake skip."""
with patch(
"screen_locker._auto_upgrade.has_workout_skip_today",
return_value=True,
):
create_locker(
mock_tk,
tmp_path,
verify_only=True,
is_sick_day_log=True,
)
# In verify_only mode, exits don't happen from wake skip path
mock_sys_exit.assert_not_called()