mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 15:08:13 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
145 lines
5.3 KiB
Python
145 lines
5.3 KiB
Python
"""Constructors for a ``ScreenLocker`` under test.
|
|
|
|
Split out of ``conftest`` (and re-exported from it) so neither file
|
|
exceeds the repo's 400-line limit. Every early-exit path a real start-up
|
|
would take is patched here, so a test gets a locker that is built but has
|
|
not run any of its flows.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from screen_locker.screen_lock import ScreenLocker
|
|
|
|
if TYPE_CHECKING:
|
|
from typing import Literal
|
|
|
|
|
|
def _make_locker(
|
|
log_file: Path,
|
|
*,
|
|
n_filled: int = 0,
|
|
bonus_applied: bool = False,
|
|
cfg: tuple | None = (1320, 1320, 300),
|
|
):
|
|
"""Build a minimal locker-like namespace for _status.run_status()."""
|
|
locker = SimpleNamespace(
|
|
log_file=log_file,
|
|
workout_data={},
|
|
)
|
|
locker._scan_and_fill_week_runnerup = MagicMock(return_value=n_filled)
|
|
locker._credit_ingested_workout = MagicMock()
|
|
locker._adjust_shutdown_time_by = MagicMock(return_value=bonus_applied)
|
|
locker._read_shutdown_config = MagicMock(return_value=cfg)
|
|
return locker
|
|
|
|
|
|
def create_locker(
|
|
_mock_tk: MagicMock,
|
|
tmp_path: Path,
|
|
*,
|
|
demo_mode: bool = True,
|
|
has_logged: bool = False,
|
|
verify_only: bool = False,
|
|
is_sick_day_log: bool = False,
|
|
) -> ScreenLocker:
|
|
"""Create a ScreenLocker instance with early bird paths disabled."""
|
|
with (
|
|
patch.object(Path, "resolve", return_value=tmp_path / "screen_locker"),
|
|
patch.object(ScreenLocker, "has_logged_today", return_value=has_logged),
|
|
patch.object(
|
|
ScreenLocker,
|
|
"_is_sick_day_today",
|
|
return_value=is_sick_day_log,
|
|
),
|
|
patch.object(ScreenLocker, "_is_early_bird_pending", return_value=False),
|
|
patch.object(ScreenLocker, "_is_early_bird_time", return_value=False),
|
|
patch.object(
|
|
ScreenLocker,
|
|
"_try_auto_upgrade_early_bird",
|
|
return_value=False,
|
|
),
|
|
patch.object(ScreenLocker, "_start_phone_check"),
|
|
patch.object(ScreenLocker, "_start_relaxed_day_flow"),
|
|
patch.object(ScreenLocker, "_start_verify_workout_check"),
|
|
patch.object(ScreenLocker, "_scan_and_fill_week_runnerup", return_value=0),
|
|
):
|
|
return ScreenLocker(
|
|
demo_mode=demo_mode,
|
|
verify_only=verify_only,
|
|
)
|
|
|
|
|
|
def create_locker_relaxed_day(
|
|
_mock_tk: MagicMock,
|
|
tmp_path: Path,
|
|
*,
|
|
demo_mode: bool = True,
|
|
has_logged: bool = False,
|
|
) -> ScreenLocker:
|
|
"""Create a ScreenLocker in relaxed-day mode (Tue/Wed/Thu).
|
|
|
|
``is_relaxed_day`` returns True so ``_relaxed_day_mode`` is set and
|
|
``_start_relaxed_day_flow`` is called instead of ``_start_phone_check``.
|
|
The autouse ``_mock_weekly_logic`` fixture is overridden here.
|
|
"""
|
|
with (
|
|
patch.object(Path, "resolve", return_value=tmp_path / "screen_locker"),
|
|
patch.object(ScreenLocker, "has_logged_today", return_value=has_logged),
|
|
patch.object(ScreenLocker, "_is_sick_day_today", return_value=False),
|
|
patch.object(ScreenLocker, "_is_early_bird_pending", return_value=False),
|
|
patch.object(ScreenLocker, "_is_early_bird_time", return_value=False),
|
|
patch.object(ScreenLocker, "_try_auto_upgrade_early_bird", return_value=False),
|
|
patch("screen_locker._startup_checks.is_relaxed_day", return_value=True),
|
|
patch(
|
|
"screen_locker._startup_checks.has_weekly_minimum",
|
|
return_value=False,
|
|
),
|
|
patch.object(ScreenLocker, "_start_phone_check"),
|
|
patch.object(ScreenLocker, "_start_relaxed_day_flow"),
|
|
patch.object(ScreenLocker, "_start_verify_workout_check"),
|
|
):
|
|
return ScreenLocker(demo_mode=demo_mode)
|
|
|
|
|
|
def create_locker_early_bird(
|
|
_mock_tk: MagicMock,
|
|
tmp_path: Path,
|
|
*,
|
|
state: Literal["none", "log_active", "log_expired"] = "none",
|
|
has_logged: bool = False,
|
|
demo_mode: bool = True,
|
|
) -> ScreenLocker:
|
|
"""Create a ScreenLocker configured for early bird path testing.
|
|
|
|
Args:
|
|
state: One of:
|
|
- "none": outside early bird window, no early bird log.
|
|
- "log_active": early bird log exists, still in window.
|
|
- "log_expired": early bird log exists, past 8:30 AM.
|
|
has_logged: Return value for has_logged_today mock.
|
|
demo_mode: Passed to ScreenLocker constructor.
|
|
"""
|
|
is_early_bird_log = state in ("log_active", "log_expired")
|
|
is_early_bird_time = state == "log_active"
|
|
with (
|
|
patch.object(Path, "resolve", return_value=tmp_path / "screen_locker"),
|
|
patch.object(ScreenLocker, "has_logged_today", return_value=has_logged),
|
|
patch.object(ScreenLocker, "_is_sick_day_today", return_value=False),
|
|
patch.object(
|
|
ScreenLocker, "_is_early_bird_pending", return_value=is_early_bird_log
|
|
),
|
|
patch.object(
|
|
ScreenLocker, "_is_early_bird_time", return_value=is_early_bird_time
|
|
),
|
|
patch.object(ScreenLocker, "_try_auto_upgrade_early_bird", return_value=False),
|
|
patch.object(ScreenLocker, "_start_phone_check"),
|
|
patch.object(ScreenLocker, "_start_relaxed_day_flow"),
|
|
patch.object(ScreenLocker, "_start_verify_workout_check"),
|
|
):
|
|
return ScreenLocker(demo_mode=demo_mode)
|