mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 20:33:56 +01:00
Every locker screen, the status window and the credit toast now show glyphs (screen_locker/_glyphs.py) and numbers, coloured by state. Sentences that carried a reason (verifier message, sync diagnosis, sick refusal, form rejection) go to the log at warning instead. New pre-commit hook text-free runs scripts/verify_text_free.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
4.4 KiB
Python
137 lines
4.4 KiB
Python
"""Tests targeting remaining screen_lock.py coverage gaps."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from screen_locker import _glyphs as g
|
|
from screen_locker.tests._unlock_helpers import setup_unlock
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.mark.usefixtures("pre_ladder")
|
|
class TestUnlockScreenExtras:
|
|
"""unlock_screen's extra-workout bonus and streak display."""
|
|
|
|
def test_extra_workout_bonus_shown(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""An additional same-day verified workout earns the +1h bonus."""
|
|
locker = setup_unlock(
|
|
mock_tk, tmp_path, weekly_count=5, seed_today_type="manual_workout"
|
|
)
|
|
|
|
with (
|
|
patch(
|
|
"screen_locker._workout_credit.count_weekly_workouts",
|
|
return_value=5,
|
|
),
|
|
patch(
|
|
"screen_locker._unlock_view.current_streak",
|
|
return_value=0,
|
|
),
|
|
patch("screen_locker._log_mixin.compute_entry_hmac", return_value=None),
|
|
):
|
|
locker.unlock_screen()
|
|
|
|
locker._adjust_shutdown_time_by.assert_called_once_with(60, at=None)
|
|
|
|
def test_extra_bonus_delta_displayed(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""extra_bonus_delta > 0 → _text shows the barbell and the +1h gift."""
|
|
locker = setup_unlock(mock_tk, tmp_path, seed_today_type="manual_workout")
|
|
|
|
# Simulate before=22:00, after=23:00 → delta=60
|
|
old_cfg = (1320, 1320, 300)
|
|
new_cfg = (1380, 1380, 300)
|
|
locker._read_shutdown_config.side_effect = [old_cfg, new_cfg, new_cfg]
|
|
|
|
text_calls: list[str] = []
|
|
|
|
def _capture_text(msg: str, **kw: object) -> None:
|
|
text_calls.append(msg)
|
|
|
|
object.__setattr__(locker, "_text", _capture_text)
|
|
|
|
with (
|
|
patch(
|
|
"screen_locker._workout_credit.count_weekly_workouts",
|
|
return_value=5,
|
|
),
|
|
patch(
|
|
"screen_locker._unlock_view.current_streak",
|
|
return_value=0,
|
|
),
|
|
patch("screen_locker._log_mixin.compute_entry_hmac", return_value=None),
|
|
):
|
|
locker.unlock_screen()
|
|
|
|
assert f"{g.LIFT} {g.GIFT}1h" in text_calls
|
|
|
|
def test_no_extra_bonus_when_adjust_fails(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Additional verified workout but the +1h adjust fails → delta stays 0."""
|
|
locker = setup_unlock(
|
|
mock_tk,
|
|
tmp_path,
|
|
seed_today_type="manual_workout",
|
|
adjust_ok=False,
|
|
)
|
|
|
|
text_calls: list[str] = []
|
|
object.__setattr__(locker, "_text", lambda msg, **kw: text_calls.append(msg))
|
|
|
|
with (
|
|
patch(
|
|
"screen_locker._workout_credit.count_weekly_workouts",
|
|
return_value=5,
|
|
),
|
|
patch("screen_locker._unlock_view.current_streak", return_value=0),
|
|
patch("screen_locker._log_mixin.compute_entry_hmac", return_value=None),
|
|
):
|
|
locker.unlock_screen()
|
|
|
|
assert not any("Extra workout" in c for c in text_calls)
|
|
|
|
def test_no_extra_bonus_when_new_config_unreadable(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Re-reading the shutdown config fails after the +1h → delta stays 0."""
|
|
locker = setup_unlock(mock_tk, tmp_path, seed_today_type="manual_workout")
|
|
# old_cfg readable, new_cfg unreadable → no delta can be computed.
|
|
locker._read_shutdown_config.side_effect = [(1320, 1320, 300), None, None]
|
|
|
|
text_calls: list[str] = []
|
|
object.__setattr__(locker, "_text", lambda msg, **kw: text_calls.append(msg))
|
|
|
|
with (
|
|
patch(
|
|
"screen_locker._workout_credit.count_weekly_workouts",
|
|
return_value=5,
|
|
),
|
|
patch("screen_locker._unlock_view.current_streak", return_value=0),
|
|
patch("screen_locker._log_mixin.compute_entry_hmac", return_value=None),
|
|
):
|
|
locker.unlock_screen()
|
|
|
|
assert not any("Extra workout" in c for c in text_calls)
|