2026-03-27 15:54:01 +01:00
|
|
|
"""Tests for UI transitions, timer logic, and sick day screens."""
|
2026-03-16 22:46:48 +01:00
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
|
|
from python_pkg.screen_locker.tests.conftest import create_locker
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestUITransitions:
|
|
|
|
|
"""Tests for UI state transitions."""
|
|
|
|
|
|
|
|
|
|
def test_clear_container(
|
|
|
|
|
self,
|
|
|
|
|
mock_tk: MagicMock,
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
mock_sys_exit: MagicMock,
|
2026-03-16 22:46:48 +01:00
|
|
|
tmp_path: Path,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test clear_container destroys all child widgets."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
|
|
|
|
|
# Set up mock children
|
|
|
|
|
mock_child1 = MagicMock()
|
|
|
|
|
mock_child2 = MagicMock()
|
2026-03-18 22:20:05 +01:00
|
|
|
locker.container.winfo_children.return_value = [
|
2026-03-16 22:46:48 +01:00
|
|
|
mock_child1,
|
|
|
|
|
mock_child2,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
locker.clear_container()
|
|
|
|
|
|
|
|
|
|
mock_child1.destroy.assert_called_once()
|
|
|
|
|
mock_child2.destroy.assert_called_once()
|
|
|
|
|
|
|
|
|
|
def test_unlock_screen_saves_and_schedules_close(
|
|
|
|
|
self,
|
|
|
|
|
mock_tk: MagicMock,
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
mock_sys_exit: MagicMock,
|
2026-03-16 22:46:48 +01:00
|
|
|
tmp_path: Path,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test unlock_screen saves log and schedules close."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
locker.log_file = tmp_path / "workout_log.json"
|
2026-03-27 15:54:01 +01:00
|
|
|
locker.workout_data = {"type": "phone_verified"}
|
2026-03-16 22:46:48 +01:00
|
|
|
|
|
|
|
|
locker.unlock_screen()
|
|
|
|
|
|
|
|
|
|
# Check that after() was called to schedule close
|
2026-03-18 22:20:05 +01:00
|
|
|
locker.root.after.assert_called()
|
2026-03-16 22:46:48 +01:00
|
|
|
|
|
|
|
|
def test_lockout_starts_countdown(
|
|
|
|
|
self,
|
|
|
|
|
mock_tk: MagicMock,
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
mock_sys_exit: MagicMock,
|
2026-03-16 22:46:48 +01:00
|
|
|
tmp_path: Path,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test lockout initializes countdown timer."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
|
|
|
|
|
locker.lockout()
|
|
|
|
|
|
|
|
|
|
# lockout() sets remaining_time to lockout_time (10 in demo mode)
|
|
|
|
|
# then calls update_lockout_countdown() which decrements it by 1
|
|
|
|
|
assert locker.remaining_time == 9 # 10 - 1 after first update
|
|
|
|
|
|
|
|
|
|
def test_close_destroys_root_and_exits(
|
|
|
|
|
self,
|
|
|
|
|
mock_tk: MagicMock,
|
|
|
|
|
mock_sys_exit: MagicMock,
|
|
|
|
|
tmp_path: Path,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test close destroys root window and exits."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
|
|
|
|
|
locker.close()
|
|
|
|
|
|
2026-03-18 22:20:05 +01:00
|
|
|
locker.root.destroy.assert_called_once()
|
2026-03-16 22:46:48 +01:00
|
|
|
mock_sys_exit.assert_called_with(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTimerLogic:
|
|
|
|
|
"""Tests for timer countdown logic."""
|
|
|
|
|
|
|
|
|
|
def test_update_lockout_countdown_decrements(
|
|
|
|
|
self,
|
|
|
|
|
mock_tk: MagicMock,
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
mock_sys_exit: MagicMock,
|
2026-03-16 22:46:48 +01:00
|
|
|
tmp_path: Path,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test countdown decrements remaining time."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
locker.remaining_time = 5
|
|
|
|
|
locker.countdown_label = MagicMock()
|
|
|
|
|
|
|
|
|
|
locker.update_lockout_countdown()
|
|
|
|
|
|
|
|
|
|
assert locker.remaining_time == 4
|
2026-03-18 22:20:05 +01:00
|
|
|
locker.root.after.assert_called_with(1000, locker.update_lockout_countdown)
|
2026-03-16 22:46:48 +01:00
|
|
|
|
|
|
|
|
def test_update_lockout_countdown_at_zero(
|
|
|
|
|
self,
|
|
|
|
|
mock_tk: MagicMock,
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
mock_sys_exit: MagicMock,
|
2026-03-16 22:46:48 +01:00
|
|
|
tmp_path: Path,
|
|
|
|
|
) -> None:
|
2026-03-27 15:54:01 +01:00
|
|
|
"""Test countdown at zero restarts phone check."""
|
2026-03-16 22:46:48 +01:00
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
locker.remaining_time = 0
|
|
|
|
|
locker.countdown_label = MagicMock()
|
2026-03-27 15:54:01 +01:00
|
|
|
object.__setattr__(locker, "_start_phone_check", MagicMock())
|
2026-03-16 22:46:48 +01:00
|
|
|
|
|
|
|
|
locker.update_lockout_countdown()
|
|
|
|
|
|
2026-03-27 15:54:01 +01:00
|
|
|
locker._start_phone_check.assert_called_once()
|
2026-03-21 17:51:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAskIfSick:
|
|
|
|
|
"""Tests for ask_if_sick method."""
|
|
|
|
|
|
|
|
|
|
def test_ask_if_sick_displays_dialog(
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
2026-03-21 17:51:36 +01:00
|
|
|
) -> None:
|
|
|
|
|
"""Test ask_if_sick shows sick day question."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
object.__setattr__(locker, "clear_container", MagicMock())
|
|
|
|
|
locker.ask_if_sick()
|
|
|
|
|
locker.clear_container.assert_called_once()
|
|
|
|
|
mock_tk.Label.assert_called()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSickQuestionButtons:
|
|
|
|
|
"""Tests for _sick_question_buttons method."""
|
|
|
|
|
|
|
|
|
|
def test_creates_buttons(
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
2026-03-21 17:51:36 +01:00
|
|
|
) -> None:
|
|
|
|
|
"""Test _sick_question_buttons creates yes/no buttons."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
locker._sick_question_buttons()
|
|
|
|
|
mock_tk.Button.assert_called()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetSickDayStatus:
|
|
|
|
|
"""Tests for _get_sick_day_status method."""
|
|
|
|
|
|
|
|
|
|
def test_already_adjusted_today(
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
2026-03-21 17:51:36 +01:00
|
|
|
) -> None:
|
|
|
|
|
"""Test status when sick mode already used today."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
object.__setattr__(
|
|
|
|
|
locker, "_sick_mode_used_today", MagicMock(return_value=True)
|
|
|
|
|
)
|
|
|
|
|
text, color = locker._get_sick_day_status()
|
|
|
|
|
assert "already adjusted" in text
|
|
|
|
|
assert color == "#ffaa00"
|
|
|
|
|
|
|
|
|
|
def test_adjustment_success(
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
2026-03-21 17:51:36 +01:00
|
|
|
) -> None:
|
|
|
|
|
"""Test status when shutdown time adjusted successfully."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
object.__setattr__(
|
|
|
|
|
locker, "_sick_mode_used_today", MagicMock(return_value=False)
|
|
|
|
|
)
|
|
|
|
|
object.__setattr__(
|
|
|
|
|
locker, "_adjust_shutdown_time_earlier", MagicMock(return_value=True)
|
|
|
|
|
)
|
|
|
|
|
text, color = locker._get_sick_day_status()
|
|
|
|
|
assert "earlier" in text
|
|
|
|
|
assert color == "#00aa00"
|
|
|
|
|
|
|
|
|
|
def test_adjustment_failure(
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
2026-03-21 17:51:36 +01:00
|
|
|
) -> None:
|
|
|
|
|
"""Test status when adjustment fails."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
object.__setattr__(
|
|
|
|
|
locker, "_sick_mode_used_today", MagicMock(return_value=False)
|
|
|
|
|
)
|
|
|
|
|
object.__setattr__(
|
|
|
|
|
locker, "_adjust_shutdown_time_earlier", MagicMock(return_value=False)
|
|
|
|
|
)
|
|
|
|
|
text, color = locker._get_sick_day_status()
|
|
|
|
|
assert "Could not adjust" in text
|
|
|
|
|
assert color == "#ff4444"
|
2026-03-27 15:54:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestShowRetryAndSick:
|
|
|
|
|
"""Tests for _show_retry_and_sick method."""
|
|
|
|
|
|
|
|
|
|
def test_displays_buttons(
|
|
|
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test _show_retry_and_sick shows retry and sick buttons."""
|
|
|
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
|
object.__setattr__(locker, "clear_container", MagicMock())
|
|
|
|
|
|
|
|
|
|
locker._show_retry_and_sick("Test message")
|
|
|
|
|
|
|
|
|
|
locker.clear_container.assert_called_once()
|
|
|
|
|
mock_tk.Label.assert_called()
|
|
|
|
|
mock_tk.Button.assert_called()
|