2026-03-25 21:15:40 +01:00
|
|
|
"""Safety conftest: prevent tests from touching real Steam/config files.
|
|
|
|
|
|
|
|
|
|
Redirects all filesystem paths used by the steam_backlog_enforcer package
|
|
|
|
|
to temporary directories. This stops tests from accidentally:
|
|
|
|
|
- Deleting real game files via uninstall_other_games / uninstall_game
|
|
|
|
|
- Overwriting ~/.config/steam_backlog_enforcer/state.json (losing the
|
|
|
|
|
user's current assignment)
|
|
|
|
|
- Reading real appmanifest files from ~/.local/share/Steam/steamapps
|
|
|
|
|
- Modifying /etc/hosts via the store blocker
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
- Corrupting the HLTB cache on disk
|
|
|
|
|
- Launching real Steam or calling real subprocess commands
|
2026-03-25 21:15:40 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
from unittest.mock import MagicMock, patch
|
2026-03-25 21:15:40 +01:00
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from collections.abc import Iterator
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _isolate_filesystem(tmp_path: Path) -> Iterator[None]:
|
|
|
|
|
"""Redirect all real filesystem paths to a temporary directory.
|
|
|
|
|
|
|
|
|
|
Individual tests that also patch these paths will simply override
|
|
|
|
|
this fixture's patches for the duration of their own ``with`` block.
|
|
|
|
|
"""
|
|
|
|
|
fake_config = tmp_path / "config"
|
|
|
|
|
fake_config.mkdir()
|
|
|
|
|
fake_steamapps = tmp_path / "steamapps"
|
|
|
|
|
fake_steamapps.mkdir()
|
|
|
|
|
fake_hosts = tmp_path / "hosts"
|
|
|
|
|
|
|
|
|
|
with (
|
|
|
|
|
# Config / state / snapshot paths (used by State.save, Config.save, etc.)
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.config.CONFIG_DIR",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_config,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.config.CONFIG_FILE",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_config / "config.json",
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.config.STATE_FILE",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_config / "state.json",
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.config.SNAPSHOT_FILE",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_config / "snapshot.json",
|
|
|
|
|
),
|
|
|
|
|
# Steam game manifests / install dirs
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.game_install.STEAMAPPS_PATH",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_steamapps,
|
|
|
|
|
),
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
# HLTB cache file (computed at import time from CONFIG_DIR, so
|
|
|
|
|
# patching CONFIG_DIR alone does not redirect it)
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer._hltb_types.HLTB_CACHE_FILE",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
fake_config / "hltb_cache.json",
|
|
|
|
|
),
|
2026-03-25 21:15:40 +01:00
|
|
|
# /etc/hosts (store blocker)
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.store_blocker.HOSTS_FILE",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_hosts,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.config.HOSTS_FILE",
|
2026-03-25 21:15:40 +01:00
|
|
|
fake_hosts,
|
|
|
|
|
),
|
2026-05-17 20:44:05 +02:00
|
|
|
# Whitelist exception files (_whitelist module-level constants)
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer._whitelist.PENDING_EXCEPTIONS_FILE",
|
2026-05-17 20:44:05 +02:00
|
|
|
fake_config / "pending_exceptions.json",
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer._whitelist.APPROVED_EXCEPTIONS_FILE",
|
2026-05-17 20:44:05 +02:00
|
|
|
fake_config / "approved_exceptions.json",
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer._whitelist.EXCEPTION_AUDIT_LOG",
|
2026-05-17 20:44:05 +02:00
|
|
|
fake_config / "exception_audit.log",
|
|
|
|
|
),
|
|
|
|
|
# _enforce_loop imports CONFIG_FILE directly; patch the local binding so
|
|
|
|
|
# lock_enforcement_files() uses the tmp path instead of the real one.
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer._enforce_loop.CONFIG_FILE",
|
2026-05-17 20:44:05 +02:00
|
|
|
fake_config / "config.json",
|
|
|
|
|
),
|
2026-03-25 21:15:40 +01:00
|
|
|
):
|
|
|
|
|
yield
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _block_real_subprocesses() -> Iterator[None]:
|
|
|
|
|
"""Block subprocess calls that could launch real Steam or modify system.
|
|
|
|
|
|
|
|
|
|
Individual tests that need to test subprocess behaviour should
|
|
|
|
|
patch the specific module's ``subprocess.run`` / ``subprocess.Popen``
|
|
|
|
|
themselves — their local patch will override this one.
|
|
|
|
|
"""
|
|
|
|
|
noop_run = MagicMock(return_value=MagicMock(returncode=1))
|
|
|
|
|
noop_popen = MagicMock()
|
|
|
|
|
|
|
|
|
|
with (
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.game_install.subprocess.run",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
noop_run,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.game_install.subprocess.Popen",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
noop_popen,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.enforcer.subprocess.run",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
noop_run,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.store_blocker.subprocess.run",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
noop_run,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.library_hider.subprocess.run",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
noop_run,
|
|
|
|
|
),
|
|
|
|
|
patch(
|
2026-05-28 07:21:29 +02:00
|
|
|
"steam_backlog_enforcer.library_hider.subprocess.Popen",
|
chore: optimize pre-commit, remove tracked binaries, fix lint issues
- Move slow hooks (mypy, pylint, bandit, pytest, prettier) to pre-push stage
- Remove redundant autoflake (ruff covers F401/F841)
- Fix shellcheck OOM by batching files with xargs -n 40
- Remove tracked .o, .wav, .pyc binaries from git
- Move pomodoro wav files to ../testsAndMisc_binaries/ with symlinks
- Add *.o, *.so, *.a to .gitignore
- Refactor hltb._pick_best_hltb_entry to fix C901/PLR0911/SIM102
- Fix SC2034 warnings in gif_to_square.sh and upgrade.sh
- Add disk_cleanup_check.sh script
- Various test and code improvements across screen_locker,
steam_backlog_enforcer, word_frequency, moviepy_showcase
2026-04-10 18:44:51 +02:00
|
|
|
noop_popen,
|
|
|
|
|
),
|
|
|
|
|
):
|
|
|
|
|
yield
|
2026-05-14 21:52:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _no_real_sleep() -> Iterator[None]:
|
|
|
|
|
"""No-op every ``time.sleep`` used by the package.
|
|
|
|
|
|
|
|
|
|
Several modules call ``time.sleep`` for Steam-launch / install-retry /
|
|
|
|
|
rate-limit pacing. Individual tests that need to observe sleep
|
|
|
|
|
behaviour can override these patches inside their own ``with`` block.
|
|
|
|
|
"""
|
|
|
|
|
noop = MagicMock()
|
|
|
|
|
with (
|
2026-05-28 07:21:29 +02:00
|
|
|
patch("steam_backlog_enforcer.game_install.time.sleep", noop),
|
|
|
|
|
patch("steam_backlog_enforcer.library_hider.time.sleep", noop),
|
|
|
|
|
patch("steam_backlog_enforcer.steam_api.time.sleep", noop),
|
|
|
|
|
patch("steam_backlog_enforcer._enforce_loop.time.sleep", noop),
|
2026-05-14 21:52:52 +02:00
|
|
|
):
|
|
|
|
|
yield
|