steam-backlog-enforcer/steam_installer/tests/test_depotdl.py
Krzysztof kuhy Rudnicki a76e726e36 Merge steam-game-installer into the repo
The installer ships as the steam_installer package beside
steam_backlog_enforcer, with its tests, docs and Proton lock. The
enforcer's fast install now starts the installer from this checkout.

Both appinfo.vdf readers share one key-value decoder
(steam_installer.appinfo_kv), and the duplicated test fixtures and
helpers are folded into conftest and _cli_helpers so the whole-tree
duplicate-code check is clean. check_requirements_sync treats sibling
packages as first-party.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
2026-11-22 20:25:39 +01:00

89 lines
2.5 KiB
Python

"""Tests for depotdl."""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Any
from steam_installer import depotdl
if TYPE_CHECKING:
from pathlib import Path
import pytest
def _capture(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]:
"""Intercept the subprocess call and hand back the argv it was given."""
seen = {}
def fake_run_logged(
cmd: list[str], _logger: logging.Logger, **_kw: float | None
) -> tuple[int, str]:
seen["cmd"] = cmd
return seen.get("rc", 0), ""
monkeypatch.setattr(depotdl.runlog, "run_logged", fake_run_logged)
return seen
def test_download_builds_expected_argv(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Download builds expected argv."""
seen = _capture(monkeypatch)
pull = depotdl.Pull(tmp_path / "Game", "krzys2000", "english", 32)
depotdl.download(1771300, pull, logging.getLogger("t"))
cmd = seen["cmd"]
assert cmd[0] == "depotdownloader"
pairs = dict(zip(cmd[1::2], cmd[2::2], strict=False))
assert pairs["-app"] == "1771300"
assert pairs["-language"] == "english"
assert pairs["-max-downloads"] == "32"
assert pairs["-username"] == "krzys2000"
def test_download_always_passes_os_windows(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Without -os, depotdownloader defaults to the host OS and can filter out
every real (Windows-tagged) depot -- the original "0 bytes from 0 depots"."""
seen = _capture(monkeypatch)
depotdl.download(
1771300, depotdl.Pull(tmp_path / "Game", "u"), logging.getLogger("t")
)
cmd = seen["cmd"]
assert cmd[cmd.index("-os") + 1] == "windows"
assert "-remember-password" in cmd
def test_download_creates_the_install_dir(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Download creates the install dir."""
_capture(monkeypatch)
target = tmp_path / "nested" / "Game"
depotdl.download(1, depotdl.Pull(target, "u"), logging.getLogger("t"))
assert target.is_dir()
def test_download_returns_the_exit_code_instead_of_raising(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""The caller must distinguish "download failed" from "manifest step failed"
to decide whether touching the manifest is safe at all."""
seen = _capture(monkeypatch)
seen["rc"] = 1
returncode = depotdl.download(
1, depotdl.Pull(tmp_path / "Game", "u"), logging.getLogger("t")
)
assert returncode == 1