steam-backlog-enforcer/steam_backlog_enforcer/tests/test_steam_restart.py
Krzysztof kuhy Rudnicki d2565416aa Pylint gate covers tests, no suppressions
Tests are now linted by the 10.00 gate (ignore-paths dropped), with no
per-test disables. CtlServer/DaemonControl members the tests drive are
public (renamed, behaviour unchanged); SteamAPIClient._get takes its
params explicitly, as every caller already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:17:07 +01:00

86 lines
2.6 KiB
Python

"""Tests for shutting Steam down and relaunching it with the debug port.
Split to keep every test file under the 250-line cap.
"""
from __future__ import annotations
from unittest.mock import MagicMock, patch
from steam_backlog_enforcer._steam_launch import (
_launch_steam_with_debug,
_shutdown_steam,
)
class TestShutdownSteam:
"""Tests for _shutdown_steam."""
def test_exits_immediately(self) -> None:
"""A Steam that is already gone needs no waiting."""
mock_result = MagicMock(returncode=1) # Not running
with (
patch(
"steam_backlog_enforcer._steam_launch._run_as_user",
),
patch(
"steam_backlog_enforcer._steam_launch.subprocess.run",
return_value=mock_result,
),
):
_shutdown_steam()
def test_waits_for_exit(self) -> None:
"""Shutdown polls until Steam has exited."""
results = [MagicMock(returncode=0), MagicMock(returncode=1)]
with (
patch(
"steam_backlog_enforcer._steam_launch._run_as_user",
),
patch(
"steam_backlog_enforcer._steam_launch.subprocess.run",
side_effect=results,
),
patch(
"steam_backlog_enforcer._steam_launch.time.sleep",
),
):
_shutdown_steam()
def test_file_not_found(self) -> None:
"""A missing steam binary does not raise."""
with patch(
"steam_backlog_enforcer._steam_launch._run_as_user",
side_effect=FileNotFoundError,
):
_shutdown_steam() # Should not raise
def test_timeout(self) -> None:
"""A Steam that never exits ends the wait without raising."""
mock_result = MagicMock(returncode=0) # Still running
with (
patch(
"steam_backlog_enforcer._steam_launch._run_as_user",
),
patch(
"steam_backlog_enforcer._steam_launch.subprocess.run",
return_value=mock_result,
),
patch(
"steam_backlog_enforcer._steam_launch.time.sleep",
),
):
_shutdown_steam() # Should complete loop without raising
class TestLaunchSteamWithDebug:
"""Tests for _launch_steam_with_debug."""
def test_launches(self) -> None:
"""Launching runs Steam once as the desktop user."""
with patch(
"steam_backlog_enforcer._steam_launch._run_as_user",
) as mock_run:
_launch_steam_with_debug()
mock_run.assert_called_once()